Add basic awareness of text input caret to ftbk and functions to get/set caret pos.

This commit is contained in:
Michael Drake 2012-07-31 14:04:12 +01:00
parent c48d7fa2da
commit 8db6d74bcb
3 changed files with 72 additions and 0 deletions

View File

@ -247,6 +247,16 @@ int fbtk_get_height(fbtk_widget_t *widget);
*/
bool fbtk_get_bbox(fbtk_widget_t *widget, struct nsfb_bbox_s *bbox);
/** Get a widget caret pos, if it owns caret.
*
* @param widget The widget to inspect.
* @param x If widget has caret, returns x-coord of caret within widget
* @param y If widget has caret, returns y-coord of caret within widget
* @param height If widget has caret, returns caret height
* @return true iff widget has caret
*/
bool fbtk_get_caret(fbtk_widget_t *widget, int *x, int *y, int *height);
/******************* Widget Manipulation **********************/
@ -255,6 +265,16 @@ bool fbtk_get_bbox(fbtk_widget_t *widget, struct nsfb_bbox_s *bbox);
*/
bool fbtk_set_pos_and_size(fbtk_widget_t *widget, int x, int y, int width, int height);
/** Set caret owner and position
*
* @param widget widget to give caret to, or ensure caret is released from
* @param set true: caret to be set for widget, false: caret to be released
* @param x x-coordinate of caret top
* @param y y-coordinate of caret top
* @param height height of caret
*/
void fbtk_set_caret(fbtk_widget_t *widget, bool set, int x, int y, int height);
/** Map a widget and request it is redrawn.
*/
int fbtk_set_mapping(fbtk_widget_t *widget, bool mapped);

View File

@ -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);

View File

@ -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 */