31#include "guillaume/theme.hpp"
50 constexpr std::array<SizeMetrics, 5> sizeTable { {
70 std::optional<Role> container;
77 ModePalette unselected;
82 constexpr std::array<Palette, 6> paletteTable { {
84 { { Role::SurfaceContainerLow, Role::Primary },
85 { Role::SurfaceContainerLow, Role::Primary },
86 { Role::Primary, Role::OnPrimary } },
88 { { Role::Primary, Role::OnPrimary },
89 { Role::SurfaceContainer, Role::OnSurfaceVariant },
90 { Role::Primary, Role::OnPrimary } },
92 { { Role::SecondaryContainer, Role::OnSecondaryContainer },
93 { Role::SecondaryContainer, Role::OnSecondaryContainer },
94 { Role::Secondary, Role::OnSecondary } },
96 { { std::nullopt, Role::Primary },
97 { std::nullopt, Role::Primary },
98 { Role::SecondaryContainer, Role::OnSecondaryContainer } },
100 { { std::nullopt, Role::Primary },
101 { std::nullopt, Role::Primary },
102 { std::nullopt, Role::Primary } },
104 { { std::nullopt, Role::OnSurfaceVariant },
105 { std::nullopt, Role::OnSurfaceVariant },
106 { Role::SecondaryContainer, Role::OnSecondaryContainer } },
111 const auto index =
static_cast<std::size_t
>(size);
112 if (index >= sizeTable.size()) {
113 throw std::runtime_error(
"Invalid button size");
115 return sizeTable[index];
119 bool isToggle,
bool isSelected)
121 const auto index =
static_cast<std::size_t
>(style);
122 if (index >= paletteTable.size()) {
123 throw std::runtime_error(
"Invalid button color style");
125 const Palette &entry = paletteTable[index];
129 return isSelected ? entry.selected : entry.unselected;
132 utility::graphic::Color32Bit transparent(
void)
134 return utility::graphic::Color32Bit(0, 0, 0, 0);
137 utility::graphic::Color32Bit
139 bool isToggle,
bool isSelected)
141 const auto role = palette(style, isToggle, isSelected).container;
148 return metrics(size).heightPadding;
154 const float padding = metrics(size).widthPadding;
155 return compact ? padding / 2.0f : padding;
160 return metrics(size).iconFontSize;
165 return metrics(size).iconLabelGap;
170 bool isButtonPressed)
172 const SizeMetrics &entry = metrics(size);
174 if (isButtonPressed) {
177 if (shape == components::CommonButton::Shape::Round) {
185 bool isToggle,
bool isSelected,
bool isMorph)
187 if (!isMorph || !isToggle || !isSelected) {
191 return (baseShape == components::CommonButton::Shape::Round)
192 ? components::CommonButton::Shape::Square
193 : components::CommonButton::Shape::Round;
196 utility::graphic::Color32Bit
198 bool isSelected,
bool isHovered,
bool isButtonPressed)
200 const auto base = getBaseContainerColor(
style, isToggle, isSelected);
202 if (!isButtonPressed && !isHovered) {
205 return ::guillaume::systems::style::stateLayer(
211 utility::graphic::Color32Bit
218 utility::graphic::Color32Bit
224 const bool outlined =
225 style == components::CommonButton::Color::Segmented
226 || (
style == components::CommonButton::Color::Outlined
227 && !(isToggle && isSelected));
Color helpers shared by the widget systems.
@ Hovered
0.08 overlay of the content color.
@ Pressed
0.12 overlay of the content color.
ShapeRole
The corner radii a widget can ask for, by name.
@ ExtraLarge
28 dp (dialogs, search bars, sheets).
@ Large
16 dp (FABs, drawers).
@ Full
Fully rounded (buttons, icon buttons, badges).
std::uint8_t getStateLayerAlpha(theme::StateLayer layer)
Get the opacity the active theme gives to a state layer, as an alpha channel value.
SchemeColorRole
The named colors of a scheme: what a color is used for, not what it looks like.
float getShapeRadius(theme::ShapeRole role)
Get the corner radius the active theme gives to a shape role.
utility::graphic::Color32Bit getActiveColor(SchemeColorRole role)
Get the color the active scheme gives to a role.
Color helpers shared by the widget systems: scheme lookup, state layers and the disabled colors.