libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
style.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <cstdint>
12#include <promeki/core/color.h>
13
15
29class TuiStyle {
30 public:
34 enum Attr : uint8_t {
35 None = 0x00,
36 Bold = 0x01,
37 Dim = 0x02,
38 Italic = 0x04,
39 Underline = 0x08,
40 Blink = 0x10,
41 Inverse = 0x20,
42 Strikethrough = 0x40
43 };
44
46 TuiStyle() = default;
47
49 TuiStyle(const Color &fg, const Color &bg, uint8_t attrs = None)
50 : _fg(fg), _bg(bg), _attrs(attrs), _attrMask(0xFF) {}
51
53 Color foreground() const { return _fg; }
54
56 Color background() const { return _bg; }
57
59 uint8_t attrs() const { return _attrs; }
60
62 uint8_t attrMask() const { return _attrMask; }
63
65 void setForeground(const Color &color) { _fg = color; }
66
68 void setBackground(const Color &color) { _bg = color; }
69
71 void setAttrs(uint8_t attrs) { _attrs = attrs; _attrMask = 0xFF; }
72
74 void setAttrs(uint8_t attrs, uint8_t mask) { _attrs = attrs; _attrMask = mask; }
75
77 bool hasForeground() const { return _fg.isValid(); }
78
80 bool hasBackground() const { return _bg.isValid(); }
81
88
91 TuiStyle s;
92 s._fg = fg;
93 s._attrs = attrs;
94 s._attrMask = attrMask;
95 return s;
96 }
97
100 TuiStyle s;
101 s._bg = bg;
102 return s;
103 }
104
105 bool operator==(const TuiStyle &o) const {
106 return _fg == o._fg && _bg == o._bg &&
107 _attrs == o._attrs && _attrMask == o._attrMask;
108 }
109 bool operator!=(const TuiStyle &o) const { return !(*this == o); }
110
111 private:
112 Color _fg;
113 Color _bg;
114 uint8_t _attrs = None;
115 uint8_t _attrMask = 0x00;
116};
117
125 public:
126 TuiStyleState() = default;
127
128 bool focused() const { return _focused; }
129 bool enabled() const { return _enabled; }
130 bool pressed() const { return _pressed; }
131 bool selected() const { return _selected; }
132
133 void setFocused(bool v) { _focused = v; }
134 void setEnabled(bool v) { _enabled = v; }
135 void setPressed(bool v) { _pressed = v; }
136 void setSelected(bool v) { _selected = v; }
137
138 private:
139 bool _focused = false;
140 bool _enabled = true;
141 bool _pressed = false;
142 bool _selected = false;
143};
144
General-purpose RGBA color.
Definition color.h:24
bool isValid() const
Returns true if this color was explicitly constructed.
Definition color.h:34
Dynamic array container wrapping std::vector.
Definition list.h:40
Widget state bundle fed into palette lookups.
Definition style.h:124
Visual properties of a TUI cell (everything except the character).
Definition style.h:29
void setForeground(const Color &color)
Sets the foreground color.
Definition style.h:65
Color foreground() const
Returns the foreground color.
Definition style.h:53
bool hasForeground() const
Returns true if the foreground color is defined (not ignored).
Definition style.h:77
void setBackground(const Color &color)
Sets the background color.
Definition style.h:68
static TuiStyle fromForeground(const Color &fg, uint8_t attrs=None, uint8_t attrMask=0)
Creates a foreground-only style (background ignored).
Definition style.h:90
TuiStyle()=default
Default constructor. All properties are ignored.
bool hasBackground() const
Returns true if the background color is defined (not ignored).
Definition style.h:80
TuiStyle merged(const TuiStyle &below) const
Merges this style on top of another.
uint8_t attrMask() const
Returns the attribute mask (1 = defined, 0 = ignored).
Definition style.h:62
uint8_t attrs() const
Returns the attribute flags.
Definition style.h:59
void setAttrs(uint8_t attrs, uint8_t mask)
Sets attribute flags with an explicit mask.
Definition style.h:74
Color background() const
Returns the background color.
Definition style.h:56
TuiStyle(const Color &fg, const Color &bg, uint8_t attrs=None)
Constructs with foreground, background, and attributes (all defined).
Definition style.h:49
static TuiStyle fromBackground(const Color &bg)
Creates a background-only style (foreground ignored).
Definition style.h:99
Attr
Text attribute flags.
Definition style.h:34
void setAttrs(uint8_t attrs)
Sets all attribute flags (marks all bits as defined).
Definition style.h:71
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19