bool TabContainerWindow::OnEvent(const TBWidgetEvent &ev) { if (ev.type == EVENT_TYPE_CLICK && ev.target->GetID() == TBIDC("set_align")) { if (TBTabContainer *tc = GetWidgetByIDAndType<TBTabContainer>(TBIDC("tabcontainer"))) tc->SetAlignment(static_cast<TB_ALIGN>(ev.target->data.GetInt())); ResizeToFitContent(RESIZE_FIT_CURRENT_OR_NEEDED); } else if (ev.type == EVENT_TYPE_CLICK && ev.target->GetID() == TBIDC("toggle_tab_axis")) { static AXIS axis = AXIS_X; axis = axis == AXIS_X ? AXIS_Y : AXIS_X; if (TBTabContainer *tc = GetWidgetByIDAndType<TBTabContainer>(TBIDC("tabcontainer"))) { for (TBWidget *child = tc->GetTabLayout()->GetFirstChild(); child; child = child->GetNext()) { if (TBButton *button = TBSafeCast<TBButton>(child)) button->SetAxis(axis); } } ResizeToFitContent(RESIZE_FIT_CURRENT_OR_NEEDED); } else if (ev.type == EVENT_TYPE_CLICK && ev.target->GetID() == TBIDC("start_spinner")) { if (TBProgressSpinner *spinner = GetWidgetByIDAndType<TBProgressSpinner>(TBIDC("spinner"))) spinner->SetValue(1); } else if (ev.type == EVENT_TYPE_CLICK && ev.target->GetID() == TBIDC("stop_spinner")) { if (TBProgressSpinner *spinner = GetWidgetByIDAndType<TBProgressSpinner>(TBIDC("spinner"))) spinner->SetValue(0); } return DemoWindow::OnEvent(ev); }
//static void TBRadioCheckBox::ToggleGroup(TBWidget *root, TBWidget *toggled) { if (root != toggled && root->GetGroupID() == toggled->GetGroupID()) root->SetValue(0); for (TBWidget *child = root->GetFirstChild(); child; child = child->GetNext()) ToggleGroup(child, toggled); }
void TBTabContainer::SetCurrentPage(int index) { if (index == m_current_page) return; m_current_page = index; // Update the pages visibility and tabs pressed value. index = 0; TBWidget *page = m_content_root.GetFirstChild(); TBWidget *tab = m_tab_layout.GetFirstChild(); for ( ; page && tab; page = page->GetNext(), tab = tab->GetNext(), index++) { bool active = index == m_current_page; page->SetOpacity(active ? 1.0f : 0.0f); tab->SetValue(active ? 1 : 0); } }
int TBTabLayout::GetIndexFromChild(TBWidget *child) const { int index = 0; for (TBWidget *tmp = GetFirstChild(); tmp; tmp = tmp->GetNext(), index++) if (tmp == child) return index; return -1; }
TBWidget *TBSelectList::GetItemWidget(int index) { if (index == -1) return nullptr; for (TBWidget *tmp = m_layout.GetContentRoot()->GetFirstChild(); tmp; tmp = tmp->GetNext()) if (tmp->data.GetInt() == index) return tmp; return nullptr; }
void JSUI::GatherWidgets(tb::TBWidget* widget, PODVector<tb::TBWidget*>& widgets) { if (widget->GetID() != TBID()) widgets.Push(widget); for (TBWidget *n = widget->GetFirstChild(); n; n = n->GetNext()) { GatherWidgets(n, widgets); } }
int TBTabContainer::GetNumPages() { int count = 0; for (TBWidget *tab = m_tab_layout.GetFirstChild(); tab; tab = tab->GetNext()) count++; if (!count) m_current_page = -1; return count; }
void TBTabContainer::SetValue(int index) { if (index == m_current_page || !GetNumPages()) return; m_current_page = index; // Update the pages visibility and tabs pressed value. index = 0; TBWidget *page = m_content_root.GetFirstChild(); TBWidget *tab = m_tab_layout.GetFirstChild(); for ( ; page && tab; page = page->GetNext(), tab = tab->GetNext(), index++) { bool active = index == m_current_page; page->SetVisibilility(active ? WIDGET_VISIBILITY_VISIBLE : WIDGET_VISIBILITY_INVISIBLE); tab->SetValue(active ? 1 : 0); } TBWidgetEvent ev(EVENT_TYPE_TAB_CHANGED); InvokeEvent(ev); }
void ResourceEditWindow::AddWidgetListItemsRecursive(TBWidget *widget, int depth) { if (depth > 0) // Ignore the root { // Add a new ResourceItem for this widget TBStr str; const char *classname = widget->GetClassName(); if (!*classname) classname = "<Unknown widget type>"; str.SetFormatted("% *s%s", depth - 1, "", classname); if (ResourceItem *item = new ResourceItem(widget, str)) m_widget_list_source.AddItem(item); } for (TBWidget *child = widget->GetFirstChild(); child; child = child->GetNext()) AddWidgetListItemsRecursive(child, depth + 1); }
bool TBSelectList::ChangeValue(SPECIAL_KEY key) { if (!m_source || !m_layout.GetContentRoot()->GetFirstChild()) return false; bool forward; if (key == TB_KEY_HOME || key == TB_KEY_DOWN) forward = true; else if (key == TB_KEY_END || key == TB_KEY_UP) forward = false; else return false; TBWidget *item_root = m_layout.GetContentRoot(); TBWidget *current = GetItemWidget(m_value); TBWidget *origin = nullptr; if (key == TB_KEY_HOME || (!current && key == TB_KEY_DOWN)) current = item_root->GetFirstChild(); else if (key == TB_KEY_END || (!current && key == TB_KEY_UP)) current = item_root->GetLastChild(); else origin = current; while (current) { if (current != origin && !current->GetDisabled()) break; current = forward ? current->GetNext() : current->GetPrev(); } // Select and focus what we found if (current) { SetValue(current->data.GetInt()); return true; } return false; }