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
|
#include <pake/widgets/fixed-text.hpp>
static void draw_if_true(
daguerre::hilbert_color &out, const bool &in,
const daguerre::hilbert_color ¶m) {
if (in) out = param;
}
namespace pake::widgets {
fixed_text::fixed_text(
std::string &&text,
const daguerre::fixed_font<bool> *font,
daguerre::hilbert_color bg,
daguerre::hilbert_color fg)
: font(font), bg(bg), fg(fg), text(std::move(text)) {}
void fixed_text::render(
dirtiable_image &onto, int x_off, int y_off, bool force) {
if (force) {
onto.image.fill( bg, x_off, y_off, width, height);
onto.dirty.fill(true, x_off, y_off, width, height);
//TODO: have options for alignment
//TODO: check overflow
onto.image.render_text(
*font, fg, x_off, y_off,
text.data(), draw_if_true);
onto.dirty.fill(
true, x_off, y_off,
font->glyph_width * text.size(),
font->glyph_height);
}
}
void fixed_text::notify_size(int width, int height) {
this->width = width; this->height = height;
}
}
|