From c0db113367fede6a2669a748ffee3bad2247e5e1 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 14 Jan 2016 20:02:01 -0500 Subject: [PATCH] Started adding support for multiline uiDrawTextLayouts and extracting the extents from them. --- test/page9.c | 19 ++++++++++++++++--- ui.h | 5 ++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/test/page9.c b/test/page9.c index 05402833..e24f9215 100644 --- a/test/page9.c +++ b/test/page9.c @@ -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); diff --git a/ui.h b/ui.h index bd27bdf4..69bce336 100644 --- a/ui.h +++ b/ui.h @@ -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);