Set Navigation title with View.title() if not empty.

This commit is contained in:
Jared Boone 2016-01-26 13:04:44 -08:00
parent dc42525dcb
commit 7fe8288737
2 changed files with 19 additions and 7 deletions

View File

@ -41,7 +41,7 @@ namespace ui {
SystemStatusView::SystemStatusView() {
add_children({ {
&button_back,
&portapack,
&title,
&sd_card_status_view,
} });
sd_card_status_view.set_parent_rect({ 28 * 8, 0 * 16, 2 * 8, 1 * 16 });
@ -57,6 +57,14 @@ void SystemStatusView::set_back_visible(bool new_value) {
button_back.hidden(!new_value);
}
void SystemStatusView::set_title(const std::string new_value) {
if( new_value.empty() ) {
title.set(default_title);
} else {
title.set(new_value);
}
}
/* Navigation ************************************************************/
bool NavigationView::is_top() const {
@ -97,7 +105,7 @@ void NavigationView::update_view() {
set_dirty();
if( on_view_changed ) {
on_view_changed();
on_view_changed(*new_view);
}
}
@ -176,8 +184,9 @@ SystemView::SystemView(
{ 0, status_view_height },
{ parent_rect.width(), static_cast<ui::Dim>(parent_rect.height() - status_view_height) }
});
navigation_view.on_view_changed = [this]() {
navigation_view.on_view_changed = [this](const View& new_view) {
this->status_view.set_back_visible(!this->navigation_view.is_top());
this->status_view.set_title(new_view.title());
};
// Initial view.

View File

@ -44,16 +44,19 @@ public:
SystemStatusView();
void set_back_visible(bool new_value);
void set_title(const std::string new_value);
private:
static constexpr auto default_title = "PortaPack";
Button button_back {
{ 0 * 8, 0 * 16, 3 * 8, 16 },
" < ",
};
Text portapack {
{ 3 * 8, 0, 9 * 8, 1 * 16 },
"PortaPack",
Text title {
{ 3 * 8, 0, 16 * 8, 1 * 16 },
default_title,
};
SDCardStatusView sd_card_status_view;
@ -61,7 +64,7 @@ private:
class NavigationView : public View {
public:
std::function<void(void)> on_view_changed;
std::function<void(const View&)> on_view_changed;
NavigationView() { }