From 5fbe85c21a887aa1b9c80c165da815726b1894b8 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 15 Jun 2016 22:28:44 -0400 Subject: [PATCH] Started adding the uiWindow size code. --- test/page15.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++---- ui.h | 3 +++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/test/page15.c b/test/page15.c index 4fdadf67..64b23a5c 100644 --- a/test/page15.c +++ b/test/page15.c @@ -2,6 +2,7 @@ #include "test.h" static uiSpinbox *x, *y; +static uiSpinbox *width, *height; static void moveX(uiSpinbox *s, void *data) { @@ -23,7 +24,7 @@ static void moveY(uiSpinbox *s, void *data) uiWindowSetPosition(w, xp, yp); } -static void update(uiWindow *w) +static void updatepos(uiWindow *w) { int xp, yp; @@ -37,13 +38,48 @@ static void center(uiButton *b, void *data) uiWindow *w = uiWindow(data); uiWindowCenter(w); - update(w); + updatepos(w); } void onMove(uiWindow *w, void *data) { printf("move\n"); - update(w); + updatepos(w); +} + +static void sizeWidth(uiSpinbox *s, void *data) +{ + uiWindow *w = uiWindow(data); + int xp, yp; + + uiWindowsContentSize(w, &xp, &yp); + xp = uiSpinboxValue(width); + uiWindowSetContentSize(w, xp, yp); +} + +static void sizeHeight(uiSpinbox *s, void *data) +{ + uiWindow *w = uiWindow(data); + int xp, yp; + + uiWindowContentSize(w, &xp, &yp); + yp = uiSpinboxValue(height); + uiWindowSetContentSize(w, xp, yp); +} + +static void updatesize(uiWindow *w) +{ + int xp, yp; + + uiWindowContentSize(w, &xp, &yp); + uiSpinboxSetValue(width, xp); + uiSpinboxSetValue(height, yp); +} + +void onSize(uiWindow *w, void *data) +{ + printf("size\n"); + updatesize(w); } uiBox *makePage15(uiWindow *w) @@ -70,7 +106,24 @@ uiBox *makePage15(uiWindow *w) uiSpinboxOnChanged(y, moveY, w); uiButtonOnClicked(button, center, w); uiWindowOnPositionChanged(w, onMove, NULL); - update(w); + updatepos(w); + + hbox = newHorizontalBox(); + uiBoxAppend(page15, uiControl(hbox), 0); + + uiBoxAppend(hbox, uiControl(uiNewLabel("Size")), 0); + width = uiNewSpinbox(INT_MIN, INT_MAX); + uiBoxAppend(hbox, uiControl(width), 1); + height = uiNewSpinbox(INT_MIN, INT_MAX); + uiBoxAppend(hbox, uiControl(height), 1); +// button = uiNewButton("Center"); +// uiBoxAppend(hbox, uiControl(button), 0); + + uiSpinboxOnChanged(width, sizeWidth, w); + uiSpinboxOnChanged(height, sizeHeight, w); +// uiButtonOnClicked(button, center, w); + uiWindowOnContentSizeChanged(w, onSize, NULL); + updatesize(w); return page15; } diff --git a/ui.h b/ui.h index 37821208..1ab01e91 100644 --- a/ui.h +++ b/ui.h @@ -103,6 +103,9 @@ _UI_EXTERN void uiWindowPosition(uiWindow *w, int *x, int *y); _UI_EXTERN void uiWindowSetPosition(uiWindow *w, int x, int y); _UI_EXTERN void uiWindowCenter(uiWindow *w); _UI_EXTERN void uiWindowOnPositionChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data); +_UI_EXTERN void uiWindowContentSize(uiWindow *w, int *width, int *height); +_UI_EXTERN void uiWindowSetContentSize(uiWindow *w, int width, int height); +_UI_EXTERN void uiWindowOnContentSizeChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data); _UI_EXTERN void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *w, void *data), void *data); _UI_EXTERN void uiWindowSetChild(uiWindow *w, uiControl *child); _UI_EXTERN int uiWindowMargined(uiWindow *w);