Started adding support for multiline uiDrawTextLayouts and extracting the extents from them.

This commit is contained in:
Pietro Gagliardi 2016-01-14 20:02:01 -05:00
parent 06fa877058
commit c0db113367
2 changed files with 20 additions and 4 deletions

View File

@ -11,6 +11,7 @@ static uiCombobox *textItalic;
static uiCheckbox *textSmallCaps;
static uiCombobox *textStretch;
static uiCombobox *textGravity;
static uiEntry *textWidth;
static uiButton *textApply;
static uiCheckbox *addLeading;
static uiArea *textArea;
@ -89,6 +90,8 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
uiDrawTextLayout *layout;
uiDrawTextFontMetrics metrics;
double ypos;
double width;
double height;
memset(&desc, 0, sizeof (uiDrawTextFontDescriptor));
family = uiEntryText(textFont);
@ -103,17 +106,27 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
uiFreeText(family);
uiDrawTextFontGetMetrics(font, &metrics);
width = entryDouble(textWidth);
drawGuides(dp->Context, &metrics);
s = uiEntryText(textString);
layout = uiDrawNewTextLayout(s, font);
layout = uiDrawNewTextLayout(s, font, width);
uiFreeText(s);
ypos = 10;
uiDrawText(dp->Context, 10, ypos, layout);
// TODO make these optional?
uiDrawTextLayoutExtents(dp->Context, &width, &height);
uiDrawFreeTextLayout(layout);
layout = uiDrawNewTextLayout("This is a second line", font);
ypos += metrics.Ascent + metrics.Descent;
layout = uiDrawNewTextLayout("This is a second line", font, -1);
if (/*TODO*/entryDouble(textWidth) < 0) {
double ad;
ad = metrics.Ascent + metrics.Descent;
printf("ad:%g extent:%g", ad, height);
}
ypos += height;
if (uiCheckboxChecked(addLeading))
ypos += metrics.Leading;
uiDrawText(dp->Context, 10, ypos, layout);

5
ui.h
View File

@ -526,8 +526,11 @@ _UI_EXTERN void uiDrawTextFontDescribe(uiDrawTextFont *font, uiDrawTextFontDescr
// TODO yuck this name
_UI_EXTERN void uiDrawTextFontGetMetrics(uiDrawTextFont *font, uiDrawTextFontMetrics *metrics);
_UI_EXTERN uiDrawTextLayout *uiDrawNewTextLayout(const char *text, uiDrawTextFont *defaultFont);
_UI_EXTERN uiDrawTextLayout *uiDrawNewTextLayout(const char *text, uiDrawTextFont *defaultFont, double width);
_UI_EXTERN void uiDrawFreeTextLayout(uiDrawTextLayout *layout);
// TODO get width
_UI_EXTERN void uiDrawTextLayoutSetWidth(uiDrawTextLayout *layout, double width);
_UI_EXTERN void uiDrawTextLayoutExtents(uiDrawTextLayout *layout, double *width, double *height);
_UI_EXTERN void uiDrawText(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout);