Added the descriptive label to the caret.

This commit is contained in:
Pietro Gagliardi 2017-02-06 01:46:06 -05:00
parent 675e7594da
commit 71176c2e33
1 changed files with 16 additions and 1 deletions

View File

@ -2,6 +2,7 @@
#include "drawtext.h" #include "drawtext.h"
// TODO have a ligature // TODO have a ligature
// TODO allow clicking on the end of a line to put the caret there
static const char *text = static const char *text =
"Each of the glyphs an end user interacts with are called graphemes. " "Each of the glyphs an end user interacts with are called graphemes. "
@ -29,6 +30,7 @@ static uiAttributedString *attrstr;
#define margins 10 #define margins 10
static uiBox *panel; static uiBox *panel;
static uiLabel *caretLabel;
static uiCheckbox *showLineBounds; static uiCheckbox *showLineBounds;
static size_t cursorPos; static size_t cursorPos;
@ -135,10 +137,17 @@ static void draw(uiAreaDrawParams *p)
uiDrawFreeTextLayout(layout); uiDrawFreeTextLayout(layout);
} }
static const char *positions[] = {
[uiDrawTextLayoutHitTestPositionBefore] = "before",
[uiDrawTextLayoutHitTestPositionInside] = "inside",
[uiDrawTextLayoutHitTestPositionAfter] = "after",
};
static void mouse(uiAreaMouseEvent *e) static void mouse(uiAreaMouseEvent *e)
{ {
uiDrawTextLayout *layout; uiDrawTextLayout *layout;
uiDrawTextLayoutHitTestResult res; uiDrawTextLayoutHitTestResult res;
char labelText[128];
if (e->Down != 1) if (e->Down != 1)
return; return;
@ -151,7 +160,11 @@ static void mouse(uiAreaMouseEvent *e)
&res); &res);
uiDrawFreeTextLayout(layout); uiDrawFreeTextLayout(layout);
// TODO make a label and set it sprintf(labelText, "pos %zd line %d x position %s y position %s",
res.Pos, res.Line,
positions[res.XPosition],
positions[res.YPosition]);
uiLabelSetText(caretLabel, labelText);
cursorPos = res.Pos; cursorPos = res.Pos;
redraw(); redraw();
@ -178,6 +191,8 @@ static uiCheckbox *newCheckbox(const char *text)
struct example *mkHitTestExample(void) struct example *mkHitTestExample(void)
{ {
panel = uiNewVerticalBox(); panel = uiNewVerticalBox();
caretLabel = uiNewLabel("Caret information is shown here");
uiBoxAppend(panel, uiControl(caretLabel), 0);
showLineBounds = newCheckbox("Show Line Bounds (for debugging metrics)"); showLineBounds = newCheckbox("Show Line Bounds (for debugging metrics)");
hitTestExample.name = "Hit-Testing and Grapheme Boundaries"; hitTestExample.name = "Hit-Testing and Grapheme Boundaries";