diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 517421c7a..60c8f910e 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -57,6 +57,8 @@ bool AppsContainer::handleEvent(Ion::Events::Event event) { void AppsContainer::switchTo(App * app) { m_window.setTitle(app->name()); + // TODO: Update the battery icon every in a time frame + m_window.updateBatteryLevel(); Container::switchTo(app); } diff --git a/apps/apps_window.cpp b/apps/apps_window.cpp index edc63bc2d..daa22be70 100644 --- a/apps/apps_window.cpp +++ b/apps/apps_window.cpp @@ -13,6 +13,11 @@ void AppsWindow::setTitle(const char * title) { m_titleBarView.setTitle(title); } +void AppsWindow::updateBatteryLevel() { + // TODO: use Ion::Battery::level() + m_titleBarView.setChargeState(Ion::Battery::Charge::EMPTY); +} + int AppsWindow::numberOfSubviews() const { return (m_contentView == nullptr ? 1 : 2); } diff --git a/apps/apps_window.h b/apps/apps_window.h index 5428336a8..4f05157c6 100644 --- a/apps/apps_window.h +++ b/apps/apps_window.h @@ -8,6 +8,7 @@ class AppsWindow : public Window { public: AppsWindow(); void setTitle(const char * title); + void updateBatteryLevel(); private: constexpr static KDCoordinate k_titleBarHeight = 18; int numberOfSubviews() const override; diff --git a/apps/title_bar_view.cpp b/apps/title_bar_view.cpp index 10a60447b..c696f668d 100644 --- a/apps/title_bar_view.cpp +++ b/apps/title_bar_view.cpp @@ -5,26 +5,36 @@ extern "C" { TitleBarView::TitleBarView() : View(), - m_titleView(KDText::FontSize::Small, nullptr, 0.5f, 0.5f, KDColorWhite, KDColorRed) + m_titleView(KDText::FontSize::Small, nullptr, 0.5f, 0.5f, KDColorWhite, Palette::YellowOne) { } void TitleBarView::drawRect(KDContext * ctx, KDRect rect) const { - ctx->fillRect(bounds(), KDColorRed); + ctx->fillRect(bounds(), Palette::YellowOne); + } void TitleBarView::setTitle(const char * title) { m_titleView.setText(title); } +void TitleBarView::setChargeState(Ion::Battery::Charge chargeState) { + m_batteryView.setChargeState(chargeState); +} + int TitleBarView::numberOfSubviews() const { - return 1; + return 2; } View * TitleBarView::subviewAtIndex(int index) { - return &m_titleView; + if (index == 0) { + return &m_titleView; + } + return &m_batteryView; } void TitleBarView::layoutSubviews() { m_titleView.setFrame(bounds()); + KDSize batterySize = m_batteryView.minimalSizeForOptimalDisplay(); + m_batteryView.setFrame(KDRect(bounds().width() - batterySize.width() - k_batteryLeftMargin, (bounds().height()- batterySize.height())/2, batterySize)); } diff --git a/apps/title_bar_view.h b/apps/title_bar_view.h index 120115fba..a0dd33e86 100644 --- a/apps/title_bar_view.h +++ b/apps/title_bar_view.h @@ -2,17 +2,21 @@ #define APPS_TITLE_BAR_VIEW_H #include +#include "battery_view.h" class TitleBarView : public View { public: TitleBarView(); void drawRect(KDContext * ctx, KDRect rect) const override; void setTitle(const char * title); + void setChargeState(Ion::Battery::Charge chargeState); private: + constexpr static KDCoordinate k_batteryLeftMargin = 5; int numberOfSubviews() const override; void layoutSubviews() override; View * subviewAtIndex(int index) override; PointerTextView m_titleView; + BatteryView m_batteryView; }; #endif