6#include "structure/widget/spk_scalable_widget.hpp"
8#include "structure/widget/spk_frame.hpp"
9#include "structure/widget/spk_icon_button.hpp"
10#include "structure/widget/spk_linear_layout.hpp"
11#include "structure/widget/spk_text_label.hpp"
25 template <
typename TContentType>
36 spk::HorizontalLayout _layout;
45 bool _isDragging =
false;
46 bool _hasMouseFocus =
false;
47 spk::Vector2Int _dragStartMousePosition;
54 _layout.setGeometry(
geometry().atOrigin());
60 _background(p_name + L
"/Background",
this),
61 _titleLabel(p_name + L
"/TitleLabel",
this),
62 _minimizeButton(p_name + L
"/MinimizeButton",
this),
63 _maximizeButton(p_name + L
"/MaximizeButton",
this),
64 _closeButton(p_name + L
"/CloseButton",
this),
74 _titleLabel.
setAlignment(spk::HorizontalAlignment::Centered, spk::VerticalAlignment::Centered);
106 _layout.setPadding(2);
107 _layout.addElement(&_titleLabel, spk::Layout::SizePolicy::Extend);
108 _layout.addElement(&_minimizeButton, spk::Layout::SizePolicy::Desired);
109 _layout.addElement(&_maximizeButton, spk::Layout::SizePolicy::Desired);
110 _layout.addElement(&_closeButton, spk::Layout::SizePolicy::Desired);
113 return (_layout.sizeHint().minimal());
117 void setTitle(
const std::wstring &p_title)
123 void setHeight(
size_t p_height)
125 _minimizeButton.
sizeHint().
setDesired({
static_cast<uint32_t
>(p_height),
static_cast<uint32_t
>(p_height)});
126 _maximizeButton.
sizeHint().
setDesired({
static_cast<uint32_t
>(p_height),
static_cast<uint32_t
>(p_height)});
127 _closeButton.
sizeHint().
setDesired({
static_cast<uint32_t
>(p_height),
static_cast<uint32_t
>(p_height)});
129 _layout.sizeHint().release();
132 void toggleMaximizedMode()
134 if (_maximizeButton.
iconSpriteID() == spk::Vector2UInt{2, 0})
146 bool _isInsideTitleLabel(
const spk::Vector2Int &p_position)
const
151 void _releaseMouseFocus()
153 if (_hasMouseFocus ==
true)
156 _hasMouseFocus =
false;
162 if (p_event.
button != spk::Mouse::Button::Left || _isInsideTitleLabel(p_event.
mouse.
position) ==
false ||
163 _owner->_isMaximized ==
true)
170 _dragStartGeometry = _owner->
geometry();
172 if (
hasFocus(FocusType::Mouse) ==
false)
175 _hasMouseFocus =
true;
183 if (_isDragging ==
false)
188 spk::Vector2Int delta = p_event.
position - _dragStartMousePosition;
190 targetGeometry.anchor += delta;
198 if (_isDragging ==
false || p_event.
button != spk::Mouse::Button::Left)
204 _releaseMouseFocus();
211 if (p_event.
button != spk::Mouse::Button::Left || _isInsideTitleLabel(p_event.
mouse.
position) ==
false)
216 _owner->_toggleMaximizedMode();
221 spk::VerticalLayout _layout;
224 TContentType _content;
227 bool _isMaximized =
false;
233 void _toggleMaximizedMode()
235 _titleBar.toggleMaximizedMode();
237 _isMaximized = !_isMaximized;
242 _layout.setGeometry(
geometry().atOrigin());
253 _titleBar(p_name + L
"/TitleBar", this, this),
254 _content(p_name + L
"/Content", this)
256 _layout.setPadding(2);
257 _layout.addElement(&_titleBar, spk::Layout::SizePolicy::Standard);
258 _layout.addElement(&_content, spk::Layout::SizePolicy::Extend);
260 _minimizeContract = _titleBar._minimizeButton.subscribe([&]() {
263 _maximizeContract = _titleBar._maximizeButton.subscribe([&]() {
264 _toggleMaximizedMode();
266 _closeContract = _titleBar._closeButton.subscribe([&]() {
270 _titleBar.activate();
274 spk::Vector2UInt titleBarMinimalSize = _titleBar.sizeHint().minimal();
275 spk::Vector2UInt contentMinimalSize = _content.sizeHint().minimal();
277 return (spk::Vector2UInt{
278 std::max(titleBarMinimalSize.
x, contentMinimalSize.
x),
279 titleBarMinimalSize.
y + 2 + contentMinimalSize.
y});
290 _baseGeometry = p_geometry;
299 _titleBar.setTitle(p_title);
309 _titleBar.setHeight(p_height);
319 _maximizedGeometry = p_maximizedGeometry;
327 if (_isMaximized ==
false)
329 _toggleMaximizedMode();
338 _content.deactivate();
346 if (_content.isActive() ==
false)
351 if (_isMaximized ==
true)
353 _toggleMaximizedMode();
void deactivate()
Sets the state to Deactivated.
Definition spk_activable_object.hpp:61
void activate()
Sets the state to Activated.
Definition spk_activable_object.hpp:54
Widget frame rendered using a nine-slice background.
Definition spk_frame.hpp:19
void setCornerSize(const spk::Vector2UInt &p_cornerSize)
Sets the corner size for nine-slice rendering.
Definition spk_frame.cpp:22
void restore()
Restores the window content and geometry.
Definition spk_interface_window.hpp:344
TContentType & content()
Returns the content widget.
Definition spk_interface_window.hpp:361
const TContentType & content() const
Returns the content widget.
Definition spk_interface_window.hpp:370
InterfaceWindow(const std::wstring &p_name, spk::Widget *p_parent)
Builds an interface window widget.
Definition spk_interface_window.hpp:251
void setMaximizedSize(const spk::Extend2D &p_maximizedGeometry)
Sets the maximized window geometry.
Definition spk_interface_window.hpp:317
void setTitleBarHeight(size_t p_height)
Sets the title bar height.
Definition spk_interface_window.hpp:307
void setTitle(const std::wstring &p_title)
Sets the title bar text.
Definition spk_interface_window.hpp:297
void setGeometry(const spk::Extend2D &p_geometry) override
Sets the window geometry and updates base geometry.
Definition spk_interface_window.hpp:287
void minimize()
Minimizes the window content.
Definition spk_interface_window.hpp:336
void maximize()
Maximizes the window if not already maximized.
Definition spk_interface_window.hpp:325
void setDesired(const Vector2UInt &p_desiredValue)
Sets the desired size override.
Definition spk_resizable_element.cpp:63
void release()
Releases all cached size hint values.
Definition spk_resizable_element.cpp:36
void configureMinimalGenerator(Generator p_generator)
Configures the minimal size generator.
Definition spk_resizable_element.cpp:21
SizeHint & sizeHint()
Returns mutable size hint data.
Definition spk_resizable_element.cpp:86
Widget that renders a text region over a nine-slice background.
Definition spk_text_label.hpp:20
void setTexture(const spk::SpriteSheet *p_spriteSheet)
Assigns the sprite sheet used for the background.
Definition spk_text_label.cpp:30
void setText(const std::wstring &p_text)
Updates the label text.
Definition spk_text_label.cpp:77
void setAlignment(HorizontalAlignment p_horizontalAlignment, VerticalAlignment p_verticalAlignment)
Sets the horizontal and vertical alignment for the text.
Definition spk_text_label.cpp:88
void setCornerSize(const spk::Vector2UInt &p_cornerSize)
Sets the corner size for the nine-slice background.
Definition spk_text_label.cpp:18
Axis-aligned rectangle defined by an anchor point and size.
Definition spk_extend_2d.hpp:24
bool contains(const Vector2Int &p_point) const
Tests whether a point lies within the rectangle bounds.
Definition spk_extend_2d.cpp:43
bool isConsumed
Indicates whether the event has been handled.
Definition spk_ievent.hpp:17
TType x
X component.
Definition spk_vector2.hpp:44
TType y
Y component.
Definition spk_vector2.hpp:48
Mouse button double-click event.
Definition spk_mouse_event.hpp:38
const Mouse & mouse
Snapshot of mouse state at double-click time.
Definition spk_mouse_event.hpp:43
Mouse::Button button
Mouse button that triggered the double click.
Definition spk_mouse_event.hpp:40
spk::Vector2Int position
Current cursor position.
Definition spk_mouse.hpp:39
Mouse move event carrying current position.
Definition spk_mouse_event.hpp:50
spk::Vector2Int position
Current cursor position in window coordinates.
Definition spk_mouse_event.hpp:52
Mouse button press event.
Definition spk_mouse_event.hpp:14
const Mouse & mouse
Snapshot of mouse state at press time.
Definition spk_mouse_event.hpp:19
Mouse::Button button
Mouse button that was pressed.
Definition spk_mouse_event.hpp:16
Mouse button release event.
Definition spk_mouse_event.hpp:26
Mouse::Button button
Mouse button that was released.
Definition spk_mouse_event.hpp:28