6#include "TinyMaterialDesign/Core/Container.h"
7#include "TinyMaterialDesign/Core/Screen.h"
8#include "TinyMaterialDesign/Widgets/IconButton.h"
9#include "TinyMaterialDesign/Widgets/NavigationBar.h"
14
15
16
17
18
19
20
21
22
23
24
25
26
33 virtual const char*
title()
const {
return title_.c_str(); }
35 void setTitle(
const char* title) { title_ = title; }
36 void setIcon(IconPainter<RGB_T> icon) { icon_ = icon; }
46 virtual bool tick(uint32_t nowMs) {
53 IconPainter<RGB_T> icon_ =
nullptr;
57
58
59
60
61
62
63
64
65
66
67
80
81
82
84 for (Page<RGB_T>* page : pages_) nav_.addDestination(page->icon(), page->title());
85 nav_.onChange = [
this](
int index) {
show(index
); };
86 screen_.addFixedWidget(nav_);
87 for (Page<RGB_T>* page : pages_) {
88 page->bounds = pageBounds;
89 screen_.addWidget(*page);
99 if (index < 0 || index >=
count())
return;
100 if (begun_ && current_ >= 0 && current_ != index) pages_[current_]->onHide();
101 const bool changed = current_ != index;
103 for (size_t i = 0; i < pages_.size(); ++i) pages_[i]->visible =
static_cast<
int>(i) == index;
104 nav_.setSelectedIndex(index);
105 pages_[current_]->onShow();
106 screen_.invalidate();
107 if (changed && onPageChanged) onPageChanged(index);
111 bool tick(uint32_t nowMs) {
return current_ >= 0 && pages_[current_]->tick(nowMs); }
114 int count()
const {
return static_cast<
int>(pages_.size()); }
115 Page<RGB_T>&
page(
int index) {
return *pages_[index]; }
121 std::vector<Page<RGB_T>*> pages_;
A widget that holds child widgets, draws/dispatches gestures to them, and scrolls its content vertica...
Definition: Container.h:56
Bottom navigation bar: 3-5 exclusive destinations, each an icon with a label underneath and a pill hi...
Definition: NavigationBar.h:29
Connects Pages with a NavigationBar: one destination per page, only the selected page is visible....
Definition: Page.h:69
void begin(Bounds pageBounds)
Adds the navigation bar (fixed) and the pages (with the indicated bounds) to the screen,...
Definition: Page.h:83
int count() const
Definition: Page.h:114
int current() const
Definition: Page.h:113
std::function< void(int index)> onPageChanged
Called after the page was changed (by the user or show()).
Definition: Page.h:74
Page< RGB_T > & page(int index)
Definition: Page.h:115
void addPage(Page< RGB_T > &page)
Adds a page (before begin()).
Definition: Page.h:77
void show(int index)
Shows the page with the index.
Definition: Page.h:98
PageNavigator(Screen< RGB_T > &screen, NavigationBar< RGB_T > &nav)
Definition: Page.h:71
Page< RGB_T > & currentPage()
Definition: Page.h:116
bool tick(uint32_t nowMs)
Calls tick() of the visible page: true if it must be redrawn.
Definition: Page.h:111
One page (tab) of an app: a scrollable Container with a title and an icon for the navigation,...
Definition: Page.h:28
virtual void onHide()
The page is hidden (another page is shown).
Definition: Page.h:43
virtual void onShow()
The page becomes visible.
Definition: Page.h:41
Page(const char *title="", IconPainter< RGB_T > icon=nullptr)
Definition: Page.h:30
virtual IconPainter< RGB_T > icon() const
Definition: Page.h:34
void setIcon(IconPainter< RGB_T > icon)
Definition: Page.h:36
virtual void build()
Creates the widgets (called once by PageNavigator::begin()).
Definition: Page.h:39
void setTitle(const char *title)
Definition: Page.h:35
virtual const char * title() const
Label and icon of the page in a NavigationBar.
Definition: Page.h:33
virtual bool tick(uint32_t nowMs)
Definition: Page.h:46
Owns a set of widgets, draws them, and routes gesture events to whichever one should handle each even...
Definition: Screen.h:71
Definition: AnchorLayout.h:4
Axis-aligned pixel rectangle used for widget bounds and hit-testing.
Definition: Bounds.h:21