Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
view_style.hpp
Go to the documentation of this file.
1/*
2 Copyright 2026 JigSawFr
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#pragma once
18
19#include <nanovg.h>
20
21#include <cstdint>
22#include <string>
23
24namespace aurore
25{
26
27// The states a view can be styled for (focus:backgroundColor="…" in XML,
28// View::setStateStyle in code). When several are on, the later one in this
29// list wins for a property both style: hover, focus, pressed, disabled.
30enum class StyleState : uint8_t
31{
32 HOVER = 1 << 0, // the mouse pointer is over the view (desktop)
33 FOCUS = 1 << 1, // the view has the focus
34 PRESSED = 1 << 2, // A or a touch is held on the view (its click animation)
35 DISABLED = 1 << 3, // set by the app (View::setStyleState), or a disabled Button
36};
37
38// A style property's value: a number (borderThickness, alpha…) or a colour
39// (backgroundColor, textColor…).
41{
42 enum class Type : uint8_t
43 {
44 NONE,
45 NUMBER,
46 COLOR,
47 };
48
50 float number = 0.0f;
51 NVGcolor color = nvgRGBA(0, 0, 0, 0);
52
53 static StyleValue of(float number)
54 {
55 StyleValue value;
56 value.type = Type::NUMBER;
57 value.number = number;
58 return value;
59 }
60
61 static StyleValue of(NVGcolor color)
62 {
63 StyleValue value;
64 value.type = Type::COLOR;
65 value.color = color;
66 return value;
67 }
68
69 bool operator==(const StyleValue& other) const;
70 bool operator!=(const StyleValue& other) const { return !(*this == other); }
71
72 // From `from` (t = 0) to `to` (t = 1), each colour channel on its own.
73 static StyleValue mix(const StyleValue& from, const StyleValue& to, float t);
74};
75
76// What a view is, for an accessibility description (the focus announcer).
77enum class AccessibilityRole : uint8_t
78{
79 NONE, // nothing said for the role
80 BUTTON,
81 LABEL,
82 HEADER,
83 IMAGE,
84 CELL,
85 TOGGLE,
86 SLIDER,
88 TAB,
89 LIST,
90 DIALOG, // said with its text when the focus enters it
91};
92
93// "button", "toggle"… (the XML names); "" for NONE.
95
96// The words the descriptions are made of, in the app's language
97// (resources/i18n/<language>/a11y.json, English when the app has none): a
98// role as said ("switch"; "" for NONE, a label, a cell), a state ("on",
99// "off", "selected", "disabled"), a share of 0..1 as "40%".
101std::string accessibilityStateWord(const std::string& state);
102std::string accessibilityPercent(float fraction);
103
104} // namespace aurore
Definition actions.hpp:25
std::string accessibilityRoleName(AccessibilityRole role)
std::string accessibilityRoleWord(AccessibilityRole role)
AccessibilityRole
Definition view_style.hpp:78
StyleState
Definition view_style.hpp:31
@ DIALOG
backdrop.dialog: dialogs, dropdowns, Cadran's sheets
@ HEADER
backdrop.header: a screen's header, its whole width
std::string accessibilityPercent(float fraction)
std::string accessibilityStateWord(const std::string &state)
Definition view_style.hpp:41
float number
Definition view_style.hpp:50
static StyleValue of(NVGcolor color)
Definition view_style.hpp:61
bool operator!=(const StyleValue &other) const
Definition view_style.hpp:70
NVGcolor color
Definition view_style.hpp:51
bool operator==(const StyleValue &other) const
Type
Definition view_style.hpp:43
Type type
Definition view_style.hpp:49
static StyleValue of(float number)
Definition view_style.hpp:53
static StyleValue mix(const StyleValue &from, const StyleValue &to, float t)