Working on making a brightness slider that can be reused easily
piping around IDS to correct places
This commit is contained in:
parent
442d0b0dad
commit
04fd9781ed
11 changed files with 79 additions and 20 deletions
|
@ -1,26 +1,20 @@
|
||||||
|
#include "BrightnessSlider.hpp"
|
||||||
#include "DisplaySettings.hpp"
|
#include "DisplaySettings.hpp"
|
||||||
#include "Slider.hpp"
|
|
||||||
|
|
||||||
using namespace UI::Page;
|
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(
|
mBrightnessSlider(AddElement<Widget::BrightnessSlider>(std::make_unique<Widget::BrightnessSlider>(mDisplay))) {
|
||||||
AddElement<Widget::Slider>(std::make_unique<Widget::Slider>(
|
|
||||||
[this](auto aNewBrightness) {
|
|
||||||
mDisplay->setBrightness(aNewBrightness);
|
|
||||||
},
|
|
||||||
0, 255))) {
|
|
||||||
SetBgColor(Color::GREY);
|
SetBgColor(Color::GREY);
|
||||||
auto usableWidth = GetContentWidth();
|
|
||||||
|
|
||||||
mBrightnessSlider->SetWidth(usableWidth - (usableWidth * 0.20f));
|
mBrightnessSlider->SetWidth(GetContentWidth());
|
||||||
mBrightnessSlider->SetHeight(lv_pct(10));
|
mBrightnessSlider->SetHeight(50);
|
||||||
mBrightnessSlider->AlignTo(this, LV_ALIGN_TOP_MID);
|
mBrightnessSlider->AlignTo(this, LV_ALIGN_TOP_MID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplaySettings::OnShow() {
|
void DisplaySettings::OnShow() {
|
||||||
mBrightnessSlider->SetValue(mDisplay->getBrightness());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void DisplaySettings::OnHide(){
|
void DisplaySettings::OnHide(){
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "PageBase.hpp"
|
#include "PageBase.hpp"
|
||||||
|
|
||||||
namespace UI::Widget {
|
namespace UI::Widget {
|
||||||
class Slider;
|
class BrightnessSlider;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace UI::Page {
|
namespace UI::Page {
|
||||||
|
@ -18,6 +18,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<DisplayAbstract> mDisplay;
|
std::shared_ptr<DisplayAbstract> mDisplay;
|
||||||
Widget::Slider *mBrightnessSlider;
|
Widget::BrightnessSlider *mBrightnessSlider;
|
||||||
};
|
};
|
||||||
} // namespace UI::Page
|
} // namespace UI::Page
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "SettingsPage.hpp"
|
#include "SettingsPage.hpp"
|
||||||
#include "BackgroundScreen.hpp"
|
#include "BackgroundScreen.hpp"
|
||||||
#include "Button.hpp"
|
#include "Button.hpp"
|
||||||
|
#include "Slider.hpp"
|
||||||
#include "Colors.hpp"
|
#include "Colors.hpp"
|
||||||
#include "DisplaySettings.hpp"
|
#include "DisplaySettings.hpp"
|
||||||
#include "PopUpScreen.hpp"
|
#include "PopUpScreen.hpp"
|
||||||
|
@ -30,8 +31,7 @@ void SettingsPage::PushDisplaySettings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsPage::AddSlider() {
|
void SettingsPage::AddSlider() {
|
||||||
auto fakeSlider = std::make_unique<UI::Widget::Base>(
|
auto fakeSlider = std::make_unique<Widget::Slider>([](auto data){});
|
||||||
lv_slider_create(UI::Screen::BackgroundScreen::getLvInstance()));
|
|
||||||
fakeSlider->SetHeight(lv_pct(10));
|
fakeSlider->SetHeight(lv_pct(10));
|
||||||
fakeSlider->SetWidth(GetContentWidth());
|
fakeSlider->SetWidth(GetContentWidth());
|
||||||
if (sliders.empty()) {
|
if (sliders.empty()) {
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
#include "BrightnessSlider.hpp"
|
||||||
|
#include "Label.hpp"
|
||||||
|
#include "Slider.hpp"
|
||||||
|
|
||||||
|
using namespace UI::Widget;
|
||||||
|
|
||||||
|
|
||||||
|
BrightnessSlider::BrightnessSlider(std::shared_ptr<DisplayAbstract> aDisplay): Base(ID::Widgets::BrightnessSlider),
|
||||||
|
mDisplay(aDisplay),
|
||||||
|
mSlider(AddElement<Widget::Slider>(std::make_unique<Slider>(
|
||||||
|
[this](auto aNewBrightness){
|
||||||
|
mDisplay->setBrightness(aNewBrightness);
|
||||||
|
},0,255))),
|
||||||
|
mLabel(AddElement<Widget::Label>(std::make_unique<Label>("Brightness")))
|
||||||
|
{
|
||||||
|
mLabel->AlignTo(this,LV_ALIGN_TOP_MID);
|
||||||
|
mSlider->AlignTo(mLabel,LV_ALIGN_OUT_BOTTOM_MID);
|
||||||
|
mSlider->SetWidth(GetContentWidth() - 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BrightnessSlider::OnShow(){
|
||||||
|
mSlider->SetValue(mDisplay->getBrightness());
|
||||||
|
}
|
||||||
|
|
||||||
|
void BrightnessSlider::SetHeight(lv_coord_t aHeight){
|
||||||
|
Base::SetHeight(aHeight);
|
||||||
|
auto labelHeight = GetContentHeight() * 0.25f;
|
||||||
|
auto sliderHeight = aHeight - labelHeight;
|
||||||
|
mLabel->SetHeight(labelHeight);
|
||||||
|
mSlider->SetHeight(sliderHeight);
|
||||||
|
mLabel->AlignTo(this,LV_ALIGN_TOP_MID);
|
||||||
|
mSlider->AlignTo(mLabel,LV_ALIGN_OUT_BOTTOM_MID);
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
#pragma once
|
||||||
|
#include "WidgetBase.hpp"
|
||||||
|
#include "DisplayAbstract.h"
|
||||||
|
|
||||||
|
namespace UI::Widget{
|
||||||
|
class Slider;
|
||||||
|
class Label;
|
||||||
|
|
||||||
|
class BrightnessSlider : public Base{
|
||||||
|
public:
|
||||||
|
BrightnessSlider(std::shared_ptr<DisplayAbstract> aDisplay);
|
||||||
|
|
||||||
|
void OnShow() override;
|
||||||
|
void SetHeight(lv_coord_t aHeight) override;
|
||||||
|
private:
|
||||||
|
std::shared_ptr<DisplayAbstract> mDisplay;
|
||||||
|
Slider* mSlider;
|
||||||
|
Label* mLabel;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -15,6 +15,9 @@ public:
|
||||||
|
|
||||||
enum class Widgets {
|
enum class Widgets {
|
||||||
Slider = static_cast<int>(Screens::INVALID_SCREEN_ID) + 1,
|
Slider = static_cast<int>(Screens::INVALID_SCREEN_ID) + 1,
|
||||||
|
Button,
|
||||||
|
Label,
|
||||||
|
BrightnessSlider,
|
||||||
INVALID_WIDGET_ID
|
INVALID_WIDGET_ID
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
using namespace UI::Widget;
|
using namespace UI::Widget;
|
||||||
|
|
||||||
Button::Button(std::function<void()> aOnPressHandler)
|
Button::Button(std::function<void()> aOnPressHandler)
|
||||||
: Base(lv_btn_create(UI::Screen::BackgroundScreen::getLvInstance())),
|
: Base(lv_btn_create(UI::Screen::BackgroundScreen::getLvInstance()),ID::Widgets::Button),
|
||||||
mOnPress(aOnPressHandler) {}
|
mOnPress(aOnPressHandler) {}
|
||||||
|
|
||||||
void Button::OnLvglEvent(lv_event_t *anEvent) {
|
void Button::OnLvglEvent(lv_event_t *anEvent) {
|
||||||
|
|
|
@ -5,6 +5,6 @@
|
||||||
using namespace UI::Widget;
|
using namespace UI::Widget;
|
||||||
|
|
||||||
Label::Label(std::string aText)
|
Label::Label(std::string aText)
|
||||||
: Base(lv_label_create(UI::Screen::BackgroundScreen::getLvInstance())) {
|
: Base(lv_label_create(UI::Screen::BackgroundScreen::getLvInstance()), ID::Widgets::Label) {
|
||||||
lv_label_set_text(LvglSelf(), aText.c_str());
|
lv_label_set_text(LvglSelf(), aText.c_str());
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ using namespace UI::Widget;
|
||||||
|
|
||||||
Slider::Slider(std::function<void(int32_t)> aOnSliderValueChange,
|
Slider::Slider(std::function<void(int32_t)> aOnSliderValueChange,
|
||||||
int32_t aMinVal, int32_t aMaxVal)
|
int32_t aMinVal, int32_t aMaxVal)
|
||||||
: Base(lv_slider_create(UI::Screen::BackgroundScreen::getLvInstance())),
|
: Base(lv_slider_create(UI::Screen::BackgroundScreen::getLvInstance()),ID::Widgets::Slider),
|
||||||
mOnSliderChange(std::move(aOnSliderValueChange)) {
|
mOnSliderChange(std::move(aOnSliderValueChange)) {
|
||||||
auto lock = LvglResourceManager::GetInstance().scopeLock();
|
auto lock = LvglResourceManager::GetInstance().scopeLock();
|
||||||
lv_slider_set_range(LvglSelf(), aMinVal, aMaxVal);
|
lv_slider_set_range(LvglSelf(), aMinVal, aMaxVal);
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
#include "WidgetBase.hpp"
|
#include "WidgetBase.hpp"
|
||||||
|
#include "BackgroundScreen.hpp"
|
||||||
|
|
||||||
|
using namespace UI;
|
||||||
using namespace UI::Widget;
|
using namespace UI::Widget;
|
||||||
|
|
||||||
Base::Base(lv_obj_t *aLvglSelf) : UIElement(aLvglSelf) {
|
Base::Base(ID anId): UIElement(lv_obj_create(Screen::BackgroundScreen::getLvInstance()),anId){
|
||||||
|
SetWidth(lv_pct(100));
|
||||||
|
SetHeight(lv_pct(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
Base::Base(lv_obj_t *aLvglSelf, ID anId) : UIElement(aLvglSelf,anId) {
|
||||||
SetWidth(lv_pct(100));
|
SetWidth(lv_pct(100));
|
||||||
SetHeight(lv_pct(100));
|
SetHeight(lv_pct(100));
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,8 @@ class Base : public UIElement {
|
||||||
public:
|
public:
|
||||||
typedef std::unique_ptr<Base> Ptr;
|
typedef std::unique_ptr<Base> Ptr;
|
||||||
|
|
||||||
Base(lv_obj_t *aLvglSelf);
|
Base(ID anId);
|
||||||
|
Base(lv_obj_t *aLvglSelf, ID anId);
|
||||||
virtual ~Base() override = default;
|
virtual ~Base() override = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Add table
Reference in a new issue