added ability to adjust brightness slider height easily
This commit is contained in:
parent
04fd9781ed
commit
0a397706af
6 changed files with 44 additions and 26 deletions
|
@ -9,7 +9,7 @@ DisplaySettings::DisplaySettings(std::shared_ptr<DisplayAbstract> aDisplay)
|
|||
SetBgColor(Color::GREY);
|
||||
|
||||
mBrightnessSlider->SetWidth(GetContentWidth());
|
||||
mBrightnessSlider->SetHeight(50);
|
||||
mBrightnessSlider->SetHeight(80);
|
||||
mBrightnessSlider->AlignTo(this, LV_ALIGN_TOP_MID);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,30 +4,30 @@
|
|||
|
||||
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);
|
||||
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() - GetContentWidth() * 0.25f);
|
||||
}
|
||||
|
||||
void BrightnessSlider::OnShow(){
|
||||
mSlider->SetValue(mDisplay->getBrightness());
|
||||
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);
|
||||
void BrightnessSlider::SetHeight(lv_coord_t aHeight) {
|
||||
Base::SetHeight(aHeight);
|
||||
auto labelHeight = 12;
|
||||
auto sliderHeight = aHeight * 0.60f - labelHeight;
|
||||
mLabel->SetHeight(labelHeight);
|
||||
mSlider->SetHeight(sliderHeight);
|
||||
mLabel->AlignTo(this, LV_ALIGN_TOP_MID);
|
||||
mSlider->AlignTo(mLabel, LV_ALIGN_OUT_BOTTOM_MID, 0,
|
||||
mLabel->GetContentHeight());
|
||||
}
|
|
@ -243,6 +243,12 @@ void UIElement::SetBgColor(lv_color_t aColor, lv_style_selector_t aStyle) {
|
|||
});
|
||||
};
|
||||
|
||||
void UIElement::SetBgOpacity(lv_opa_t aOpacity, lv_style_selector_t aStyle) {
|
||||
LvglResourceManager::GetInstance().AttemptNow([this, aOpacity, aStyle] {
|
||||
lv_obj_set_style_bg_opa(mLvglSelf, aOpacity, aStyle);
|
||||
});
|
||||
}
|
||||
|
||||
void UIElement::Show() {
|
||||
if (IsVisible()) {
|
||||
return;
|
||||
|
|
|
@ -21,6 +21,9 @@ public:
|
|||
virtual void SetBgColor(lv_color_t value,
|
||||
lv_style_selector_t selector = LV_PART_MAIN);
|
||||
|
||||
virtual void SetBgOpacity(lv_opa_t aOpacity,
|
||||
lv_style_selector_t aStyle = LV_PART_MAIN);
|
||||
|
||||
void SetVisiblity(bool aVisibility);
|
||||
bool IsVisible();
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ 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()),ID::Widgets::Slider),
|
||||
: Base(lv_slider_create(UI::Screen::BackgroundScreen::getLvInstance()),
|
||||
ID::Widgets::Slider),
|
||||
mOnSliderChange(std::move(aOnSliderValueChange)) {
|
||||
auto lock = LvglResourceManager::GetInstance().scopeLock();
|
||||
lv_slider_set_range(LvglSelf(), aMinVal, aMaxVal);
|
||||
|
|
|
@ -4,12 +4,20 @@
|
|||
using namespace UI;
|
||||
using namespace UI::Widget;
|
||||
|
||||
Base::Base(ID anId): UIElement(lv_obj_create(Screen::BackgroundScreen::getLvInstance()),anId){
|
||||
// Constructor typically used as a container for other widgets
|
||||
Base::Base(ID anId)
|
||||
: UIElement(lv_obj_create(Screen::BackgroundScreen::getLvInstance()),
|
||||
anId) {
|
||||
SetWidth(lv_pct(100));
|
||||
SetHeight(lv_pct(100));
|
||||
SetPadding(Padding());
|
||||
SetOutline(Outline());
|
||||
SetBorder(Border());
|
||||
SetBgOpacity(LV_OPA_TRANSP);
|
||||
}
|
||||
|
||||
Base::Base(lv_obj_t *aLvglSelf, ID anId) : UIElement(aLvglSelf,anId) {
|
||||
Base::Base(lv_obj_t *aLvglSelf, ID anId) : UIElement(aLvglSelf, anId) {
|
||||
SetWidth(lv_pct(100));
|
||||
SetHeight(lv_pct(100));
|
||||
SetBorder(Border());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue