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() { SystemStatusView::SystemStatusView() {
add_children({ { add_children({ {
&button_back, &button_back,
&portapack, &title,
&sd_card_status_view, &sd_card_status_view,
} }); } });
sd_card_status_view.set_parent_rect({ 28 * 8, 0 * 16, 2 * 8, 1 * 16 }); 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); 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 ************************************************************/ /* Navigation ************************************************************/
bool NavigationView::is_top() const { bool NavigationView::is_top() const {
@ -97,7 +105,7 @@ void NavigationView::update_view() {
set_dirty(); set_dirty();
if( on_view_changed ) { if( on_view_changed ) {
on_view_changed(); on_view_changed(*new_view);
} }
} }
@ -176,8 +184,9 @@ 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) }
}); });
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_back_visible(!this->navigation_view.is_top());
this->status_view.set_title(new_view.title());
}; };
// Initial view. // Initial view.

View File

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