convert tab view to use onEvent to handle events instead of the manual registration.

remove padding from base page.
This commit is contained in:
MatthewColvin 2023-10-08 17:20:04 -05:00
parent dc5ad76994
commit a8c14d2b6f
3 changed files with 11 additions and 16 deletions

View file

@ -9,7 +9,7 @@ Base::Base(ID aID)
Base::Base(lv_obj_t *aLvglSelf, ID aID) : UIElement(aLvglSelf, aID) {
SetHeight(lv_pct(100));
SetWidth(lv_pct(100));
lv_obj_set_align(aLvglSelf, LV_ALIGN_CENTER);
SetPadding(Padding()); // Set Padding to default
}
// Return non owning refrence to widget
UI::Widget::Base *Base::AddWidget(Widget::Base::Ptr aWidget) {

View file

@ -29,10 +29,7 @@ void Tab::OnHide() { mContent->OnHide(); };
TabView::TabView(ID aId)
: Base(lv_tabview_create(Screen::BackgroundScreen::getLvInstance(),
LV_DIR_TOP, 0),
aId) {
lv_obj_add_event_cb(LvglSelf(), HandleTabChangeImpl, LV_EVENT_VALUE_CHANGED,
nullptr);
}
aId) {}
void TabView::AddTab(Page::Base::Ptr aPage, std::string aTitle) {
auto tab = std::make_unique<Tab>(
@ -64,17 +61,15 @@ void TabView::HandleTabChange() {
}
}
void TabView::HandleTabChangeImpl(lv_event_t *aTabChangeEvent) {
auto self =
UIElement::GetElement<TabView *>(lv_event_get_target(aTabChangeEvent));
if (self) {
self->HandleTabChange();
}
}
bool TabView::KeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) {
if (OnKeyEvent(aKeyEvent)) {
return true;
}
return mTabs[GetCurrentTabIdx()]->KeyEvent(aKeyEvent);
};
void TabView::OnLvglEvent(lv_event_t *anEvent) {
if (anEvent->code == LV_EVENT_VALUE_CHANGED) {
HandleTabChange();
}
}

View file

@ -37,12 +37,12 @@ public:
bool KeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) override;
protected:
void OnShow() {}
void OnHide() {}
void OnLvglEvent(lv_event_t *anEvent) override;
void OnShow() override {}
void OnHide() override {}
private:
void HandleTabChange();
static void HandleTabChangeImpl(lv_event_t *aTabChangeEvent);
std::vector<Page::Tab::Ptr> mTabs;
};