Add system setting and add a timeout dropdown

This commit is contained in:
MatthewColvin 2023-10-12 22:21:27 -05:00
parent 8d54d37978
commit 5d0533c18a
8 changed files with 83 additions and 24 deletions

View file

@ -1,26 +1,16 @@
#include "DisplaySettings.hpp"
#include "BrightnessSlider.hpp"
#include "Label.hpp"
using namespace UI::Page;
DisplaySettings::DisplaySettings(std::shared_ptr<DisplayAbstract> aDisplay)
: Base(UI::ID::Pages::DisplaySettings), mDisplay(aDisplay),
mBrightnessSlider(AddElement<Widget::BrightnessSlider>(
std::make_unique<Widget::BrightnessSlider>(mDisplay))),
mScreenTimeOutDropDown(AddElement<Widget::DropDown<int>>(
std::make_unique<Widget::DropDown<int>>([this](int aTimeout) {
}))) {
std::make_unique<Widget::BrightnessSlider>(mDisplay))) {
SetBgColor(Color::GREY);
mBrightnessSlider->SetWidth(GetContentWidth());
mBrightnessSlider->SetHeight(80);
mBrightnessSlider->AlignTo(this, LV_ALIGN_TOP_MID);
mScreenTimeOutDropDown->SetHeight(30);
mScreenTimeOutDropDown->SetWidth(GetContentWidth());
mScreenTimeOutDropDown->AddItem("10 Seconds", 10);
mScreenTimeOutDropDown->AddItem("15 Seconds", 15);
mScreenTimeOutDropDown->AddItem("20 Seconds", 20);
mScreenTimeOutDropDown->AlignTo(mBrightnessSlider, LV_ALIGN_OUT_BOTTOM_MID);
}

View file

@ -17,6 +17,5 @@ public:
private:
std::shared_ptr<DisplayAbstract> mDisplay;
Widget::BrightnessSlider *mBrightnessSlider;
Widget::DropDown<int> *mScreenTimeOutDropDown;
};
} // namespace UI::Page

View file

@ -1,12 +1,13 @@
#include "SettingsPage.hpp"
#include "BackgroundScreen.hpp"
#include "Button.hpp"
#include "Slider.hpp"
#include "List.hpp"
#include "Colors.hpp"
#include "DisplaySettings.hpp"
#include "List.hpp"
#include "PopUpScreen.hpp"
#include "ScreenManager.hpp"
#include "Slider.hpp"
#include "SystemSettings.hpp"
using namespace UI::Page;
using namespace UI::Color;
@ -16,8 +17,11 @@ SettingsPage::SettingsPage(std::shared_ptr<HardwareAbstract> aHardware)
mSettingsList(AddElement<Widget::List>(std::make_unique<Widget::List>())),
mHardware(aHardware) {
mSettingsList->AddItem("Display",LV_SYMBOL_EYE_OPEN,[this] { PushDisplaySettings(); });
mSettingsList->AddItem("Wifi",LV_SYMBOL_WIFI,[]{});
mSettingsList->AddItem("Display", LV_SYMBOL_EYE_OPEN,
[this] { PushDisplaySettings(); });
mSettingsList->AddItem("Wifi", LV_SYMBOL_WIFI, [] {});
mSettingsList->AddItem("System", LV_SYMBOL_SETTINGS,
[this] { PushSystemSettings(); });
}
void SettingsPage::PushDisplaySettings() {
@ -25,3 +29,7 @@ void SettingsPage::PushDisplaySettings() {
std::make_unique<DisplaySettings>(mHardware->display()));
}
void SettingsPage::PushSystemSettings() {
UI::Screen::Manager::getInstance().pushPopUp(
std::make_unique<SystemSettings>(mHardware));
}

View file

@ -1,18 +1,21 @@
#include "HardwareAbstract.hpp"
#include "PageBase.hpp"
namespace UI::Widget{
class Button;
class List;
}
namespace UI::Widget {
class Button;
class List;
} // namespace UI::Widget
namespace UI::Page {
class SettingsPage : public Base {
public:
SettingsPage(std::shared_ptr<HardwareAbstract> aHardware = nullptr);
bool OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) override{return false;};
bool OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) override {
return false;
};
void PushDisplaySettings();
void PushSystemSettings();
protected:
void OnShow() override{};

View file

@ -0,0 +1,25 @@
#include "SystemSettings.hpp"
#include "Label.hpp"
using namespace UI::Page;
SystemSettings::SystemSettings(std::shared_ptr<HardwareAbstract> aHardware)
: Base(ID::Pages::SystemSettings), mHardware(aHardware),
mTimeoutLabel(AddElement<Widget::Label>(
std::make_unique<Widget::Label>("TimeOut"))),
mScreenTimeOutDropDown(AddElement<Widget::DropDown<int>>(
std::make_unique<Widget::DropDown<int>>([this](int aTimeout) {
mHardware->setSleepTimeout(aTimeout);
}))) {
mTimeoutLabel->AlignTo(this, LV_ALIGN_TOP_MID);
mTimeoutLabel->SetHeight(15);
mScreenTimeOutDropDown->SetHeight(30);
mScreenTimeOutDropDown->SetWidth(GetContentWidth());
mScreenTimeOutDropDown->AddItem("10 Seconds", 10000);
mScreenTimeOutDropDown->AddItem("15 Seconds", 15000);
mScreenTimeOutDropDown->AddItem("20 Seconds", 20000);
mScreenTimeOutDropDown->AlignTo(mTimeoutLabel, LV_ALIGN_OUT_BOTTOM_MID);
mScreenTimeOutDropDown->SetSelected(mHardware->getSleepTimeout());
}

View file

@ -0,0 +1,25 @@
#pragma once
#include "DropDown.hpp"
#include "HardwareAbstract.hpp"
#include "PageBase.hpp"
namespace UI::Widget {
class Label;
}
namespace UI::Page {
class SystemSettings : public Base {
public:
SystemSettings(std::shared_ptr<HardwareAbstract> aHardware);
protected:
std::string GetTitle() override { return "System Settings"; }
private:
std::shared_ptr<HardwareAbstract> mHardware;
Widget::Label *mTimeoutLabel;
Widget::DropDown<int> *mScreenTimeOutDropDown;
};
} // namespace UI::Page

View file

@ -26,6 +26,7 @@ public:
enum class Pages {
Settings = static_cast<int>(Widgets::INVALID_WIDGET_ID) + 1,
DisplaySettings,
SystemSettings,
Demo,
INVALID_PAGE_ID
};

View file

@ -20,6 +20,14 @@ public:
LV_DROPDOWN_POS_LAST);
mOptionsData.push_back(aOptionData);
}
void SetSelected(T aOptionData) {
for (int i = 0; i < mOptionsData.size(); i++) {
if (mOptionsData[i] == aOptionData) {
lv_dropdown_set_selected(LvglSelf(), i);
}
}
}
// TODO Could Implement a remove Item but need to make sure
// correct order is retained in data vector.