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