Merge pull request #122 from klockee/new-main-menu-footer

New main menu footer
This commit is contained in:
Erwin Ried 2020-08-08 11:43:45 +02:00 committed by GitHub
commit 4ce44b84f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 108 additions and 6 deletions

View File

@ -95,6 +95,15 @@ void BtnGridView::set_parent_rect(const Rect new_parent_rect) {
update_items(); update_items();
} }
void BtnGridView::set_arrow_enabled(bool new_value) {
if(new_value){
add_child(&arrow_more);
}
else{
remove_child(&arrow_more);
}
};
void BtnGridView::on_tick_second() { void BtnGridView::on_tick_second() {
if (more && blink) if (more && blink)
arrow_more.set_foreground(Color::white()); arrow_more.set_foreground(Color::white());

View File

@ -62,6 +62,7 @@ public:
uint32_t highlighted_index(); uint32_t highlighted_index();
void set_parent_rect(const Rect new_parent_rect) override; void set_parent_rect(const Rect new_parent_rect) override;
void set_arrow_enabled(bool new_value);
void on_focus() override; void on_focus() override;
void on_blur() override; void on_blur() override;
bool on_key(const KeyEvent event) override; bool on_key(const KeyEvent event) override;

View File

@ -306,6 +306,32 @@ void SystemStatusView::on_title() {
nav_.push<AboutView>(); nav_.push<AboutView>();
} }
/* Information View *****************************************************/
InformationView::InformationView(
NavigationView& nav
) : nav_ (nav)
{
static constexpr Style style_infobar {
.font = font::fixed_8x16,
.background = {33, 33, 33},
.foreground = Color::white(),
};
add_children({
&backdrop,
&version,
&ltime
});
version.set_style(&style_infobar);
ltime.set_style(&style_infobar);
ltime.set_seconds_enabled(true);
ltime.set_date_enabled(false);
set_dirty();
}
/* Navigation ************************************************************/ /* Navigation ************************************************************/
bool NavigationView::is_top() const { bool NavigationView::is_top() const {
@ -502,6 +528,7 @@ SystemMenuView::SystemMenuView(NavigationView& nav) {
//{ "About", ui::Color::cyan(), nullptr, [&nav](){ nav.push<AboutView>(); } } //{ "About", ui::Color::cyan(), nullptr, [&nav](){ nav.push<AboutView>(); } }
}); });
set_max_rows(2); // allow wider buttons set_max_rows(2); // allow wider buttons
set_arrow_enabled(false);
//set_highlighted(1); // Startup selection //set_highlighted(1); // Startup selection
} }
@ -522,6 +549,7 @@ SystemView::SystemView(
set_style(&style_default); set_style(&style_default);
constexpr ui::Dim status_view_height = 16; constexpr ui::Dim status_view_height = 16;
constexpr ui::Dim info_view_height = 16;
add_child(&status_view); add_child(&status_view);
status_view.set_parent_rect({ status_view.set_parent_rect({
@ -537,11 +565,27 @@ SystemView::SystemView(
{ 0, status_view_height }, { 0, status_view_height },
{ parent_rect.width(), static_cast<ui::Dim>(parent_rect.height() - status_view_height) } { parent_rect.width(), static_cast<ui::Dim>(parent_rect.height() - status_view_height) }
}); });
add_child(&info_view);
info_view.set_parent_rect({
{0, 19 * 16},
{ parent_rect.width(), info_view_height }
});
navigation_view.on_view_changed = [this](const View& new_view) { navigation_view.on_view_changed = [this](const View& new_view) {
if(!this->navigation_view.is_top()){
remove_child(&info_view);
}
else{
add_child(&info_view);
}
this->status_view.set_back_enabled(!this->navigation_view.is_top()); this->status_view.set_back_enabled(!this->navigation_view.is_top());
this->status_view.set_title_image_enabled(this->navigation_view.is_top()); this->status_view.set_title_image_enabled(this->navigation_view.is_top());
this->status_view.set_dirty();
this->status_view.set_title(new_view.title()); this->status_view.set_title(new_view.title());
this->status_view.set_dirty();
}; };
@ -557,6 +601,9 @@ SystemView::SystemView(
if (portapack::persistent_memory::config_splash()) if (portapack::persistent_memory::config_splash())
navigation_view.push<BMPView>(); navigation_view.push<BMPView>();
status_view.set_back_enabled(false);
status_view.set_title_image_enabled(true);
status_view.set_dirty();
//else //else
// navigation_view.push<SystemMenuView>(); // navigation_view.push<SystemMenuView>();

View File

@ -110,7 +110,7 @@ public:
void set_title(const std::string new_value); void set_title(const std::string new_value);
private: private:
static constexpr auto default_title = " v1.1.1"; // TODO: Move the version somewhere static constexpr auto default_title = "";
NavigationView& nav_; NavigationView& nav_;
@ -208,6 +208,29 @@ private:
}; };
}; };
class InformationView : public View {
public:
InformationView(NavigationView& nav);
private:
static constexpr auto version_string = "v1.1.1";
NavigationView& nav_;
Rectangle backdrop {
{ 0, 0 * 16, 240, 16 },
{33, 33, 33}
};
Text version {
{0, 0, 11 * 8, 16},
version_string
};
LiveDateTime ltime {
{176, 0, 8 * 8, 16}
};
};
class BMPView : public View { class BMPView : public View {
public: public:
BMPView(NavigationView& nav); BMPView(NavigationView& nav);
@ -262,6 +285,7 @@ public:
private: private:
SystemStatusView status_view { navigation_view }; SystemStatusView status_view { navigation_view };
InformationView info_view { navigation_view };
NavigationView navigation_view { }; NavigationView navigation_view { };
Context& context_; Context& context_;
}; };

