Implement DropDown core widget using
templates to simplify creation and handling of of data related to dropdowns
This commit is contained in:
parent
6be699da64
commit
8d54d37978
5 changed files with 56 additions and 2 deletions
|
@ -6,10 +6,21 @@ using namespace UI::Page;
|
||||||
DisplaySettings::DisplaySettings(std::shared_ptr<DisplayAbstract> aDisplay)
|
DisplaySettings::DisplaySettings(std::shared_ptr<DisplayAbstract> aDisplay)
|
||||||
: Base(UI::ID::Pages::DisplaySettings), mDisplay(aDisplay),
|
: Base(UI::ID::Pages::DisplaySettings), mDisplay(aDisplay),
|
||||||
mBrightnessSlider(AddElement<Widget::BrightnessSlider>(
|
mBrightnessSlider(AddElement<Widget::BrightnessSlider>(
|
||||||
std::make_unique<Widget::BrightnessSlider>(mDisplay))) {
|
std::make_unique<Widget::BrightnessSlider>(mDisplay))),
|
||||||
|
mScreenTimeOutDropDown(AddElement<Widget::DropDown<int>>(
|
||||||
|
std::make_unique<Widget::DropDown<int>>([this](int aTimeout) {
|
||||||
|
|
||||||
|
}))) {
|
||||||
SetBgColor(Color::GREY);
|
SetBgColor(Color::GREY);
|
||||||
|
|
||||||
mBrightnessSlider->SetWidth(GetContentWidth());
|
mBrightnessSlider->SetWidth(GetContentWidth());
|
||||||
mBrightnessSlider->SetHeight(80);
|
mBrightnessSlider->SetHeight(80);
|
||||||
mBrightnessSlider->AlignTo(this, LV_ALIGN_TOP_MID);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "DisplayAbstract.h"
|
#include "DisplayAbstract.h"
|
||||||
|
#include "DropDown.hpp"
|
||||||
#include "PageBase.hpp"
|
#include "PageBase.hpp"
|
||||||
|
|
||||||
namespace UI::Widget {
|
namespace UI::Widget {
|
||||||
class BrightnessSlider;
|
class BrightnessSlider;
|
||||||
}
|
} // namespace UI::Widget
|
||||||
|
|
||||||
namespace UI::Page {
|
namespace UI::Page {
|
||||||
class DisplaySettings : public Base {
|
class DisplaySettings : public Base {
|
||||||
|
@ -16,5 +17,6 @@ public:
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<DisplayAbstract> mDisplay;
|
std::shared_ptr<DisplayAbstract> mDisplay;
|
||||||
Widget::BrightnessSlider *mBrightnessSlider;
|
Widget::BrightnessSlider *mBrightnessSlider;
|
||||||
|
Widget::DropDown<int> *mScreenTimeOutDropDown;
|
||||||
};
|
};
|
||||||
} // namespace UI::Page
|
} // namespace UI::Page
|
||||||
|
|
|
@ -18,6 +18,7 @@ public:
|
||||||
Button,
|
Button,
|
||||||
Label,
|
Label,
|
||||||
List,
|
List,
|
||||||
|
DropDown,
|
||||||
BrightnessSlider,
|
BrightnessSlider,
|
||||||
INVALID_WIDGET_ID
|
INVALID_WIDGET_ID
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#pragma once
|
||||||
#include "ScreenBase.hpp"
|
#include "ScreenBase.hpp"
|
||||||
namespace UI::Screen {
|
namespace UI::Screen {
|
||||||
/// @brief Due to the way LVGL utilizes screens we basically need a canvas to
|
/// @brief Due to the way LVGL utilizes screens we basically need a canvas to
|
||||||
|
|
39
Platformio/OmoteUI/core/widget/DropDown.hpp
Normal file
39
Platformio/OmoteUI/core/widget/DropDown.hpp
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
#pragma once
|
||||||
|
#include "BackgroundScreen.hpp"
|
||||||
|
#include "WidgetBase.hpp"
|
||||||
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace UI::Widget {
|
||||||
|
|
||||||
|
template <typename T> class DropDown : public Base {
|
||||||
|
public:
|
||||||
|
DropDown(std::function<void(T)> aOnItemSelected)
|
||||||
|
: Base(lv_dropdown_create(UI::Screen::BackgroundScreen::getLvInstance()),
|
||||||
|
ID::Widgets::DropDown),
|
||||||
|
mSelectionHandler(aOnItemSelected) {
|
||||||
|
lv_dropdown_clear_options(LvglSelf());
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddItem(std::string aOptionTitle, T aOptionData) {
|
||||||
|
lv_dropdown_add_option(LvglSelf(), aOptionTitle.c_str(),
|
||||||
|
LV_DROPDOWN_POS_LAST);
|
||||||
|
mOptionsData.push_back(aOptionData);
|
||||||
|
}
|
||||||
|
// TODO Could Implement a remove Item but need to make sure
|
||||||
|
// correct order is retained in data vector.
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void OnLvglEvent(lv_event_t *anEvent) override {
|
||||||
|
if (anEvent->code == LV_EVENT_VALUE_CHANGED) {
|
||||||
|
auto idx = lv_dropdown_get_selected(LvglSelf());
|
||||||
|
mSelectionHandler(mOptionsData[idx]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::function<void(T)> mSelectionHandler;
|
||||||
|
std::vector<T> mOptionsData;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace UI::Widget
|
Loading…
Add table
Reference in a new issue