Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_tab_widget.hpp
1#pragma once
2
3#include <cstddef>
4#include <memory>
5#include <optional>
6#include <string>
7#include <vector>
8
9#include "structure/widget/spk_command_panel.hpp"
10#include "structure/widget/spk_linear_layout.hpp"
11#include "structure/widget/spk_push_button.hpp"
12#include "structure/widget/spk_widget.hpp"
13
14namespace spk
15{
25 class TabWidget : public spk::Widget
26 {
27 private:
28 struct Tab
29 {
30 spk::PushButton *button;
31 std::unique_ptr<spk::Widget> content;
33 };
34
35 spk::CommandPanel _tabBar;
36 spk::Widget _contentContainer;
37 spk::VerticalLayout _layout;
38 std::vector<Tab> _tabs;
39 std::optional<size_t> _activeIndex;
40 spk::Vector2UInt _tabCornerSize{4, 4};
41
42 void _refreshContentGeometry();
43 void _refreshSizeHints();
44 void _addTab(const std::wstring &p_label, std::unique_ptr<spk::Widget> p_content);
45
46 spk::Vector2UInt _activeContentMinimal() const;
47 spk::Vector2UInt _activeContentDesired() const;
48 spk::Vector2UInt _activeContentMaximal() const;
49 spk::Vector2UInt _maxContentMinimal() const;
50 spk::Vector2UInt _maxContentDesired() const;
51 spk::Vector2UInt _maxContentMaximal() const;
52
53 protected:
57 void _onGeometryChange() override;
58
59 public:
65 TabWidget(const std::wstring &p_name, spk::Widget *p_parent);
66
67 template <typename TContent, typename... TArgs>
77 TContent &addTab(const std::wstring &p_label, const std::wstring &p_contentName, TArgs &&...p_args)
78 {
79 auto content = std::make_unique<TContent>(p_contentName, &_contentContainer, std::forward<TArgs>(p_args)...);
80 TContent &contentRef = *content;
81 _addTab(p_label, std::move(content));
82 return contentRef;
83 }
84
90 void addTab(const std::wstring &p_label, std::unique_ptr<spk::Widget> p_content);
95 void setActiveIndex(size_t p_index);
100 std::optional<size_t> activeIndex() const;
105 size_t tabCount() const;
106
111 void setTabAlignment(spk::HorizontalAlignment p_alignment);
116 spk::HorizontalAlignment tabAlignment() const;
117 };
118}
Horizontal panel that manages a collection of command buttons.
Definition spk_command_panel.hpp:27
Button widget displaying text with background visuals.
Definition spk_push_button.hpp:21
spk::TContractProvider<>::Contract Contract
Contract type for click subscriptions.
Definition spk_push_button.hpp:26
size_t tabCount() const
Returns the number of tabs.
Definition spk_tab_widget.cpp:221
TContent & addTab(const std::wstring &p_label, const std::wstring &p_contentName, TArgs &&...p_args)
Adds a new tab with constructed content.
Definition spk_tab_widget.hpp:77
spk::HorizontalAlignment tabAlignment() const
Returns the tab alignment.
Definition spk_tab_widget.cpp:233
void setActiveIndex(size_t p_index)
Sets the active tab index.
Definition spk_tab_widget.cpp:187
void _onGeometryChange() override
Updates layout geometry when size changes.
Definition spk_tab_widget.cpp:144
TabWidget(const std::wstring &p_name, spk::Widget *p_parent)
Builds a tab widget.
Definition spk_tab_widget.cpp:150
std::optional< size_t > activeIndex() const
Returns the active tab index.
Definition spk_tab_widget.cpp:216
void setTabAlignment(spk::HorizontalAlignment p_alignment)
Sets tab alignment in the tab bar.
Definition spk_tab_widget.cpp:226
Base class for interactive UI elements handling focus and events.
Definition spk_widget.hpp:52