guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
common_button.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <optional>
26
27#include "guillaume/ecs/component.hpp"
28#include "guillaume/ecs/entity.hpp"
29
31{
32
56 {
57 public:
67 enum class Color { Elevated, Filled, Tonal, Outlined, Text, Segmented };
68
73 enum class Shape { Round, Square };
74
80 enum class Size { ExtraSmall, Small, Medium, Large, ExtraLarge };
81
83 static constexpr float MinWidth = 64.0f;
84
87 static constexpr float MinHeight = 40.0f;
88
93 struct Corners {
94 float topLeft { 0.0f };
95 float topRight { 0.0f };
96 float bottomRight { 0.0f };
97 float bottomLeft { 0.0f };
98
104 bool operator==(const Corners &other) const = default;
105 };
106
107 private:
108 Color _colorStyle { Color::Text };
109 Shape _shape { Shape::Round };
110 Size _size { Size::Small };
111 bool _compact {
112 false
113 };
114
115 float _minWidth { 0.0f };
116 bool _uppercase { false };
117 std::optional<Corners> _corners {};
118
119 public:
123 CommonButton(void) = default;
124
128 ~CommonButton(void) = default;
129
134 Color getColorStyle(void) const noexcept;
135
142
147 Shape getShape(void) const noexcept;
148
159
164 Size getSize(void) const noexcept;
165
172
177 bool isCompact(void) const noexcept;
178
184 CommonButton &setCompact(bool compact);
185
190 float getMinWidth(void) const noexcept;
191
200 CommonButton &setMinWidth(float width);
201
206 bool isUppercase(void) const noexcept;
207
216 CommonButton &setUppercase(bool uppercase);
217
223 const std::optional<Corners> &getCorners(void) const noexcept;
224
234 CommonButton &setCorners(const std::optional<Corners> &corners);
235 };
236
237} // namespace guillaume::components
CommonButton & setCorners(const std::optional< Corners > &corners)
Override the radius of each corner.
CommonButton & setMinWidth(float width)
Request a minimum container width.
CommonButton & setSize(Size size)
Choose the size step.
const std::optional< Corners > & getCorners(void) const noexcept
Get the per-corner radius override.
Color
Which theme colors fill the container, the content and the outline.
Shape getShape(void) const noexcept
Get the corner shape at rest.
~CommonButton(void)=default
Default destructor.
CommonButton & setUppercase(bool uppercase)
Draw the label in upper case, or as written.
CommonButton & setCompact(bool compact)
Halve the horizontal padding, or restore it.
static constexpr float MinWidth
Minimum width of the container, in dp.
CommonButton(void)=default
Create the configuration of a small, round text button.
Color getColorStyle(void) const noexcept
Get the color style.
CommonButton & setShape(Shape shape)
Choose the corner shape at rest.
float getMinWidth(void) const noexcept
Get the requested minimum width.
Size
Size step. It sets the padding, the icon size, the gap between icon and label and the corner radius; ...
Size getSize(void) const noexcept
Get the size step.
bool isUppercase(void) const noexcept
Check whether the label is drawn in upper case.
bool isCompact(void) const noexcept
Check whether the horizontal padding is halved.
CommonButton & setColorStyle(Color style)
Choose which theme colors the button uses.
Shape
Corner shape at rest: fully rounded (Round) or the rounded rectangle of the size (Square).
A run of text: its content, its font metrics and the position of the editing cursor.
Definition text.hpp:66
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
State. Every class here is plain data attached to an entity.
Radius of each corner, for a button joined to its neighbours (a segment of a segmented button).
bool operator==(const Corners &other) const =default
Compare two corner sets.
float bottomLeft
Bottom-left radius, in dp.
float bottomRight
Bottom-right radius, in dp.