Player12
An open source football management simulator
Loading...
Searching...
No Matches
theme.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// Football Management Project
3// Copyright (c) 2025 - 2026 Flavio Milinanni. All Rights Reserved.
4//
5// This file is part of the Football Management Project.
6// See the LICENSE file in the project root.
7// -----------------------------------------------------------------------------
8
9#pragma once
10
11#include <imgui.h>
12
13#include <cstdint>
14#include <optional>
15
16#include "global/types.h"
17
27namespace Theme
28{
29
31namespace Space
32{
33constexpr float XS = 4.0f;
34constexpr float S = 8.0f;
35constexpr float M = 12.0f;
36constexpr float L = 16.0f;
37constexpr float XL = 24.0f;
38} // namespace Space
39
41enum class Text : uint8_t
42{
43 CAPTION,
44 SMALL,
45 BODY,
46 TITLE,
47 HEADING,
48 DISPLAY
49};
50
52enum class Preset : uint8_t
53{
57 LIGHT,
59 TRUE_DARK,
60 COUNT
61};
62
67enum class ColorVision : uint8_t
68{
69 STANDARD,
70 RED_GREEN,
72 COUNT
73};
74
77{
79 bool club_accent = true;
80 ImVec4 custom_accent = ImVec4(0.130f, 0.650f, 0.390f, 1.0f);
81 float ui_scale = 0.0f;
82 bool compact = false;
83 bool reduced_motion = false;
85 float text_scale = 1.0f;
86};
87
89struct Palette
90{
91 ImVec4 background;
92 ImVec4 sidebar;
93 ImVec4 surface;
94 ImVec4 raised;
95 ImVec4 border;
96 ImVec4 text;
97 ImVec4 muted;
98 ImVec4 faint;
99 ImVec4 positive;
100 ImVec4 warning;
101 ImVec4 negative;
102 ImVec4 info;
103 ImVec4 accent;
104 ImVec4 on_accent;
105};
106
111Palette presetPalette(Preset preset, ColorVision vision, const ImVec4& accent);
112
114const char* colorVisionKey(ColorVision vision);
115
117float contrastRatio(const ImVec4& first, const ImVec4& second);
118
120const Palette& palette();
121
123const Appearance& appearance();
124
130void apply(const Appearance& options, float displayScale);
131
133void setClub(std::optional<TeamID> teamId);
134
136float scale();
137
139bool reducedMotion();
140
142struct Swatch
143{
145 ImVec4 surface;
146 ImVec4 text;
147 ImVec4 muted;
148};
149
152
154const char* presetKey(Preset preset);
155
157ImVec4 clubAccent(TeamID teamId);
158
160ImVec4 ratingColor(double value);
161
163float textSize(Text level);
164
166ImU32 toU32(const ImVec4& color, float alpha = 1.0f);
167
169uint32_t packRgb(const ImVec4& color);
170
172ImVec4 unpackRgb(uint32_t rgb);
173
176{
177 public:
178 explicit ScopedText(Text level);
179 ~ScopedText();
180 ScopedText(const ScopedText&) = delete;
181 ScopedText& operator=(const ScopedText&) = delete;
182};
183
184} // namespace Theme
Pushes a typography level for the lifetime of the object.
Definition theme.h:176
~ScopedText()
Definition theme.cpp:551
ScopedText & operator=(const ScopedText &)=delete
ScopedText(const ScopedText &)=delete
constexpr float XS
Definition theme.h:33
constexpr float M
Definition theme.h:35
constexpr float S
Definition theme.h:34
constexpr float XL
Definition theme.h:37
constexpr float L
Definition theme.h:36
Design tokens shared by every management screen.
Definition theme.cpp:322
ImU32 toU32(const ImVec4 &color, float alpha)
Converts a colour with an optional alpha multiplier.
Definition theme.cpp:524
float scale()
Effective UI scale (fonts and sizes).
Definition theme.cpp:435
ImVec4 ratingColor(double value)
Continuous colour scale for 0-100 ratings (red to green).
Definition theme.cpp:474
ImVec4 unpackRgb(uint32_t rgb)
Unpacks 0xRRGGBB into an opaque colour.
Definition theme.cpp:539
const char * presetKey(Preset preset)
Localisation key of a preset name.
Definition theme.cpp:446
const Palette & palette()
Returns the active palette (accent included).
Definition theme.cpp:374
float textSize(Text level)
Unscaled pixel size for a typography level.
Definition theme.cpp:503
bool reducedMotion()
True when animations should be avoided.
Definition theme.cpp:437
void setClub(std::optional< TeamID > teamId)
Tells the theme which club is managed (for club accents).
Definition theme.cpp:428
Preset
Built-in palettes.
Definition theme.h:53
const char * colorVisionKey(ColorVision vision)
Localisation key of a colour-vision mode's name.
Definition theme.cpp:351
const Appearance & appearance()
Returns the active appearance options.
Definition theme.cpp:376
Text
Typography scale.
Definition theme.h:42
Palette presetPalette(Preset preset, ColorVision vision, const ImVec4 &accent)
Palette of a preset without applying it (no ImGui state touched), e.g. for previews and contrast chec...
Definition theme.cpp:324
void apply(const Appearance &options, float displayScale)
Applies an appearance to the current ImGui style.
Definition theme.cpp:378
Swatch presetSwatch(Preset preset)
Preview colours of a preset without applying it.
Definition theme.cpp:439
ColorVision
Hues of the status colours. Good and bad are never told apart by red against green alone in the safe ...
Definition theme.h:68
uint32_t packRgb(const ImVec4 &color)
Packs an opaque colour as 0xRRGGBB (for settings files).
Definition theme.cpp:529
float contrastRatio(const ImVec4 &first, const ImVec4 &second)
WCAG contrast ratio of two opaque colours (1 to 21).
Definition theme.cpp:367
ImVec4 clubAccent(TeamID teamId)
Deterministic accent colour for a club.
Definition theme.cpp:469
User-selected appearance options.
Definition theme.h:77
ImVec4 custom_accent
Definition theme.h:80
ColorVision color_vision
Definition theme.h:84
bool compact
Definition theme.h:82
float ui_scale
Definition theme.h:81
bool club_accent
Definition theme.h:79
float text_scale
Definition theme.h:85
Preset preset
Definition theme.h:78
bool reduced_motion
Definition theme.h:83
Semantic colours used by widgets.
Definition theme.h:90
ImVec4 raised
Definition theme.h:94
ImVec4 sidebar
Definition theme.h:92
ImVec4 surface
Definition theme.h:93
ImVec4 muted
Definition theme.h:97
ImVec4 text
Definition theme.h:96
ImVec4 info
Definition theme.h:102
ImVec4 background
Definition theme.h:91
ImVec4 negative
Definition theme.h:101
ImVec4 warning
Definition theme.h:100
ImVec4 on_accent
Definition theme.h:104
ImVec4 positive
Definition theme.h:99
ImVec4 faint
Definition theme.h:98
ImVec4 accent
Definition theme.h:103
ImVec4 border
Definition theme.h:95
Representative colours of a preset, for previews.
Definition theme.h:143
ImVec4 muted
Definition theme.h:147
ImVec4 surface
Definition theme.h:145
ImVec4 background
Definition theme.h:144
ImVec4 text
Definition theme.h:146
uint16_t TeamID
Type alias for Team identifiers.
Definition types.h:18