touchgfx MenuView
MenuView.hpp
#ifndef MENU_VIEW_HPP
#define MENU_VIEW_HPP
#include <gui_generated/menu_screen/MenuViewBase.hpp>
#include <gui/menu_screen/MenuPresenter.hpp>
#include <gui/menu_screen/Tile.hpp>
#include <gui/menu_screen/LiveDataDisplayTile.hpp>
#include <gui/menu_screen/HomeAutomationTile.hpp>
#include <gui/menu_screen/AnimatedGraphicsTile.hpp>
#include <gui/menu_screen/ChromArtTile.hpp>
class MenuView : public MenuViewBase
{
static const int TILE_OFFSET_X = 17;
static const int TILE_OFFSET_Y = 11;
Tile<LiveDataDisplayTile> liveDataDisplayTile;
Tile<HomeAutomationTile> homeAutomationTile;
Tile<AnimatedGraphicsTile> animatedGraphicsTile;
Tile<ChromArtTile> chromArtTile;
public:
MenuView();
virtual ~MenuView() {}
virtual void setupScreen();
virtual void tearDownScreen();
void addRoomToHomeAutomationTile(RoomTemperatureInfo& room);
void initializeTiles();
Callback<MenuView, const AbstractButton&> onButtonPressed;
void buttonPressedhandler(const AbstractButton& button);
protected:
};
#endif // MENU_VIEW_HPP
MenuView.cpp
#include <gui/menu_screen/MenuView.hpp>
MenuView::MenuView() :
onButtonPressed(this, &MenuView::buttonPressedhandler)
{
}
void MenuView::setupScreen()
{
MenuViewBase::setupScreen();
liveDataDisplayTile.setXY(TILE_OFFSET_X, HAL::DISPLAY_HEIGHT - liveDataDisplayTile.getHeight() - TILE_OFFSET_Y);
homeAutomationTile.setXY(TILE_OFFSET_X, TILE_OFFSET_Y);
animatedGraphicsTile.setXY(TILE_OFFSET_X, homeAutomationTile.getY() + homeAutomationTile.getHeight() + TILE_OFFSET_Y);
chromArtTile.setXY(animatedGraphicsTile.getX() + animatedGraphicsTile.getWidth() + TILE_OFFSET_X - 3, animatedGraphicsTile.getY());
add(liveDataDisplayTile);
add(homeAutomationTile);
add(animatedGraphicsTile);
add(chromArtTile);
}
void MenuView::tearDownScreen()
{
MenuViewBase::tearDownScreen();
}
void MenuView::buttonPressedhandler(const AbstractButton& button)
{
}
void MenuView::addRoomToHomeAutomationTile(RoomTemperatureInfo& room)
{
homeAutomationTile.getTile().addRoom(room);
}
void MenuView::initializeTiles()
{
homeAutomationTile.getTile().initialize();
}
Tile.hpp
#ifndef TILE_HPP_
#define TILE_HPP_
#include <touchgfx/mixins/ClickListener.hpp>
#include <touchgfx/containers/Container.hpp>
#include <touchgfx/widgets/Box.hpp>
#include <touchgfx/Color.hpp>
using namespace touchgfx;
/**
* Container wrapping tile classes. Adding pressed and clicked events to the tile.
*/
template<class T>
class Tile : public Container
{
public:
Tile() :
pressedActive(false),
onTileClicked(this, &Tile::tileClickedhandler)
{
setWidth(tile.getWidth() + 6);
setHeight(tile.getHeight() + 6);
tile.setXY(3, 3);
tile.setClickAction(onTileClicked);
add(tile);
}
virtual ~Tile()
{
}
T& getTile()
{
return tile;
}
private:
ClickListener<T> tile;
bool pressedActive;
Callback<Tile, const T&, const ClickEvent& > onTileClicked;
void tileClickedhandler(const T& t, const ClickEvent& event)
{
if (&t == &tile)
{
if (event.getType() == ClickEvent::RELEASED)
{
if (pressedActive)
{
tile.gotoAssociatedScreen();
}
}
else if (event.getType() == ClickEvent::PRESSED)
{
pressedActive = true;
}
else if (event.getType() == ClickEvent::CANCEL)
{
pressedActive = false;
}
}
}
};
#endif /* TILE_HPP_ */