Started adding the uiWindow size code.

This commit is contained in:
Pietro Gagliardi 2016-06-15 22:28:44 -04:00
parent c3777da0f4
commit 5fbe85c21a
2 changed files with 60 additions and 4 deletions

View File

@ -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;
}

3
ui.h
View File

@ -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);