14#include "structure/design_pattern/spk_contract_provider.hpp"
15#include "structure/widget/spk_frame.hpp"
16#include "structure/widget/spk_linear_layout.hpp"
17#include "structure/widget/spk_push_button.hpp"
18#include "structure/widget/spk_scrollable_area.hpp"
19#include "structure/widget/spk_widget.hpp"
44 Item(
const std::wstring &p_name,
spk::Widget *p_parent);
46 void setText(
const std::wstring &p_text);
53 spk::VerticalLayout _layout;
54 std::vector<std::unique_ptr<Item>> _items;
60 ListContent(
const std::wstring &p_name,
spk::Widget *p_parent);
62 Item &addItem(
const std::wstring &p_name,
const std::wstring &p_text);
63 void removeItem(
size_t p_index);
65 spk::Vector2UInt maxItemMinimal()
const;
73 std::optional<uint32_t> _maxHeight;
76 void _refreshContentGeometry();
77 uint32_t _resolveHeight(uint32_t p_contentHeight)
const;
83 Popup(
const std::wstring &p_name,
spk::Widget *p_parent);
85 ListContent &content();
86 const ListContent &content()
const;
87 spk::Vector2UInt backgroundPadding()
const;
88 void updateContentGeometry();
91 void setMaxPopupHeight(uint32_t p_height);
92 uint32_t maxPopupHeight()
const;
93 uint32_t resolvedHeight(uint32_t p_contentHeight)
const;
94 void setScrollBarWidth(
size_t p_scrollBarWidth);
95 size_t scrollBarWidth()
const;
107 std::vector<Entry> _entries;
108 std::optional<size_t> _currentIndex;
109 bool _isPopupOpen =
false;
111 std::vector<spk::PushButton::Contract> _itemContracts;
112 spk::Vector2Int _popupOffset{0, 2};
115 void _refreshPopupGeometry();
116 void _setPopupOpen(
bool p_open);
117 void _refreshDisplay();
118 void _addEntry(
const std::wstring &p_text, std::any p_value);
119 void _selectIndex(
size_t p_index);
120 void _updateMaxEntryMinimal();
121 void _refreshSizeHint();
122 bool _needsPopupVerticalScrollBar()
const;
144 template <
typename TValue>
145 void addElement(
const std::wstring &p_text, TValue &&p_value)
147 _addEntry(p_text, std::any(std::forward<TValue>(p_value)));
162 template <
typename TValue>
165 if (_currentIndex.has_value() ==
false)
167 throw std::runtime_error(
"ComboBox has no current value.");
170 return std::any_cast<TValue>(_entries[_currentIndex.value()].value);
207 const Popup &
popup()
const;
void openPopup()
Opens the popup list.
Definition spk_combo_box.cpp:476
Popup & popup()
Returns the popup widget.
Definition spk_combo_box.cpp:576
void _onGeometryChange() override
Updates popup and layout when geometry changes.
Definition spk_combo_box.cpp:481
TValue currentValue() const
Returns the current value cast to the requested type.
Definition spk_combo_box.hpp:163
ComboBox(const std::wstring &p_name, spk::Widget *p_parent)
Builds a combo box widget.
Definition spk_combo_box.cpp:491
void removeElement(const std::wstring &p_text)
Removes an element by its display text.
Definition spk_combo_box.cpp:426
const std::wstring & currentText() const
Returns the current display text.
Definition spk_combo_box.cpp:566
void selectElement(const std::wstring &p_text)
Selects an element by its display text.
Definition spk_combo_box.cpp:407
void addElement(const std::wstring &p_text, TValue &&p_value)
Adds an element to the combo box.
Definition spk_combo_box.hpp:145
Widget frame rendered using a nine-slice background.
Definition spk_frame.hpp:19
Scrollable container that hosts a content widget.
Definition spk_scrollable_area.hpp:31
static const IVector2 Zero
Definition spk_vector2.hpp:96