TinyMaterialDesign
Loading...
Searching...
No Matches
Icons.h
Go to the documentation of this file.
1#pragma once
2#include "TinyGPU/Surface/ISurface.h"
3#include "TinyMaterialDesign/Core/Bounds.h"
4
5namespace tinymd {
6
7/// Draws a line `thickness` times, offset by whole pixels, as a cheap
8/// approximation of a stroked line - good enough at the small sizes these
9/// vector icons are drawn at (checkbox/radio/icon-button glyphs).
10template <typename RGB_T>
13 if (thickness == 0) thickness = 1;
14 const int32_t half = thickness / 2;
15 for (int32_t o = -half; o < static_cast<int32_t>(thickness) - half; ++o) {
16 target.drawLine(toPx(x0 + o), toPx(y0), toPx(x1 + o), toPx(y1), color);
17 target.drawLine(toPx(x0), toPx(y0 + o), toPx(x1), toPx(y1 + o), color);
18 }
19}
20
21/// Checkmark glyph (Checkbox, checked state), inset within `r`.
22template <typename RGB_T>
24 uint8_t thickness = 2) {
25 const int32_t x0 = r.x + static_cast<int32_t>(r.w * 0.20f);
26 const int32_t y0 = r.y + static_cast<int32_t>(r.h * 0.55f);
27 const int32_t x1 = r.x + static_cast<int32_t>(r.w * 0.42f);
28 const int32_t y1 = r.y + static_cast<int32_t>(r.h * 0.78f);
29 const int32_t x2 = r.x + static_cast<int32_t>(r.w * 0.82f);
30 const int32_t y2 = r.y + static_cast<int32_t>(r.h * 0.24f);
33}
34
35/// Filled dot (RadioButton, selected state), centered within `r`.
36template <typename RGB_T>
38 const int32_t radius = r.w < r.h ? r.w / 4 : r.h / 4;
40}
41
42/// "X" close glyph, inset within `r`.
43template <typename RGB_T>
45 uint8_t thickness = 2) {
46 const Bounds in = r.inset(static_cast<int32_t>(r.w * 0.25f));
49}
50
51/// "+" plus glyph, inset within `r`.
52template <typename RGB_T>
54 uint8_t thickness = 2) {
55 const Bounds in = r.inset(static_cast<int32_t>(r.w * 0.22f));
58}
59
60/// "-" minus glyph, inset within `r`.
61template <typename RGB_T>
63 uint8_t thickness = 2) {
64 const Bounds in = r.inset(static_cast<int32_t>(r.w * 0.22f));
66}
67
68/// Downward chevron ("v"), inset within `r` - used for expandable affordances.
69template <typename RGB_T>
71 uint8_t thickness = 2) {
72 const int32_t x0 = r.x + static_cast<int32_t>(r.w * 0.22f);
73 const int32_t y0 = r.y + static_cast<int32_t>(r.h * 0.35f);
74 const int32_t xm = r.centerX();
75 const int32_t ym = r.y + static_cast<int32_t>(r.h * 0.65f);
76 const int32_t x1 = r.x + static_cast<int32_t>(r.w * 0.78f);
79}
80
81/// Rightward chevron (">"), inset within `r` - navigation affordance.
82template <typename RGB_T>
84 uint8_t thickness = 2) {
85 const int32_t x0 = r.x + static_cast<int32_t>(r.w * 0.35f);
86 const int32_t y0 = r.y + static_cast<int32_t>(r.h * 0.22f);
87 const int32_t xm = r.centerX();
88 const int32_t ym = r.centerY();
89 const int32_t y1 = r.y + static_cast<int32_t>(r.h * 0.78f);
92}
93
94/// Hamburger menu glyph (three horizontal bars), inset within `r` - the
95/// conventional affordance for opening a Drawer.
96template <typename RGB_T>
98 uint8_t thickness = 2) {
99 const Bounds in = r.inset(static_cast<int32_t>(r.w * 0.15f));
103}
104
105/// Magnifying-glass search glyph, inset within `r` - used by SearchBar.
106template <typename RGB_T>
108 uint8_t thickness = 2) {
109 const int32_t lensDiameter = static_cast<int32_t>(r.w * 0.55f);
110 const int32_t lensCx = r.x + static_cast<int32_t>(r.w * 0.40f);
111 const int32_t lensCy = r.y + static_cast<int32_t>(r.h * 0.40f);
113 const int32_t handleX0 = lensCx + static_cast<int32_t>(lensDiameter * 0.42f);
114 const int32_t handleY0 = lensCy + static_cast<int32_t>(lensDiameter * 0.42f);
116}
117
118/// WiFi glyph: a dot with three arcs above it.
119template <typename RGB_T>
121 const int32_t cx = r.centerX();
122 const int32_t cy = r.bottom() - r.h / 5;
124 for (int i = 1; i <= 3; ++i) {
125 target.drawArc(toPx(cx), toPx(cy), toPx(r.w * i / 8 + 1), 225.0f, 315.0f, color, thickness);
126 }
127}
128
129/// Signal strength: 4 bars of growing height, the first `bars` (0-4) in
130/// `on`, the others in `off`.
131template <typename RGB_T>
133 const int32_t w = r.w / 5;
134 for (int i = 0; i < 4; ++i) {
135 const int32_t h = r.h * (i + 1) / 4;
136 target.fillRect(toPx(r.x + i * (w + w / 3)), toPx(r.bottom() - h), toPx(w), toPx(h), i < bars ? on : off);
137 }
138}
139
140/// Padlock (e.g. a secured network).
141template <typename RGB_T>
143 const int32_t bodyH = r.h / 2;
145 target.drawArc(toPx(r.centerX()), toPx(r.bottom() - bodyH), toPx(r.w / 2 - 1), 180.0f, 360.0f, color,
146 thickness + 1);
147}
148
149} // namespace tinymd
Definition: AnchorLayout.h:4
void drawPlus(tinygpu::ISurface< RGB_T > &target, const Bounds &r, RGB_T color, uint8_t thickness=2)
"+" plus glyph, inset within r.
Definition: Icons.h:53
void drawLock(tinygpu::ISurface< RGB_T > &target, const Bounds &r, RGB_T color, uint8_t thickness=1)
Padlock (e.g. a secured network).
Definition: Icons.h:142
void drawClose(tinygpu::ISurface< RGB_T > &target, const Bounds &r, RGB_T color, uint8_t thickness=2)
"X" close glyph, inset within r.
Definition: Icons.h:44
void drawChevronDown(tinygpu::ISurface< RGB_T > &target, const Bounds &r, RGB_T color, uint8_t thickness=2)
Downward chevron ("v"), inset within r - used for expandable affordances.
Definition: Icons.h:70
void drawCheckmark(tinygpu::ISurface< RGB_T > &target, const Bounds &r, RGB_T color, uint8_t thickness=2)
Checkmark glyph (Checkbox, checked state), inset within r.
Definition: Icons.h:23
void drawWifi(tinygpu::ISurface< RGB_T > &target, const Bounds &r, RGB_T color, uint8_t thickness=2)
WiFi glyph: a dot with three arcs above it.
Definition: Icons.h:120
void drawDot(tinygpu::ISurface< RGB_T > &target, const Bounds &r, RGB_T color)
Filled dot (RadioButton, selected state), centered within r.
Definition: Icons.h:37
void drawChevronRight(tinygpu::ISurface< RGB_T > &target, const Bounds &r, RGB_T color, uint8_t thickness=2)
Rightward chevron (">"), inset within r - navigation affordance.
Definition: Icons.h:83
void drawSignalBars(tinygpu::ISurface< RGB_T > &target, const Bounds &r, int bars, RGB_T on, RGB_T off)
Definition: Icons.h:132
void drawMenu(tinygpu::ISurface< RGB_T > &target, const Bounds &r, RGB_T color, uint8_t thickness=2)
Definition: Icons.h:97
void drawSearch(tinygpu::ISurface< RGB_T > &target, const Bounds &r, RGB_T color, uint8_t thickness=2)
Magnifying-glass search glyph, inset within r - used by SearchBar.
Definition: Icons.h:107
void drawMinus(tinygpu::ISurface< RGB_T > &target, const Bounds &r, RGB_T color, uint8_t thickness=2)
"-" minus glyph, inset within r.
Definition: Icons.h:62
void drawLineThick(tinygpu::ISurface< RGB_T > &target, int32_t x0, int32_t y0, int32_t x1, int32_t y1, RGB_T color, uint8_t thickness=2)
Definition: Icons.h:11