#include "tab_bar.hpp" namespace dusk::ui { namespace { Rml::Element* createRoot(Rml::Element* parent) { auto* doc = parent->GetOwnerDocument(); auto elem = doc->CreateElement("tab-bar"); return parent->AppendChild(std::move(elem)); } } // namespace TabBar::TabBar(Rml::Element* parent, Props props) : FluentComponent(createRoot(parent)), mProps(std::move(props)) { listen(Rml::EventId::Keydown, [this](Rml::Event& event) { const auto cmd = map_nav_event(event); if (cmd != NavCommand::None && handle_nav_command(event, cmd)) { event.StopPropagation(); } }); } bool TabBar::focus() { if (mProps.selectedTabIndex >= 0 && mProps.selectedTabIndex < mTabs.size()) { // Try to focus the currently selected tab if (mTabs[mProps.selectedTabIndex].button.focus()) { return true; } } // Otherwise, focus the first enabled tab for (const auto& tab : mTabs) { if (tab.button.focus()) { return true; } } return false; } void TabBar::add_tab(const Rml::String& title, TabCallback callback) { const int index = static_cast(mTabs.size()); const bool selected = index == mProps.selectedTabIndex; if (selected && callback) { callback(); } auto& button = add_child