mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps] Display the preferences in the title bar
Change-Id: Ib1defef85b68a48f667127c583901b659db1cbaf
This commit is contained in:
@@ -18,6 +18,7 @@ AppsContainer::AppsContainer() :
|
||||
m_preferences(Preferences()),
|
||||
m_variableBoxController(&m_globalContext)
|
||||
{
|
||||
refreshPreferences();
|
||||
}
|
||||
|
||||
int AppsContainer::numberOfApps() {
|
||||
@@ -71,6 +72,10 @@ void AppsContainer::switchTo(App * app) {
|
||||
Container::switchTo(app);
|
||||
}
|
||||
|
||||
void AppsContainer::refreshPreferences() {
|
||||
m_window.refreshPreferences(&m_preferences);
|
||||
}
|
||||
|
||||
Window * AppsContainer::window() {
|
||||
return &m_window;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ public:
|
||||
VariableBoxController * variableBoxController();
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
void switchTo(App * app) override;
|
||||
void refreshPreferences();
|
||||
private:
|
||||
Window * window() override;
|
||||
static constexpr int k_numberOfApps = 9;
|
||||
|
||||
@@ -18,6 +18,10 @@ void AppsWindow::updateBatteryLevel() {
|
||||
m_titleBarView.setChargeState(Ion::Battery::Charge::EMPTY);
|
||||
}
|
||||
|
||||
void AppsWindow::refreshPreferences(Preferences * preferences) {
|
||||
m_titleBarView.setPreferences(preferences);
|
||||
}
|
||||
|
||||
int AppsWindow::numberOfSubviews() const {
|
||||
return (m_contentView == nullptr ? 1 : 2);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ public:
|
||||
AppsWindow();
|
||||
void setTitle(const char * title);
|
||||
void updateBatteryLevel();
|
||||
void refreshPreferences(Preferences * preferences);
|
||||
private:
|
||||
constexpr static KDCoordinate k_titleBarHeight = 18;
|
||||
int numberOfSubviews() const override;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "sub_controller.h"
|
||||
#include "../apps_container.h"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Settings {
|
||||
@@ -33,6 +34,8 @@ void SubController::didBecomeFirstResponder() {
|
||||
bool SubController::handleEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::OK) {
|
||||
setPreferenceAtIndexWithValueIndex(m_preferenceIndex, m_selectableTableView.selectedRow());
|
||||
AppsContainer * myContainer = (AppsContainer * )app()->container();
|
||||
myContainer->refreshPreferences();
|
||||
StackViewController * stack = stackController();
|
||||
stack->pop();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ extern "C" {
|
||||
|
||||
TitleBarView::TitleBarView() :
|
||||
View(),
|
||||
m_titleView(KDText::FontSize::Small, nullptr, 0.5f, 0.5f, KDColorWhite, Palette::YellowDark)
|
||||
m_titleView(KDText::FontSize::Small, nullptr, 0.5f, 0.5f, KDColorWhite, Palette::YellowDark),
|
||||
m_preferenceView(KDText::FontSize::Small, 1.0f, 0.5, KDColorWhite, Palette::YellowDark)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -23,18 +24,44 @@ void TitleBarView::setChargeState(Ion::Battery::Charge chargeState) {
|
||||
}
|
||||
|
||||
int TitleBarView::numberOfSubviews() const {
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
View * TitleBarView::subviewAtIndex(int index) {
|
||||
if (index == 0) {
|
||||
return &m_titleView;
|
||||
}
|
||||
if (index == 1) {
|
||||
return &m_preferenceView;
|
||||
}
|
||||
return &m_batteryView;
|
||||
}
|
||||
|
||||
void TitleBarView::layoutSubviews() {
|
||||
m_titleView.setFrame(bounds());
|
||||
m_preferenceView.setFrame(KDRect(0, 0, m_preferenceView.minimalSizeForOptimalDisplay()));
|
||||
KDSize batterySize = m_batteryView.minimalSizeForOptimalDisplay();
|
||||
m_batteryView.setFrame(KDRect(bounds().width() - batterySize.width() - k_batteryLeftMargin, (bounds().height()- batterySize.height())/2, batterySize));
|
||||
}
|
||||
|
||||
void TitleBarView::setPreferences(Preferences * preferences) {
|
||||
char buffer[13];
|
||||
int numberOfChar = 0;
|
||||
if (preferences->displayMode() == Preferences::DisplayMode::Scientific) {
|
||||
strlcpy(buffer, "sci/", 5);
|
||||
numberOfChar += 4;
|
||||
}
|
||||
if (preferences->numberType() == Preferences::NumberType::Complex) {
|
||||
strlcpy(buffer+numberOfChar, "cplx/", 6);
|
||||
numberOfChar += 5;
|
||||
}
|
||||
if (preferences->angleUnit() == Preferences::AngleUnit::Radian) {
|
||||
strlcpy(buffer+numberOfChar, "rad", 4);
|
||||
} else {
|
||||
strlcpy(buffer+numberOfChar, "deg", 4);
|
||||
}
|
||||
numberOfChar += 3;
|
||||
buffer[numberOfChar] = 0;
|
||||
m_preferenceView.setText(buffer);
|
||||
layoutSubviews();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <escher.h>
|
||||
#include "battery_view.h"
|
||||
#include "preferences.h"
|
||||
|
||||
class TitleBarView : public View {
|
||||
public:
|
||||
@@ -10,6 +11,7 @@ public:
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
void setTitle(const char * title);
|
||||
void setChargeState(Ion::Battery::Charge chargeState);
|
||||
void setPreferences(Preferences * preferences);
|
||||
private:
|
||||
constexpr static KDCoordinate k_batteryLeftMargin = 5;
|
||||
int numberOfSubviews() const override;
|
||||
@@ -17,6 +19,7 @@ private:
|
||||
View * subviewAtIndex(int index) override;
|
||||
PointerTextView m_titleView;
|
||||
BatteryView m_batteryView;
|
||||
BufferTextView m_preferenceView;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user