Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
button.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019-2021 natinusala
3 Copyright 2019 p-sam
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18#pragma once
19
20#include <aurore/core/bind.hpp>
21#include <aurore/core/box.hpp>
23
24namespace aurore
25{
26
27// Style and colors of different buttons styles
28// Border color entries can be empty if thickness is 0
29// Highlight padding can be empty
30// Background color entries can be empty
31// Border thickness can be empty
32// The rest is mandatory
33typedef struct ButtonStyle
34{
35 // Regular values
38
39 // Style entries
40 std::string highlightPadding;
41 std::string borderThickness;
42
43 // Theme entries
45 std::string enabledLabelColor;
46 std::string enabledBorderColor;
47
49 std::string disabledLabelColor;
51} ButtonStyle;
52
53// primary action button (different background color than default, to catch the eye)
56 .hideHighlightBackground = true,
57
58 .highlightPadding = "aurore/button/primary_highlight_padding",
59 .borderThickness = "",
60
61 .enabledBackgroundColor = "aurore/button/primary_enabled_background",
62 .enabledLabelColor = "aurore/button/primary_enabled_text",
63 .enabledBorderColor = "",
64
65 .disabledBackgroundColor = "aurore/button/primary_disabled_background",
66 .disabledLabelColor = "aurore/button/primary_disabled_text",
67 .disabledBorderColor = "",
68};
69
70// between primary and default - text color is different, background color is the same
73 .hideHighlightBackground = true,
74
75 .highlightPadding = "",
76 .borderThickness = "",
77
78 .enabledBackgroundColor = "aurore/button/default_enabled_background",
79 .enabledLabelColor = "aurore/button/highlight_enabled_text",
80 .enabledBorderColor = "",
81
82 .disabledBackgroundColor = "aurore/button/default_disabled_background",
83 .disabledLabelColor = "aurore/button/highlight_disabled_text",
84 .disabledBorderColor = "",
85};
86
87// default, plain button
90 .hideHighlightBackground = true,
91
92 .highlightPadding = "",
93 .borderThickness = "",
94
95 .enabledBackgroundColor = "aurore/button/default_enabled_background",
96 .enabledLabelColor = "aurore/button/default_enabled_text",
97 .enabledBorderColor = "",
98
99 .disabledBackgroundColor = "aurore/button/default_disabled_background",
100 .disabledLabelColor = "aurore/button/default_disabled_text",
101 .disabledBorderColor = "",
102};
103
104// text and a border
107 .hideHighlightBackground = false,
108
109 .highlightPadding = "",
110 .borderThickness = "aurore/button/border_thickness",
111
112 .enabledBackgroundColor = "",
113 .enabledLabelColor = "aurore/button/default_enabled_text",
114 .enabledBorderColor = "aurore/button/enabled_border_color",
115
116 .disabledBackgroundColor = "",
117 .disabledLabelColor = "aurore/button/default_disabled_text",
118 .disabledBorderColor = "aurore/button/disabled_border_color",
119};
120
121// only text
124 .hideHighlightBackground = false,
125
126 .highlightPadding = "",
127 .borderThickness = "",
128
129 .enabledBackgroundColor = "",
130 .enabledLabelColor = "aurore/button/default_enabled_text",
131 .enabledBorderColor = "",
132
133 .disabledBackgroundColor = "",
134 .disabledLabelColor = "aurore/button/default_disabled_text",
135 .disabledBorderColor = "",
136};
137
138enum class ButtonState
139{
140 ENABLED = 0, // the user can select and click on the button
141 DISABLED, // the user can select but not click on the button (greyed out)
142};
143
144// A button
145class Button : public Box
146{
147 public:
149
150 void onFocusGained() override;
151 void onFocusLost() override;
152
153 static View* create();
154
159 void setStyle(const ButtonStyle* style);
160
165
170
174 void setText(std::string text);
175
179 void setFontSize(float value);
180
184 void setTextColor(NVGcolor color);
185
189 std::string getText();
190
191 // textColor: its label's.
192 bool getStyleProperty(const std::string& name, StyleValue* value) override;
193 bool setStyleProperty(const std::string& name, const StyleValue& value) override;
194 bool setBoundText(const std::string& text) override;
195
196 protected:
198 std::string getDefaultAccessibilityLabel() override { return this->getText(); }
199
200 private:
201 const ButtonStyle* style = &BUTTONSTYLE_DEFAULT;
203
204 NVGcolor textColor;
205 bool textColorOverritten = false;
206
207 void applyStyle();
208
209 AURORE_BIND(Label, label, "aurore/button/label");
210};
211
212} // namespace aurore
#define AURORE_BIND(type, name, id)
Definition bind.hpp:39
Generic FlexBox layout.
Definition box.hpp:74
Definition button.hpp:146
void setState(ButtonState state)
bool setStyleProperty(const std::string &name, const StyleValue &value) override
bool setBoundText(const std::string &text) override
bool getStyleProperty(const std::string &name, StyleValue *value) override
void setText(std::string text)
std::string getText()
void onFocusLost() override
void setTextColor(NVGcolor color)
AccessibilityRole getDefaultAccessibilityRole() override
Definition button.hpp:197
void setStyle(const ButtonStyle *style)
void onFocusGained() override
std::string getDefaultAccessibilityLabel() override
A focusable box says the texts shown in it (getAccessibilityText).
Definition button.hpp:198
ButtonState getState()
void setFontSize(float value)
static View * create()
Definition label.hpp:65
Definition view.hpp:232
Definition actions.hpp:25
const ButtonStyle BUTTONSTYLE_DEFAULT
Definition button.hpp:88
AccessibilityRole
Definition view_style.hpp:78
const ButtonStyle BUTTONSTYLE_PRIMARY
Definition button.hpp:54
const ButtonStyle BUTTONSTYLE_HIGHLIGHT
Definition button.hpp:71
ShadowType
A View shape's shadow type.
Definition view.hpp:163
@ NONE
do not draw any shadow around the shape
@ GENERIC
generic all-purpose shadow
ButtonState
Definition button.hpp:139
const ButtonStyle BUTTONSTYLE_BORDERED
Definition button.hpp:105
const ButtonStyle BUTTONSTYLE_BORDERLESS
Definition button.hpp:122
Definition text.hpp:13
Definition button.hpp:34
std::string enabledLabelColor
Definition button.hpp:45
std::string disabledBorderColor
Definition button.hpp:50
std::string disabledBackgroundColor
Definition button.hpp:48
std::string highlightPadding
Definition button.hpp:40
std::string enabledBackgroundColor
Definition button.hpp:44
ShadowType shadowType
Definition button.hpp:36
std::string disabledLabelColor
Definition button.hpp:49
std::string enabledBorderColor
Definition button.hpp:46
std::string borderThickness
Definition button.hpp:41
bool hideHighlightBackground
Definition button.hpp:37
Definition view_style.hpp:41