70 lines
2.0 KiB
C
70 lines
2.0 KiB
C
// 20 january 2017
|
|
#include "drawtext.h"
|
|
|
|
static const char *text =
|
|
"Each of the glyphs an end user interacts with are called graphemes. "
|
|
"If you enter a byte range in the text boxes below and click the button, you can see the blue box move to surround that byte range, as well as what the actual byte range necessary is. "
|
|
"You'll also see the index of the first grapheme; uiAttributedString has facilities for converting between UTF-8 code points and grapheme indices. "
|
|
"Additionally, click on the string to move the caret. Watch the status text at the bottom change too. "
|
|
"That being said: "
|
|
"\xC3\x93O\xCC\x81 (combining accents) "
|
|
"A\xCC\x81\xE0\xAB\x81 (multiple combining accents) "
|
|
"\xE2\x80\xAE#\xE2\x80\xAC (RTL glyph) "
|
|
"\xF0\x9F\x92\xBB (non-BMP character) "
|
|
"\xF0\x9F\x92\xBB\xCC\x80 (combined non-BMP character) "
|
|
"";
|
|
static char fontFamily[] = "Helvetica";
|
|
static uiDrawFontDescriptor defaultFont = {
|
|
.Family = fontFamily,
|
|
.Size = 14,
|
|
.Weight = uiDrawTextWeightNormal,
|
|
.Italic = uiDrawTextItalicNormal,
|
|
.Stretch = uiDrawTextStretchNormal,
|
|
};
|
|
static uiAttributedString *attrstr;
|
|
|
|
#define margins 10
|
|
|
|
static uiBox *panel;
|
|
|
|
static void draw(uiAreaDrawParams *p)
|
|
{
|
|
uiDrawPath *path;
|
|
uiDrawTextLayout *layout;
|
|
|
|
// only clip the text, not the guides
|
|
uiDrawSave(p->Context);
|
|
|
|
path = uiDrawNewPath(uiDrawFillModeWinding);
|
|
uiDrawPathAddRectangle(path, margins, margins,
|
|
p->AreaWidth - 2 * margins,
|
|
p->AreaHeight - 2 * margins);
|
|
uiDrawPathEnd(path);
|
|
uiDrawClip(p->Context, path);
|
|
uiDrawFreePath(path);
|
|
|
|
layout = uiDrawNewTextLayout(attrstr,
|
|
&defaultFont,
|
|
p->AreaWidth - 2 * margins);
|
|
uiDrawText(p->Context, layout, margins, margins);
|
|
|
|
uiDrawRestore(p->Context);
|
|
|
|
uiDrawFreeTextLayout(layout);
|
|
}
|
|
|
|
static struct example hitTestExample;
|
|
|
|
struct example *mkHitTestExample(void)
|
|
{
|
|
panel = uiNewVerticalBox();
|
|
|
|
hitTestExample.name = "Hit-Testing and Grapheme Boundaries";
|
|
hitTestExample.panel = uiControl(panel);
|
|
hitTestExample.draw = draw;
|
|
|
|
attrstr = uiNewAttributedString(text);
|
|
|
|
return &hitTestExample;
|
|
}
|