mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps] Display the baterry icon view on the title bar
Change-Id: I3a1f2540151f7ecbfafaead346e673f694d8c0dd
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -2,17 +2,21 @@
|
||||
#define APPS_TITLE_BAR_VIEW_H
|
||||
|
||||
#include <escher.h>
|
||||
#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
|
||||
|
||||
Reference in New Issue
Block a user