Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_command_panel.hpp
1#pragma once
2
3#include <memory>
4#include <string>
5#include <unordered_map>
6#include <vector>
7
8#include "structure/widget/spk_layout.hpp"
9#include "structure/widget/spk_linear_layout.hpp"
10#include "structure/widget/spk_push_button.hpp"
11#include "structure/widget/spk_spacer_widget.hpp"
12#include "structure/widget/spk_widget.hpp"
13#include "type/spk_text_aligmnent.hpp"
14
15namespace spk
16{
26 class CommandPanel : public Widget
27 {
28 public:
34 CommandPanel(const std::wstring &p_name, Widget *p_parent);
35
42 PushButton &addButton(const std::wstring &p_name, const std::wstring &p_text);
48 PushButton *button(const std::wstring &p_name);
53 void removeButton(const std::wstring &p_name);
54
59 void setElementPadding(size_t p_elementPadding);
64 const uint32_t &elementPadding() const;
65
70 void setAlignment(HorizontalAlignment p_alignment);
75 HorizontalAlignment alignment() const noexcept;
86
87 protected:
91 void _onGeometryChange() override;
92
93 private:
94 static std::wstring _buttonWidgetName(const std::wstring &p_name);
95 void _refreshLayout();
96
97 HorizontalLayout _layout;
98 SpacerWidget _leadingSpacer;
99 SpacerWidget _trailingSpacer;
100
101 std::vector<PushButton *> _orderedButtons;
102 std::unordered_map<std::wstring, PushButton *> _buttons;
103 std::vector<std::unique_ptr<PushButton>> _ownedButtons;
104
105 HorizontalAlignment _alignment = HorizontalAlignment::Right;
106 Layout::SizePolicy::Value _buttonSizePolicy = Layout::SizePolicy::Standard;
107 };
108}
CommandPanel(const std::wstring &p_name, Widget *p_parent)
Builds a command panel widget.
Definition spk_command_panel.cpp:7
void _onGeometryChange() override
Updates geometry when layout changes.
Definition spk_command_panel.cpp:125
const uint32_t & elementPadding() const
Returns the spacing between buttons.
Definition spk_command_panel.cpp:88
PushButton & addButton(const std::wstring &p_name, const std::wstring &p_text)
Adds a button with a name and display text.
Definition spk_command_panel.cpp:28
Layout::SizePolicy::Value buttonSizePolicy() const noexcept
Returns the button size policy.
Definition spk_command_panel.cpp:120
PushButton * button(const std::wstring &p_name)
Finds a button by name.
Definition spk_command_panel.cpp:51
void setElementPadding(size_t p_elementPadding)
Sets spacing between buttons.
Definition spk_command_panel.cpp:81
HorizontalAlignment alignment() const noexcept
Returns the current horizontal alignment.
Definition spk_command_panel.cpp:104
void setButtonSizePolicy(Layout::SizePolicy::Value p_policy)
Sets the button size policy.
Definition spk_command_panel.cpp:109
void removeButton(const std::wstring &p_name)
Removes a button by name.
Definition spk_command_panel.cpp:57
void setAlignment(HorizontalAlignment p_alignment)
Sets the horizontal alignment of the panel.
Definition spk_command_panel.cpp:93
Button widget displaying text with background visuals.
Definition spk_push_button.hpp:21
Empty widget used to add spacing in layouts.
Definition spk_spacer_widget.hpp:12
Widget(const std::wstring &p_name, Widget *p_parent)
Builds a widget optionally attached to a parent.
Definition spk_widget.cpp:103
Value
Policy value controlling sizing behavior.
Definition spk_layout.hpp:37