View File

@ -409,10 +409,17 @@ void Labels::paint(Painter& painter) {
void LiveDateTime::on_tick_second() { void LiveDateTime::on_tick_second() {
rtcGetTime(&RTCD1, &datetime); rtcGetTime(&RTCD1, &datetime);
text = "";
text = to_string_dec_uint(datetime.month(), 2, '0') + "/" + to_string_dec_uint(datetime.day(), 2, '0') + " " + if(date_enabled){
to_string_dec_uint(datetime.hour(), 2, '0') + ":" + to_string_dec_uint(datetime.minute(), 2, '0'); text = to_string_dec_uint(datetime.month(), 2, '0') + "/" + to_string_dec_uint(datetime.day(), 2, '0') + " ";
}
text = text + to_string_dec_uint(datetime.hour(), 2, '0') + ":" + to_string_dec_uint(datetime.minute(), 2, '0');
if(seconds_enabled){
text = text + ":" + to_string_dec_uint(datetime.second(), 2, '0');
}
set_dirty(); set_dirty();
} }
@ -444,6 +451,14 @@ void LiveDateTime::paint(Painter& painter) {
); );
} }
void LiveDateTime::set_date_enabled(bool new_value){
this->date_enabled = new_value;
}
void LiveDateTime::set_seconds_enabled(bool new_value) {
this->seconds_enabled = new_value;
}
/* BigFrequency **********************************************************/ /* BigFrequency **********************************************************/
BigFrequency::BigFrequency( BigFrequency::BigFrequency(

View File

@ -244,6 +244,9 @@ public:
void paint(Painter& painter) override; void paint(Painter& painter) override;
void set_seconds_enabled(bool new_value);
void set_date_enabled(bool new_value);
std::string& string() { std::string& string() {
return text; return text;
} }
@ -251,6 +254,9 @@ public:
private: private:
void on_tick_second(); void on_tick_second();
bool date_enabled = true;
bool seconds_enabled = false;
rtc::RTC datetime { }; rtc::RTC datetime { };
SignalToken signal_token_tick_second { }; SignalToken signal_token_tick_second { };
std::string text { }; std::string text { };