summaryrefslogtreecommitdiff
path: root/framebuffer/fbtk
diff options
context:
space:
mode:
Diffstat (limited to 'framebuffer/fbtk')
-rw-r--r--framebuffer/fbtk/fbtk.c44
-rw-r--r--framebuffer/fbtk/text.c28
-rw-r--r--framebuffer/fbtk/widget.h8
3 files changed, 67 insertions, 13 deletions
diff --git a/framebuffer/fbtk/fbtk.c b/framebuffer/fbtk/fbtk.c
index db298ebdc..8e8bc112c 100644
--- a/framebuffer/fbtk/fbtk.c
+++ b/framebuffer/fbtk/fbtk.c
@@ -220,6 +220,28 @@ fbtk_set_pos_and_size(fbtk_widget_t *widget,
return false;
}
+
+/* exported function docuemnted in fbtk.h */
+void
+fbtk_set_caret(fbtk_widget_t *widget, bool set,
+ int x, int y, int height)
+{
+ fbtk_widget_t *root;
+
+ assert(widget != NULL);
+ root = fbtk_get_root_widget(widget);
+
+ if (set) {
+ root->u.root.caret.owner = widget;
+ root->u.root.caret.x = x;
+ root->u.root.caret.y = y;
+ root->u.root.caret.height = height;
+
+ } else {
+ root->u.root.caret.owner = NULL;
+ }
+}
+
/* exported function documented in fbtk.h */
int
fbtk_destroy_widget(fbtk_widget_t *widget)
@@ -429,6 +451,27 @@ fbtk_get_bbox(fbtk_widget_t *widget, nsfb_bbox_t *bbox)
return true;
}
+bool
+fbtk_get_caret(fbtk_widget_t *widget, int *x, int *y, int *height)
+{
+ fbtk_widget_t *root = fbtk_get_root_widget(widget);
+
+ if (root->u.root.caret.owner == widget) {
+ *x = root->u.root.caret.x;
+ *y = root->u.root.caret.y;
+ *height = root->u.root.caret.height;
+
+ return true;
+
+ } else {
+ *x = 0;
+ *y = 0;
+ *height = 0;
+
+ return false;
+ }
+}
+
/* exported function documented in fbtk.h */
fbtk_widget_t *
fbtk_get_widget_at(fbtk_widget_t *nwid, int x, int y)
@@ -727,6 +770,7 @@ fbtk_init(nsfb_t *fb)
root->type = FB_WIDGET_TYPE_ROOT;
root->u.root.fb = fb;
+ root->u.root.caret.owner = NULL;
nsfb_get_geometry(fb, &root->width, &root->height, NULL);
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index f50a5ad59..27968148f 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -50,6 +50,19 @@
/* Convert pixels to points, assuming a DPI of 90 */
#define px_to_pt(x) (((x) * 72) / FBTK_DPI)
+/* Get a font style for a text input */
+static inline void
+fb_text_font_style(fbtk_widget_t *widget, int font_height,
+ plot_font_style_t *font_style)
+{
+ font_style->family = PLOT_FONT_FAMILY_SANS_SERIF;
+ font_style->size = px_to_pt(font_height) * FONT_SIZE_SCALE;
+ font_style->weight = 400;
+ font_style->flags = FONTF_NONE;
+ font_style->background = widget->bg;
+ font_style->foreground = widget->fg;
+}
+
/** Text redraw callback.
*
* Called when a text widget requires redrawing.
@@ -94,13 +107,7 @@ fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi )
if (widget->u.text.text != NULL) {
fh = widget->height - padding - padding;
- font_style.family = PLOT_FONT_FAMILY_SANS_SERIF;
- font_style.size = px_to_pt(fh) * FONT_SIZE_SCALE;
- font_style.weight = 400;
- font_style.flags = FONTF_NONE;
- font_style.background = widget->bg;
- font_style.foreground = widget->fg;
-
+ fb_text_font_style(widget, fh, &font_style);
FBTK_LOG(("plotting %p at %d,%d %d,%d w/h %d,%d font h %d padding %d",
widget, bbox.x0, bbox.y0, bbox.x1, bbox.y1,
widget->width, widget->height, fh, padding));
@@ -192,12 +199,7 @@ fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
if (widget->u.text.text != NULL) {
fh = widget->height - border - border;
- font_style.family = PLOT_FONT_FAMILY_SANS_SERIF;
- font_style.size = px_to_pt(fh) * FONT_SIZE_SCALE;
- font_style.weight = 400;
- font_style.flags = FONTF_NONE;
- font_style.background = widget->bg;
- font_style.foreground = widget->fg;
+ fb_text_font_style(widget, fh, &font_style);
LOG(("plotting %p at %d,%d %d,%d w/h %d,%d font h %d border %d",
widget, bbox.x0, bbox.y0, bbox.x1, bbox.y1,
diff --git a/framebuffer/fbtk/widget.h b/framebuffer/fbtk/widget.h
index 060999bba..e31fa117d 100644
--- a/framebuffer/fbtk/widget.h
+++ b/framebuffer/fbtk/widget.h
@@ -161,6 +161,14 @@ struct fbtk_widget_s {
struct fbtk_widget_s *prev; /* previous widget pointer wasin */
struct fbtk_widget_s *grabbed; /* widget that has grabbed pointer movement. */
struct fbtk_widget_s *input;
+
+ /* caret */
+ struct {
+ struct fbtk_widget_s *owner; /* widget / NULL */
+ int x; /* relative to owner */
+ int y; /* relative to owner */
+ int height;
+ } caret;
} root;
/* bitmap */