From beb03f347d9708d75919fa7556b5ef676110d95d Mon Sep 17 00:00:00 2001 From: Matthew Arnold Date: Sun, 5 Feb 2023 21:06:27 +0100 Subject: [PATCH] [ui] Remove dependency of :ui:gui on :ui:menu --- src/modm/ui/gui/module.lb | 4 +-- src/modm/ui/gui/view.cpp | 11 +++++++-- src/modm/ui/gui/view.hpp | 45 +++++++++++++++++++++++++++++++--- src/modm/ui/gui/view_stack.cpp | 2 +- src/modm/ui/gui/view_stack.hpp | 13 ++++++++-- 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/modm/ui/gui/module.lb b/src/modm/ui/gui/module.lb index 1dde1231ec..ca9c614bcf 100644 --- a/src/modm/ui/gui/module.lb +++ b/src/modm/ui/gui/module.lb @@ -23,9 +23,7 @@ def prepare(module, options): ":container", ":debug", ":processing:timer", - ":ui:display", - ":ui:gui", - ":ui:menu") + ":ui:display") return True def build(env): diff --git a/src/modm/ui/gui/view.cpp b/src/modm/ui/gui/view.cpp index 75c5389d8c..1fd4c505f1 100644 --- a/src/modm/ui/gui/view.cpp +++ b/src/modm/ui/gui/view.cpp @@ -18,9 +18,10 @@ // ---------------------------------------------------------------------------- modm::gui::View::View(modm::gui::GuiViewStack* stack, uint8_t identifier, modm::gui::Dimension dimension) : - AbstractView(stack, identifier), stack(stack), - dimension(dimension) + dimension(dimension), + identifier(identifier), + alive(true) { this->display().clear(); } @@ -161,3 +162,9 @@ void modm::gui::View::markDrawn() (*iter)->markDrawn(); } } + +modm::ColorGraphicDisplay& +modm::gui::View::display() +{ + return stack->getDisplay(); +} diff --git a/src/modm/ui/gui/view.hpp b/src/modm/ui/gui/view.hpp index 69d02fcca3..a06a3bf2cd 100644 --- a/src/modm/ui/gui/view.hpp +++ b/src/modm/ui/gui/view.hpp @@ -24,8 +24,6 @@ #include "widgets/widget.hpp" #include "colorpalette.hpp" -#include - namespace modm { @@ -41,7 +39,7 @@ class GuiViewStack; * @ingroup modm_ui_gui * @author Thorsten Lajewski */ -class View : public modm::AbstractView +class View { friend class GuiViewStack; @@ -61,6 +59,14 @@ class View : public modm::AbstractView virtual void update(); + /** + * @brief hasChanged indicates the current displayed view has changed. + * This function prevents unnecessary drawing of the display + * @return if true the display has to be redrawn. + */ + virtual bool + hasChanged() = 0; + virtual void preUpdate() { @@ -79,10 +85,30 @@ class View : public modm::AbstractView bool pack(Widget *w, const modm::glcd::Point &coord); + /** + * @brief isAlive tells the ViewStack if it should remove this screen. + * @return + */ + bool + isAlive() const + { + return this->alive; + } + /// Remove the view from the screen. The viewStack handles the deletion. void remove(); + /** + * @brief onRemove will be called right before the view gets deleted, + * can be reimplemented to reset external data. + */ + virtual void + onRemove() + { + // nothing to be done here + } + /// Set color palette for every contained widget void setColorPalette(ColorPalette& cp); @@ -105,12 +131,25 @@ class View : public modm::AbstractView return stack; } + modm::ColorGraphicDisplay& + display(); + + /** + * @brief getIdentifier of the view. + */ + inline uint8_t getIdentifier(){ + return this->identifier; + } + protected: modm::gui::GuiViewStack* stack; Dimension dimension; WidgetContainer widgets; modm::gui::ColorPalette colorpalette; + + const uint8_t identifier; + bool alive; }; } // namespace gui diff --git a/src/modm/ui/gui/view_stack.cpp b/src/modm/ui/gui/view_stack.cpp index de116a93fc..a5e1b614d3 100644 --- a/src/modm/ui/gui/view_stack.cpp +++ b/src/modm/ui/gui/view_stack.cpp @@ -20,7 +20,7 @@ // ---------------------------------------------------------------------------- modm::gui::GuiViewStack::GuiViewStack(modm::ColorGraphicDisplay* display, modm::gui::inputQueue* queue) : - ViewStack(display), + display(display), input_queue(queue) { } diff --git a/src/modm/ui/gui/view_stack.hpp b/src/modm/ui/gui/view_stack.hpp index 308ce0085d..edff70b95d 100644 --- a/src/modm/ui/gui/view_stack.hpp +++ b/src/modm/ui/gui/view_stack.hpp @@ -21,7 +21,6 @@ #include #include #include -#include #include "view.hpp" #include "types.hpp" @@ -41,7 +40,7 @@ namespace gui * @ingroup modm_ui_gui * @author Thorsten Lajewski */ -class GuiViewStack : public modm::ViewStack +class GuiViewStack { public: GuiViewStack(modm::ColorGraphicDisplay* display, modm::gui::inputQueue* queue); @@ -84,7 +83,17 @@ class GuiViewStack : public modm::ViewStack virtual void update(); + /** + * @brief getDisplay access underlying GraphicDisplay + */ + inline modm::ColorGraphicDisplay& + getDisplay() + { + return *this->display; + } + private: + modm::ColorGraphicDisplay *display; modm::Stack< modm::gui::View* , modm::LinkedList< modm::gui::View* > > stack; modm::gui::inputQueue *input_queue; };