And implemented caret motions in the hit test examples.
This commit is contained in:
parent
64a1167e5f
commit
a1bebc82d8
|
@ -349,8 +349,7 @@ void uiDrawTextLayoutByteRangeToRectangle(uiDrawTextLayout *tl, size_t start, si
|
|||
for (i = 0; i < tl->nLines; i++) {
|
||||
line = (CTLineRef) CFArrayGetValueAtIndex(tl->lines, i);
|
||||
range = CTLineGetStringRange(line);
|
||||
// TODO explain this check
|
||||
if (range.location >= start)
|
||||
if (start >= range.location && start < (range.location + range.length))
|
||||
break;
|
||||
}
|
||||
if (i == tl->nLines)
|
||||
|
|
|
@ -253,6 +253,7 @@ struct example *mkBasicExample(void)
|
|||
basicExample.name = "Basic Paragraph of Text";
|
||||
basicExample.panel = uiControl(panel);
|
||||
basicExample.draw = draw;
|
||||
basicExample.mouse = NULL;
|
||||
|
||||
attrstr = uiNewAttributedString(text);
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@ struct example {
|
|||
const char *name;
|
||||
uiControl *panel;
|
||||
void (*draw)(uiAreaDrawParams *p);
|
||||
// TODO mouse and key?
|
||||
void (*mouse)(uiAreaMouseEvent *e);
|
||||
// TODO key?
|
||||
};
|
||||
|
||||
// main.c
|
||||
|
|
|
@ -133,6 +133,28 @@ static void draw(uiAreaDrawParams *p)
|
|||
uiDrawFreeTextLayout(layout);
|
||||
}
|
||||
|
||||
static void mouse(uiAreaMouseEvent *e)
|
||||
{
|
||||
uiDrawTextLayout *layout;
|
||||
uiDrawTextLayoutHitTestResult res;
|
||||
|
||||
if (e->Down != 1)
|
||||
return;
|
||||
|
||||
layout = uiDrawNewTextLayout(attrstr,
|
||||
&defaultFont,
|
||||
e->AreaWidth - 2 * margins);
|
||||
uiDrawTextLayoutHitTest(layout,
|
||||
e->X - margins, e->Y - margins,
|
||||
&res);
|
||||
uiDrawFreeTextLayout(layout);
|
||||
|
||||
// TODO make a label and set it
|
||||
|
||||
cursorPos = res.Pos;
|
||||
redraw();
|
||||
}
|
||||
|
||||
static struct example hitTestExample;
|
||||
|
||||
// TODO share?
|
||||
|
@ -159,6 +181,7 @@ struct example *mkHitTestExample(void)
|
|||
hitTestExample.name = "Hit-Testing and Grapheme Boundaries";
|
||||
hitTestExample.panel = uiControl(panel);
|
||||
hitTestExample.draw = draw;
|
||||
hitTestExample.mouse = mouse;
|
||||
|
||||
attrstr = uiNewAttributedString(text);
|
||||
cursorPos = uiAttributedStringLen(attrstr);
|
||||
|
|
|
@ -31,7 +31,8 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
|
|||
|
||||
static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e)
|
||||
{
|
||||
// do nothing
|
||||
if (examples[curExample]->mouse != NULL)
|
||||
examples[curExample]->mouse(e);
|
||||
}
|
||||
|
||||
static void handlerMouseCrossed(uiAreaHandler *ah, uiArea *a, int left)
|
||||
|
|
Loading…
Reference in New Issue