libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
style.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <cstdint>
11#include <promeki/namespace.h>
12#include <promeki/color.h>
13
14PROMEKI_NAMESPACE_BEGIN
15
35class TuiStyle {
36 public:
40 enum Attr : uint8_t {
41 None = 0x00,
42 Bold = 0x01,
43 Dim = 0x02,
44 Italic = 0x04,
45 Underline = 0x08,
46 Blink = 0x10,
47 Inverse = 0x20,
48 Strikethrough = 0x40
49 };
50
52 TuiStyle() = default;
53
55 TuiStyle(const Color &fg, const Color &bg, uint8_t attrs = None)
56 : _fg(fg), _bg(bg), _attrs(attrs), _attrMask(0xFF) {}
57
59 Color foreground() const { return _fg; }
60
62 Color background() const { return _bg; }
63
65 uint8_t attrs() const { return _attrs; }
66
68 uint8_t attrMask() const { return _attrMask; }
69
71 void setForeground(const Color &color) { _fg = color; }
72
74 void setBackground(const Color &color) { _bg = color; }
75
77 void setAttrs(uint8_t attrs) {
78 _attrs = attrs;
79 _attrMask = 0xFF;
80 }
81
83 void setAttrs(uint8_t attrs, uint8_t mask) {
84 _attrs = attrs;
85 _attrMask = mask;
86 }
87
89 bool hasForeground() const { return _fg.isValid(); }
90
92 bool hasBackground() const { return _bg.isValid(); }
93
99 TuiStyle merged(const TuiStyle &below) const;
100
102 static TuiStyle fromForeground(const Color &fg, uint8_t attrs = None, uint8_t attrMask = 0) {
103 TuiStyle s;
104 s._fg = fg;
105 s._attrs = attrs;
106 s._attrMask = attrMask;
107 return s;
108 }
109
111 static TuiStyle fromBackground(const Color &bg) {
112 TuiStyle s;
113 s._bg = bg;
114 return s;
115 }
116
117 bool operator==(const TuiStyle &o) const {
118 return _fg == o._fg && _bg == o._bg && _attrs == o._attrs && _attrMask == o._attrMask;
119 }
120 bool operator!=(const TuiStyle &o) const { return !(*this == o); }
121
122 private:
123 Color _fg;
124 Color _bg;
125 uint8_t _attrs = None;
126 uint8_t _attrMask = 0x00;
127};
128
139 public:
140 TuiStyleState() = default;
141
142 bool focused() const { return _focused; }
143 bool enabled() const { return _enabled; }
144 bool pressed() const { return _pressed; }
145 bool selected() const { return _selected; }
146
147 void setFocused(bool v) { _focused = v; }
148 void setEnabled(bool v) { _enabled = v; }
149 void setPressed(bool v) { _pressed = v; }
150 void setSelected(bool v) { _selected = v; }
151
152 private:
153 bool _focused = false;
154 bool _enabled = true;
155 bool _pressed = false;
156 bool _selected = false;
157};
158
159PROMEKI_NAMESPACE_END
Widget state bundle fed into palette lookups.
Definition style.h:138
Visual properties of a TUI cell (everything except the character).
Definition style.h:35
bool hasBackground() const
Returns true if the background color is defined (not ignored).
Definition style.h:92
void setBackground(const Color &color)
Sets the background color.
Definition style.h:74
uint8_t attrs() const
Returns the attribute flags.
Definition style.h:65
uint8_t attrMask() const
Returns the attribute mask (1 = defined, 0 = ignored).
Definition style.h:68
void setAttrs(uint8_t attrs)
Sets all attribute flags (marks all bits as defined).
Definition style.h:77
static TuiStyle fromBackground(const Color &bg)
Creates a background-only style (foreground ignored).
Definition style.h:111
bool hasForeground() const
Returns true if the foreground color is defined (not ignored).
Definition style.h:89
static TuiStyle fromForeground(const Color &fg, uint8_t attrs=None, uint8_t attrMask=0)
Creates a foreground-only style (background ignored).
Definition style.h:102
Color foreground() const
Returns the foreground color.
Definition style.h:59
Attr
Text attribute flags.
Definition style.h:40
void setAttrs(uint8_t attrs, uint8_t mask)
Sets attribute flags with an explicit mask.
Definition style.h:83
TuiStyle merged(const TuiStyle &below) const
Merges this style on top of another.
void setForeground(const Color &color)
Sets the foreground color.
Definition style.h:71
TuiStyle(const Color &fg, const Color &bg, uint8_t attrs=None)
Constructs with foreground, background, and attributes (all defined).
Definition style.h:55
TuiStyle()=default
Default constructor. All properties are ignored.
Color background() const
Returns the background color.
Definition style.h:62