From a0d2d6a1f87a536580cc2a6b8915c90383d7f22a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 18 Mar 2018 15:30:50 -0400 Subject: [PATCH] Added alignment to the drawtext example. --- examples/drawtext/main.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/examples/drawtext/main.c b/examples/drawtext/main.c index 45549dff..3f6e403e 100644 --- a/examples/drawtext/main.c +++ b/examples/drawtext/main.c @@ -7,6 +7,7 @@ uiWindow *mainwin; uiArea *area; uiAreaHandler handler; uiFontButton *fontButton; +uiCombobox *alignment; uiAttributedString *attrstr; @@ -103,7 +104,7 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p) uiFontButtonFont(fontButton, &defaultFont); params.DefaultFont = &defaultFont; params.Width = p->AreaWidth - (2 * margins); - params.Align = uiDrawTextAlignLeft; + params.Align = (uiDrawTextAlign) uiComboboxSelected(alignment); textLayout = uiDrawNewTextLayout(¶ms); // TODO clip to margins uiDrawText(p->Context, textLayout, margins, margins); @@ -137,6 +138,11 @@ static void onFontChanged(uiFontButton *b, void *data) uiAreaQueueRedrawAll(area); } +static void onComboboxSelected(uiCombobox *b, void *data) +{ + uiAreaQueueRedrawAll(area); +} + static int onClosing(uiWindow *w, void *data) { uiControlDestroy(uiControl(mainwin)); @@ -155,6 +161,7 @@ int main(void) uiInitOptions o; const char *err; uiBox *hbox, *vbox; + uiForm *form; handler.Draw = handlerDraw; handler.MouseEvent = handlerMouseEvent; @@ -190,6 +197,20 @@ int main(void) uiFontButtonOnChanged(fontButton, onFontChanged, NULL); uiBoxAppend(vbox, uiControl(fontButton), 0); + form = uiNewForm(); + uiFormSetPadded(form, 1); + // TODO on OS X if this is set to 1 then the window can't resize; does the form not have the concept of stretchy trailing space? + uiBoxAppend(vbox, uiControl(form), 0); + + alignment = uiNewCombobox(); + // note that the items match with the values of the uiDrawTextAlign values + uiComboboxAppend(alignment, "Left"); + uiComboboxAppend(alignment, "Center"); + uiComboboxAppend(alignment, "Right"); + uiComboboxSetSelected(alignment, 0); // start with left alignment + uiComboboxOnSelected(alignment, onComboboxSelected, NULL); + uiFormAppend(form, "Alignment", uiControl(alignment), 0); + area = uiNewArea(&handler); uiBoxAppend(hbox, uiControl(area), 1);