Repository navigation
Expand file tree
/
Copy pathUIThemeTokens.h
More file actions
47 lines (44 loc) · 2.77 KB
/
Copy pathUIThemeTokens.h
File metadata and controls
47 lines (44 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <BoardConfig.h>
#include <FreeInkUIGfxRenderer.h>
#include "UITheme.h"
// Merges the active UITheme's shape (row gaps, radii, insets, selection
// style) with the uiScale-derived sizes into FreeInkUI theme tokens: the
// theme says what lists look like, the scale says how big they are.
// Everything read here is plain data from ThemeMetrics — the same values an
// SD-card theme file will eventually supply.
inline freeink::ui::ThemeTokens uiThemeTokens(const freeink::ui::GfxRendererTarget& target) {
namespace fui = freeink::ui;
const ThemeMetrics& metrics = UITheme::getInstance().getMetrics();
fui::ThemeTokens tokens = fui::themeTokensForLineHeight(target.lineHeight(fui::GfxRendererTarget::FONT_BODY));
// Button-device lists retain the theme's preferred density. The SDK still
// grows individual rows for wrapping, subtitles and icons.
if (!BoardConfig::hasTouch()) tokens.listMinRowHeight = static_cast<int16_t>(metrics.listRowHeight);
tokens.listRowGap = static_cast<int16_t>(metrics.listRowGap);
tokens.listRowRadius = static_cast<uint8_t>(metrics.listRowRadius);
tokens.listInset = static_cast<int16_t>(metrics.listInset);
tokens.listSidePadding = static_cast<int16_t>(metrics.listSidePadding);
tokens.listSelectionStyle = static_cast<fui::SelectionStyle>(metrics.listSelectionStyle);
tokens.listScrollWidth = static_cast<int16_t>(metrics.listScrollWidth);
tokens.listScrollSide = static_cast<uint8_t>(metrics.listScrollSide);
// No extra scroll-track inset: the bezel is already compensated once at the
// frame level (GfxRendererTarget::deviceContext() feeds the board's
// viewable insets into the fui safe area, and every list band derives from
// safeRect()). Adding the same inset here doubled the compensation and
// floated the track a full bezel-width inside the visible edge.
tokens.listScrollInset = 0;
// Screen::header()/status() band height. Without this the SDK's
// line-height-derived default applies and fui-drawn headers (OPDS) come out
// a different height than every GUI.drawHeader band.
tokens.headerHeight = static_cast<int16_t>(metrics.headerHeight);
tokens.headerSidePadding = static_cast<int16_t>(metrics.headerSidePadding);
tokens.headerUnderline = static_cast<uint8_t>(metrics.headerUnderlineSize);
tokens.headerTitleAlign = static_cast<fui::TextAlign>(metrics.headerTitleAlign);
// Control-panel shape (sheet corners, tiles, step buttons, capsule slider),
// so the control center follows the theme like every list and header does.
tokens.controlRadius = static_cast<uint8_t>(metrics.controlRadius);
tokens.sheetRadius = static_cast<uint8_t>(metrics.sheetRadius);
tokens.capsuleRadius = static_cast<uint8_t>(metrics.capsuleRadius);
tokens.bodyText.bold = metrics.listTitleBold;
return tokens;
}