Added alignment to the drawtext example.

This commit is contained in:
Pietro Gagliardi 2018-03-18 15:30:50 -04:00
parent 8944a3fc55
commit a0d2d6a1f8
1 changed files with 22 additions and 1 deletions

View File

@ -7,6 +7,7 @@ uiWindow *mainwin;
uiArea *area; uiArea *area;
uiAreaHandler handler; uiAreaHandler handler;
uiFontButton *fontButton; uiFontButton *fontButton;
uiCombobox *alignment;
uiAttributedString *attrstr; uiAttributedString *attrstr;
@ -103,7 +104,7 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
uiFontButtonFont(fontButton, &defaultFont); uiFontButtonFont(fontButton, &defaultFont);
params.DefaultFont = &defaultFont; params.DefaultFont = &defaultFont;
params.Width = p->AreaWidth - (2 * margins); params.Width = p->AreaWidth - (2 * margins);
params.Align = uiDrawTextAlignLeft; params.Align = (uiDrawTextAlign) uiComboboxSelected(alignment);
textLayout = uiDrawNewTextLayout(&params); textLayout = uiDrawNewTextLayout(&params);
// TODO clip to margins // TODO clip to margins
uiDrawText(p->Context, textLayout, margins, margins); uiDrawText(p->Context, textLayout, margins, margins);
@ -137,6 +138,11 @@ static void onFontChanged(uiFontButton *b, void *data)
uiAreaQueueRedrawAll(area); uiAreaQueueRedrawAll(area);
} }
static void onComboboxSelected(uiCombobox *b, void *data)
{
uiAreaQueueRedrawAll(area);
}
static int onClosing(uiWindow *w, void *data) static int onClosing(uiWindow *w, void *data)
{ {
uiControlDestroy(uiControl(mainwin)); uiControlDestroy(uiControl(mainwin));
@ -155,6 +161,7 @@ int main(void)
uiInitOptions o; uiInitOptions o;
const char *err; const char *err;
uiBox *hbox, *vbox; uiBox *hbox, *vbox;
uiForm *form;
handler.Draw = handlerDraw; handler.Draw = handlerDraw;
handler.MouseEvent = handlerMouseEvent; handler.MouseEvent = handlerMouseEvent;
@ -190,6 +197,20 @@ int main(void)
uiFontButtonOnChanged(fontButton, onFontChanged, NULL); uiFontButtonOnChanged(fontButton, onFontChanged, NULL);
uiBoxAppend(vbox, uiControl(fontButton), 0); 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); area = uiNewArea(&handler);
uiBoxAppend(hbox, uiControl(area), 1); uiBoxAppend(hbox, uiControl(area), 1);