summaryrefslogtreecommitdiff
path: root/libraries/pake/source/widgets
diff options
context:
space:
mode:
authorBenji Dial <benji@benjidial.net>2024-07-29 21:26:17 -0400
committerBenji Dial <benji@benjidial.net>2024-07-29 21:26:17 -0400
commitc34b9191f258ddc15c5b45c000cd0266aed9dead (patch)
tree88e66004d1514d6f22b4366fc415b467784fee63 /libraries/pake/source/widgets
parente6c3a80b01ffb52079783cddd9be6d392d0f7039 (diff)
downloadhilbert-os-c34b9191f258ddc15c5b45c000cd0266aed9dead.tar.gz
window borders
Diffstat (limited to 'libraries/pake/source/widgets')
-rw-r--r--libraries/pake/source/widgets/fixed-text.cpp42
1 files changed, 33 insertions, 9 deletions
diff --git a/libraries/pake/source/widgets/fixed-text.cpp b/libraries/pake/source/widgets/fixed-text.cpp
index 9ae55dc..c3a9a10 100644
--- a/libraries/pake/source/widgets/fixed-text.cpp
+++ b/libraries/pake/source/widgets/fixed-text.cpp
@@ -12,24 +12,48 @@ namespace pake::widgets {
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)) {}
+ daguerre::hilbert_color fg,
+ halign ha, valign va)
+ : font(font), bg(bg), fg(fg),
+ text(std::move(text)), ha(ha), va(va) {}
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.dirty.fill(true, x_off, y_off, width, height);
+
+ onto.image.fill( bg, x_off, y_off, width, height);
+
+ switch (ha) {
+ case halign::left:
+ break;
+ case halign::center:
+ x_off = width / 2 - text.size() * font->glyph_width / 2;
+ break;
+ case halign::right:
+ x_off = width - text.size() * font->glyph_width;
+ break;
+ }
+
+ switch (va) {
+ case valign::top:
+ break;
+ case valign::center:
+ y_off = height / 2 - font->glyph_height / 2;
+ break;
+ case valign::bottom:
+ y_off = height - font->glyph_width;
+ break;
+ }
+
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);
+
}
}