summaryrefslogtreecommitdiff
path: root/libraries/pake/source/widgets/fixed-text.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/pake/source/widgets/fixed-text.cpp')
-rw-r--r--libraries/pake/source/widgets/fixed-text.cpp41
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 &param) {
+ 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;
+ }
+
+}