5#ifndef MALENA_TABBEDPANEL_H
6#define MALENA_TABBEDPANEL_H
92 std::unique_ptr<ml::Core> content;
100 std::vector<Tab> _tabs;
102 int _hoveredIdx = -1;
110 std::vector<std::unique_ptr<ml::Core>> _pendingDelete;
112 std::function<void(std::size_t,
const std::string&)> _onTabChanged;
113 std::function<void(std::size_t,
const std::string&)> _onTabClosed;
116 void computeTabLayout();
118 bool hitTestClose(
int tabIdx,
const sf::Vector2f& wp)
const;
125 void drawStrip(sf::RenderTarget& target,
const sf::RenderStates& states)
const;
126 void drawTab(sf::RenderTarget& target,
const sf::RenderStates& states,
127 int idx,
bool active,
bool hovered)
const;
144 static_assert(std::is_base_of_v<TabbedPanelSettings, S>,
145 "applySettings() requires TabbedPanelSettings");
153 static_assert(std::is_base_of_v<TabbedPanelTheme, T>,
154 "applyTheme() requires TabbedPanelTheme");
158 template<
typename St>
161 static_assert(std::is_base_of_v<TabbedPanelSettings, St> &&
162 std::is_base_of_v<TabbedPanelTheme, St>,
163 "applyStyle() requires TabbedPanelSettings and TabbedPanelTheme");
188 std::unique_ptr<T> content,
192 static_assert(std::is_base_of_v<ml::Core, T>,
193 "addTab() content must derive from ml::Core");
195 T* ptr = content.get();
199 tab.content = std::move(content);
203 if constexpr (detail::has_setSize<T>::value)
204 tab.resizeFn = [ptr](
sf::Vector2f sz){ ptr->setSize(sz); };
206 _tabs.push_back(std::move(tab));
228 [[nodiscard]]
int activeTab()
const {
return _activeIdx; }
231 [[nodiscard]] std::size_t
tabCount()
const {
return _tabs.size(); }
250 void onTabChanged(std::function<
void(std::size_t,
const std::string&)> cb);
253 void onTabClosed(std::function<
void(std::size_t,
const std::string&)> cb);
265 template<
typename MANIFEST>
static const sf::Font & getDefault()
Return the built-in Arial font.
Base class for all Malena manifests.
T & addTab(const std::string &label, std::unique_ptr< T > content, const sf::Texture *icon=nullptr, bool closeable=false)
Add a tab with owned content.
TabbedPanelSettings::TabPosition TabPosition
sf::FloatRect getGlobalBounds() const override
TabbedPanel(const TabbedPanel &)=delete
void applySettings(const S &s)
TabbedPanel & operator=(const TabbedPanel &)=delete
sf::Vector2f contentSize() const
Return the content area size.
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
TabbedPanel(const sf::Font &font=FontManager<>::getDefault())
TabbedPanelManifest::State State
void onTabClosed(std::function< void(std::size_t, const std::string &)> cb)
Fired when a tab is closed via the × button.
void selectTab(std::size_t index)
Programmatically select a tab by index.
void applyStyle(const St &s)
TabbedPanelManifest::Flag Flag
sf::Vector2f getPosition() const override
void onThemeApplied(const Theme &theme) override
Called by ThemeManager when the active theme changes.
int activeTab() const
Return the currently active tab index, or -1 if no tabs.
std::size_t tabCount() const
Return the number of tabs.
sf::Vector2f getSize() const
void setPosition(const sf::Vector2f &position) override
void setSize(const sf::Vector2f &size)
void onTabChanged(std::function< void(std::size_t, const std::string &)> cb)
Fired when the active tab changes.
void removeTab(std::size_t index)
Remove a tab by index.
void applyTheme(const T &t)
TabbedPanel(const sf::Font &font=FontManager<>::getDefault())
Component< M, Traits... > ComponentWith
Alias for Component<M, Traits...>.
Vector2< float > Vector2f
bool closeable
show × on all tabs by default
Universal design token set applied across all Themeable components.