forked from CoretechR/OMOTE
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add start stop event handling in UIElement
Add demo page to get play logic out of settings page. Add a demo page and a Settings page to the home screen. Change-Id: I22274df5d64fae9b3212a59aa7da64fbefa1f222
- Loading branch information
Matthew Colvin
authored and
Matthew Colvin
committed
Oct 12, 2023
1 parent
7d5a1e0
commit c02bac3
Showing
10 changed files
with
171 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "Demo.hpp" | ||
#include "Slider.hpp" | ||
|
||
using namespace UI::Page; | ||
|
||
Demo::Demo(std::shared_ptr<HardwareAbstract> aHardware): Base(ID::Pages::Demo), mHardware(aHardware){ | ||
|
||
|
||
} | ||
|
||
void Demo::AddSlider() { | ||
auto fakeSlider = std::make_unique<Widget::Slider>([](auto data){}); | ||
fakeSlider->SetHeight(lv_pct(10)); | ||
fakeSlider->SetWidth(GetContentWidth()); | ||
if (sliders.empty()) { | ||
fakeSlider->AlignTo(this,LV_ALIGN_TOP_MID); | ||
} else { | ||
auto nextY = sliders.back()->GetY() + sliders.back()->GetHeight(); | ||
fakeSlider->SetY(nextY + 10); | ||
} | ||
|
||
sliders.push_back(AddElement(std::move(fakeSlider))); | ||
} | ||
|
||
bool Demo::OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) { | ||
using id = KeyPressAbstract::KeyId; | ||
using eventType = KeyPressAbstract::KeyEvent::Type; | ||
bool used = true; | ||
switch (aKeyEvent.mId) { | ||
case id::Aux1: | ||
if (aKeyEvent.mType == eventType::Press) { | ||
AddSlider(); | ||
} | ||
break; | ||
case id::Aux2: | ||
if (aKeyEvent.mType == eventType::Release) { | ||
if (sliders.size() > 0) { | ||
RemoveElement(sliders[0]); | ||
sliders.erase( | ||
sliders.begin()); // sliders is non owning so after removing delete | ||
// it from non owning array | ||
} | ||
} | ||
break; | ||
case id::Aux3: | ||
break; | ||
case id::Aux4: | ||
break; | ||
default: | ||
used = Page::Base::OnKeyEvent(aKeyEvent); | ||
break; | ||
} | ||
return used; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
#include "PageBase.hpp" | ||
#include "HardwareAbstract.hpp" | ||
|
||
namespace UI::Page{ | ||
|
||
class Demo : public Base{ | ||
public: | ||
Demo(std::shared_ptr<HardwareAbstract> aHardware); | ||
|
||
void AddSlider(); | ||
|
||
void OnShow()override{}; | ||
void OnHide()override{}; | ||
bool OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent); | ||
|
||
private: | ||
std::shared_ptr<HardwareAbstract> mHardware; | ||
std::vector<UIElement *> sliders; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "List.hpp" | ||
#include "BackgroundScreen.hpp" | ||
using namespace UI; | ||
using namespace UI::Widget; | ||
|
||
ListItem::ListItem(lv_obj_t *aListItem, std::function<void()> onItemSelected): | ||
UIElement(aListItem,ID()), | ||
mSelectedHandler(std::move(onItemSelected)){} | ||
|
||
void ListItem::OnLvglEvent(lv_event_t* anEvent){ | ||
if(anEvent->code == LV_EVENT_CLICKED){ | ||
if(mSelectedHandler){ | ||
mSelectedHandler(); | ||
} | ||
} | ||
} | ||
|
||
List::List():Base(lv_list_create(Screen::BackgroundScreen::getLvInstance()),ID::Widgets::List){ | ||
StopLvglEventHandler(); | ||
} | ||
|
||
void List::AddItem(std::string aTitle, const char* aSymbol, std::function<void()> onItemSelected){ | ||
auto lvListItem = lv_list_add_btn(LvglSelf(),aSymbol,aTitle.c_str()); | ||
mListItems.push_back(std::make_unique<ListItem>(lvListItem, std::move(onItemSelected))); | ||
mListItems.back()->SetHeight(lv_pct(20)); | ||
} | ||
|
||
void List::OnLvglEvent(lv_event_t* anEvent){ | ||
if(anEvent->code == LV_EVENT_CLICKED){ | ||
auto tgt = anEvent->target; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
#include "WidgetBase.hpp" | ||
|
||
namespace UI::Widget{ | ||
|
||
class ListItem : public UIElement{ | ||
public: | ||
ListItem(lv_obj_t* aListItem, std::function<void()> onItemSelected); | ||
protected: | ||
void OnLvglEvent(lv_event_t* anEvent) override; | ||
bool OnKeyEvent(KeyPressAbstract::KeyEvent anEvent)override{return false;}; | ||
void OnShow()override{}; | ||
void OnHide()override{}; | ||
private: | ||
std::function<void()> mSelectedHandler; | ||
}; | ||
|
||
class List : public Base{ | ||
public: | ||
List(); | ||
void AddItem(std::string aTitle, const char* aSymbol, std::function<void()> onItemSelected); | ||
|
||
protected: | ||
void OnLvglEvent(lv_event_t* anEvent)override; | ||
|
||
private: | ||
std::vector<UIElement::Ptr> mListItems; | ||
}; | ||
|
||
} |