Skip to content

Commit

Permalink
[menu] remove coupling between modm gui and modm menu view and menu
Browse files Browse the repository at this point in the history
This is because the gui stuff requires colored menus
but the menu code should not have to have colored
menus. This wouldn't be an issue if we could dynamic
cast but on certain devices you can't do this.
  • Loading branch information
MatthewMArnold committed May 3, 2021
1 parent 05badc4 commit 76e5a09
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/modm/ui/gui/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -161,3 +162,9 @@ void modm::gui::View::markDrawn()
(*iter)->markDrawn();
}
}

modm::ColorGraphicDisplay&
modm::gui::View::display()
{
return stack->getDisplay();
}
52 changes: 51 additions & 1 deletion src/modm/ui/gui/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GuiViewStack;
* @ingroup modm_ui_gui
* @author Thorsten Lajewski
*/
class View : public modm::AbstractView
class View
{
friend class GuiViewStack;

Expand All @@ -61,6 +61,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()
{
Expand All @@ -75,14 +83,43 @@ class View : public modm::AbstractView
virtual void
draw();

/**
* @brief shortButtonPress handle the action for the pressed button
*/
virtual void
shortButtonPress(modm::MenuButtons::Button /*button*/)
{
// nothing to be done
}

/// Add widget to view
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);
Expand All @@ -105,12 +142,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
Expand Down
2 changes: 1 addition & 1 deletion src/modm/ui/gui/view_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

// ----------------------------------------------------------------------------
modm::gui::GuiViewStack::GuiViewStack(modm::ColorGraphicDisplay* display, modm::gui::inputQueue* queue) :
ViewStack(display),
display(display),
input_queue(queue)
{
}
Expand Down
24 changes: 23 additions & 1 deletion src/modm/ui/gui/view_stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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);
Expand Down Expand Up @@ -84,7 +84,29 @@ class GuiViewStack : public modm::ViewStack
virtual void
update();

/**
* @brief shortButtonPress pass the button press to the current top view
* @param button the pressed button
*/

void
shortButtonPress(modm::MenuButtons::Button button)
{
modm::gui::View* top = this->get();
top->shortButtonPress(button);
}

/**
* @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;
};
Expand Down
2 changes: 1 addition & 1 deletion src/modm/ui/menu/iabstract_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef MODM_IABSTRACT_VIEW_HPP
#define MODM_IABSTRACT_VIEW_HPP

#include <modm/ui/display/color_graphic_display.hpp>
#include <modm/ui/display/graphic_display.hpp>

#include "menu_buttons.hpp"

Expand Down

0 comments on commit 76e5a09

Please sign in to comment.