From 2917d568d2b64610f0bd116320e11c05b74f47a9 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 9 Apr 2015 12:14:18 -0400 Subject: [PATCH] Added a checkbox to the test program. It won't do anything just yet... --- new/test.c | 58 ++++++++++++++++++++++++++++++++++++++++++------------ new/ui.h | 4 ++++ 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/new/test.c b/new/test.c index 53869e7..cdc157d 100644 --- a/new/test.c +++ b/new/test.c @@ -47,13 +47,32 @@ static void setButtonText(uiControl *b, void *data) uiFreeText(text); } +static void getCheckboxText(uiControl *b, void *data) +{ + char *text; + + text = uiCheckboxText((uiControl *) data); + uiEntrySetText(e, text); + uiFreeText(text); +} + +static void setCheckboxText(uiControl *b, void *data) +{ + char *text; + + text = uiEntryText(e); + uiCheckboxSetText((uiControl *) data, text); + uiFreeText(text); +} + +uiControl *stacks[3]; + int main(int argc, char *argv[]) { uiInitError *err; uiWindow *w; - uiControl *mainStack; - uiControl *buttonStack; uiControl *getButton, *setButton; + uiControl *spaced; err = uiInit(NULL); if (err != NULL) { @@ -65,29 +84,42 @@ int main(int argc, char *argv[]) w = uiNewWindow("Hello", 320, 240); uiWindowOnClosing(w, onClosing, NULL); - mainStack = uiNewVerticalStack(); - uiWindowSetChild(w, mainStack); + stacks[0] = uiNewVerticalStack(); + uiWindowSetChild(w, staacks[0]); e = uiNewEntry(); - uiStackAdd(mainStack, e, 0); + uiStackAdd(stacks[0], e, 0); - buttonStack = uiNewHorizontalStack(); + stacks[1] = uiNewHorizontalStack(); getButton = uiNewButton("Get Window Text"); uiButtonOnClicked(getButton, getWindowText, w); setButton = uiNewButton("Set Window Text"); uiButtonOnClicked(setButton, setWindowText, w); - uiStackAdd(buttonStack, getButton, 1); - uiStackAdd(buttonStack, setButton, 1); - uiStackAdd(mainStack, buttonStack, 0); + uiStackAdd(stacks[1], getButton, 1); + uiStackAdd(stacks[1], setButton, 1); + uiStackAdd(stacks[0], stacks[1], 0); - buttonStack = uiNewHorizontalStack(); + stacks[2] = uiNewHorizontalStack(); getButton = uiNewButton("Get Button Text"); uiButtonOnClicked(getButton, getButtonText, getButton); setButton = uiNewButton("Set Button Text"); uiButtonOnClicked(setButton, setButtonText, getButton); - uiStackAdd(buttonStack, getButton, 1); - uiStackAdd(buttonStack, setButton, 1); - uiStackAdd(mainStack, buttonStack, 0); + uiStackAdd(stacks[2], getButton, 1); + uiStackAdd(stacks[2], setButton, 1); + uiStackAdd(stacks[0], stacks[2], 0); + + spaced = uiNewCheckbox("Spaced"); + + stacks[3] = uiNewHorizontalStack(); + getButton = uiNewButton("Get Checkbox Text"); + uiButtonOnClicked(getButton, getCheckboxText, spaced); + setButton = uiNewButton("Set Checkbox Text"); + uiButtonOnClicked(setButton, setCheckboxText, spaced); + uiStackAdd(stacks[3], getButton, 1); + uiStackAdd(stacks[3], setButton, 1); + uiStackAdd(stacks[0], stacks[3], 0); + + uiStackAdd(stacks[0], spaced, 0); uiWindowShow(w); uiMain(); diff --git a/new/ui.h b/new/ui.h index 435ec28..632a7ba 100644 --- a/new/ui.h +++ b/new/ui.h @@ -45,4 +45,8 @@ uiControl *uiNewEntry(void); char *uiEntryText(uiControl *); void uiEntrySetText(uiControl *, const char *); +uiControl *uiNewCheckbox(const char *); +char *uiCheckboxText(void); +void uiCheckboxSetText(uiControl *, const char *); + #endif