Add Slider Class
Add brightness slider to the display settings class.
This commit is contained in:
parent
615bcd1fde
commit
dface01a40
4 changed files with 62 additions and 2 deletions
|
@ -10,7 +10,9 @@ Manager &Manager::getInstance() { return mManager; }
|
|||
Manager::Manager() {}
|
||||
|
||||
void Manager::pushScreen(Screen::Base::Ptr aScreen) {
|
||||
if (!mScreens.empty()) {
|
||||
mScreens.back()->OnHide();
|
||||
}
|
||||
mScreens.push_back(std::move(aScreen));
|
||||
mScreens.back()->Show();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
#include "DisplaySettings.hpp"
|
||||
#include "Slider.hpp"
|
||||
|
||||
using namespace UI::Page;
|
||||
|
||||
DisplaySettings::DisplaySettings(std::shared_ptr<DisplayAbstract> aDisplay)
|
||||
: Base(UI::ID::Pages::DisplaySettings), mDisplay(aDisplay) {}
|
||||
: Base(UI::ID::Pages::DisplaySettings), mDisplay(aDisplay) {
|
||||
auto slider = std::make_unique<Widget::Slider>(
|
||||
[this](auto aNewBrightness) { mDisplay->setBrightness(aNewBrightness); },
|
||||
0, 255);
|
||||
slider->AlignTo(this, LV_ALIGN_CENTER);
|
||||
slider->SetWidth(GetContentWidth());
|
||||
slider->SetHeight(lv_pct(10));
|
||||
AddWidget(std::move(slider));
|
||||
}
|
30
Platformio/OmoteUI/core/widget/Slider.cpp
Normal file
30
Platformio/OmoteUI/core/widget/Slider.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include "Slider.hpp"
|
||||
#include "BackgroundScreen.hpp"
|
||||
#include "LvglResourceManger.hpp"
|
||||
|
||||
using namespace UI::Widget;
|
||||
|
||||
Slider::Slider(std::function<void(int32_t)> aOnSliderValueChange,
|
||||
int32_t aMinVal, int32_t aMaxVal)
|
||||
: Base(lv_slider_create(UI::Screen::BackgroundScreen::getLvInstance())),
|
||||
mOnSliderChange(std::move(aOnSliderValueChange)) {
|
||||
auto lock = LvglResourceManger::GetInstance().scopeLock();
|
||||
lv_slider_set_range(LvglSelf(), aMinVal, aMaxVal);
|
||||
}
|
||||
|
||||
int32_t Slider::GetValue() {
|
||||
auto lock = LvglResourceManger::GetInstance().scopeLock();
|
||||
return lv_slider_get_value(LvglSelf());
|
||||
}
|
||||
|
||||
void Slider::SetValue(int32_t aValue, lv_anim_enable_t aIsAnimate) {
|
||||
LvglResourceManger::GetInstance().AttemptNow([this, aValue, aIsAnimate] {
|
||||
lv_slider_set_value(LvglSelf(), aValue, aIsAnimate);
|
||||
});
|
||||
}
|
||||
|
||||
void Slider::OnLvglEvent(lv_event_t *anEvent) {
|
||||
if (anEvent->code == LV_EVENT_VALUE_CHANGED) {
|
||||
mOnSliderChange(GetValue());
|
||||
}
|
||||
}
|
19
Platformio/OmoteUI/core/widget/Slider.hpp
Normal file
19
Platformio/OmoteUI/core/widget/Slider.hpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include "WidgetBase.hpp"
|
||||
|
||||
namespace UI::Widget {
|
||||
class Slider : public Base {
|
||||
public:
|
||||
Slider(std::function<void(int32_t)> OnSliderValueChange, int32_t aMinVal = 0,
|
||||
int32_t aMaxVal = 100);
|
||||
|
||||
int32_t GetValue();
|
||||
void SetValue(int32_t aValue, lv_anim_enable_t aIsAnimate = LV_ANIM_ON);
|
||||
|
||||
protected:
|
||||
void OnLvglEvent(lv_event_t *anEvent) override;
|
||||
|
||||
private:
|
||||
std::function<void(int32_t)> mOnSliderChange;
|
||||
};
|
||||
|
||||
} // namespace UI::Widget
|
Loading…
Add table
Reference in a new issue