Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_workspace.hpp
1#pragma once
2
3#include <string>
4
5#include "structure/widget/spk_menu_bar.hpp"
6#include "structure/widget/spk_widget.hpp"
7
8namespace spk
9{
21 template <typename TContentType>
22 class Workspace : public spk::Widget
23 {
24 private:
25 spk::MenuBar _menuBar;
26 TContentType _content;
27
28 void _onGeometryChange() override
29 {
30 _menuBar.setGeometry(geometry().atOrigin());
31
32 spk::Extend2D contentGeometry = {
33 {0, _menuBar.height()},
34 {geometry().size.x, geometry().size.y - _menuBar.height()}};
35
36 _content.setGeometry(contentGeometry);
37 }
38
39 public:
45 Workspace(const std::wstring &p_name, spk::Widget *p_parent) :
46 spk::Widget(p_name, p_parent),
47 _menuBar(p_name + L"/MenuBar", this),
48 _content(p_name + L"/Content", this)
49 {
50 _menuBar.setLayer(10);
51 _content.setLayer(1);
52
53 _menuBar.activate();
54 _content.activate();
55
57 uint32_t width = std::max(_menuBar.sizeHint().minimal().x, _content.sizeHint().minimal().x);
58 uint32_t height = _menuBar.height() + _content.sizeHint().minimal().y;
59
60 return (spk::Vector2UInt(width, height));
61 });
62 }
63
69 {
70 return (_menuBar);
71 }
72
77 const spk::MenuBar &menuBar() const
78 {
79 return (_menuBar);
80 }
81
86 TContentType &content()
87 {
88 return (_content);
89 }
90
95 const TContentType &content() const
96 {
97 return (_content);
98 }
99 };
100}
Menu bar widget hosting top-level menus.
Definition spk_menu_bar.hpp:28
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
Base class for interactive UI elements handling focus and events.
Definition spk_widget.hpp:52
void setGeometry(const spk::Extend2D &p_geometry) override
Requests a specific viewport and scissor region for the widget.
Definition spk_widget.cpp:168
virtual void _onGeometryChange()
Notifies derived widgets that the view region changed.
Definition spk_widget.cpp:292
const spk::Extend2D & geometry() const
Returns the current widget geometry.
Definition spk_widget.cpp:195
Widget(const std::wstring &p_name, Widget *p_parent)
Builds a widget optionally attached to a parent.
Definition spk_widget.cpp:103
TContentType & content()
Accesses the workspace content widget.
Definition spk_workspace.hpp:86
const TContentType & content() const
Accesses the workspace content widget.
Definition spk_workspace.hpp:95
spk::MenuBar & menuBar()
Accesses the workspace menu bar.
Definition spk_workspace.hpp:68
const spk::MenuBar & menuBar() const
Accesses the workspace menu bar.
Definition spk_workspace.hpp:77
Workspace(const std::wstring &p_name, spk::Widget *p_parent)
Builds a workspace with a menu bar and content widget.
Definition spk_workspace.hpp:45
Axis-aligned rectangle defined by an anchor point and size.
Definition spk_extend_2d.hpp:24
TType x
X component.
Definition spk_vector2.hpp:44
TType y
Y component.
Definition spk_vector2.hpp:48