forked from crosspoint-reader/crosspoint-reader
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUIThemeTokens.h
More file actions
40 lines (37 loc) · 2.28 KB
/
Copy pathUIThemeTokens.h
File metadata and controls
40 lines (37 loc) · 2.28 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
#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));
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);
// The scroll track hugs the band edge; on boards whose panel sits recessed
// behind the bezel the edge columns are covered, so push the indicator
// inward past the covered side. Bezel truth is per-board data
// (BoardConfig::ViewableInsets); lists render in the portrait UI frame, so
// the panel-native portrait insets apply directly.
const auto& vi = BoardConfig::ACTIVE.viewableInsets;
tokens.listScrollInset = static_cast<int16_t>(metrics.listScrollSide == 1 ? vi.left : vi.right);
// 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);
tokens.bodyText.bold = metrics.listTitleBold;
return tokens;
}