diff options
author | Benji Dial <benji@benjidial.net> | 2024-07-29 19:59:52 -0400 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2024-07-29 19:59:52 -0400 |
commit | e6c3a80b01ffb52079783cddd9be6d392d0f7039 (patch) | |
tree | 148276b9878f287bc81638f90249ec4d7b86eaf0 /libraries/pake/source/widgets/fixed-text.cpp | |
parent | be691582ee12613278af24cb5a824eeb357f6324 (diff) | |
download | hilbert-os-e6c3a80b01ffb52079783cddd9be6d392d0f7039.tar.gz |
redesign compositor protocol, start widget library
Diffstat (limited to 'libraries/pake/source/widgets/fixed-text.cpp')
-rw-r--r-- | libraries/pake/source/widgets/fixed-text.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/libraries/pake/source/widgets/fixed-text.cpp b/libraries/pake/source/widgets/fixed-text.cpp new file mode 100644 index 0000000..9ae55dc --- /dev/null +++ b/libraries/pake/source/widgets/fixed-text.cpp @@ -0,0 +1,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; + } + +} |