Whoops, forgot to migrate the tests.
This commit is contained in:
parent
a048f0bcc0
commit
d5f2cae243
|
@ -0,0 +1,14 @@
|
|||
# 22 april 2015
|
||||
|
||||
testCFILES = \
|
||||
test/main.c \
|
||||
test/menus.c \
|
||||
test/page1.c \
|
||||
test/page2.c \
|
||||
test/page3.c \
|
||||
test/page4.c \
|
||||
test/page5.c \
|
||||
test/spaced.c
|
||||
|
||||
testHFILES = \
|
||||
test/test.h
|
|
@ -0,0 +1,110 @@
|
|||
// 22 april 2015
|
||||
#include "test.h"
|
||||
|
||||
void die(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
fprintf(stderr, "[test program] ");
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(ap);
|
||||
abort();
|
||||
}
|
||||
|
||||
int onClosing(uiWindow *w, void *data)
|
||||
{
|
||||
printf("in onClosing()\n");
|
||||
uiQuit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int onShouldQuit(void *data)
|
||||
{
|
||||
printf("in onShouldQuit()\n");
|
||||
if (uiMenuItemChecked(shouldQuitItem)) {
|
||||
uiControlDestroy(uiControl(data));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uiBox *mainBox;
|
||||
uiTab *mainTab;
|
||||
|
||||
uiBox *(*newhbox)(void);
|
||||
uiBox *(*newvbox)(void);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
uiInitOptions o;
|
||||
int i;
|
||||
const char *err;
|
||||
uiWindow *w;
|
||||
uiBox *page2, *page3, *page4, *page5;
|
||||
int nomenus = 0;
|
||||
|
||||
newhbox = uiNewHorizontalBox;
|
||||
newvbox = uiNewVerticalBox;
|
||||
|
||||
memset(&o, 0, sizeof (uiInitOptions));
|
||||
for (i = 1; i < argc; i++)
|
||||
if (strcmp(argv[i], "nomenus") == 0)
|
||||
nomenus = 1;
|
||||
else if (strcmp(argv[i], "swaphv") == 0) {
|
||||
newhbox = uiNewVerticalBox;
|
||||
newvbox = uiNewHorizontalBox;
|
||||
} else {
|
||||
fprintf(stderr, "%s: unrecognized option %s\n", argv[0], argv[i]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
err = uiInit(&o);
|
||||
if (err != NULL) {
|
||||
fprintf(stderr, "error initializing ui: %s\n", err);
|
||||
uiFreeInitError(err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!nomenus)
|
||||
initMenus();
|
||||
|
||||
w = newWindow("Main Window", 320, 240, 1);
|
||||
uiWindowOnClosing(w, onClosing, NULL);
|
||||
printf("main window %p\n", w);
|
||||
|
||||
uiOnShouldQuit(onShouldQuit, w);
|
||||
|
||||
mainBox = newHorizontalBox();
|
||||
uiWindowSetChild(w, uiControl(mainBox));
|
||||
|
||||
mainTab = newTab();
|
||||
uiBoxAppend(mainBox, uiControl(mainTab), 1);
|
||||
|
||||
// page 1 uses page 2's uiGroup
|
||||
page2 = makePage2();
|
||||
|
||||
makePage1(w);
|
||||
uiTabAppend(mainTab, "Page 1", uiControl(page1));
|
||||
|
||||
uiTabAppend(mainTab, "Page 2", uiControl(page2));
|
||||
|
||||
uiTabAppend(mainTab, "Empty Page", uiControl(uiNewHorizontalBox()));
|
||||
|
||||
page3 = makePage3();
|
||||
uiTabAppend(mainTab, "Page 3", uiControl(page3));
|
||||
|
||||
page4 = makePage4();
|
||||
uiTabAppend(mainTab, "Page 4", uiControl(page4));
|
||||
|
||||
page5 = makePage5();
|
||||
uiTabAppend(mainTab, "Page 5", uiControl(page5));
|
||||
|
||||
uiControlShow(uiControl(w));
|
||||
uiMain();
|
||||
printf("after uiMain()\n");
|
||||
uiUninit();
|
||||
printf("after uiUninit()\n");
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
// 23 april 2015
|
||||
#include "test.h"
|
||||
|
||||
uiMenu *fileMenu;
|
||||
uiMenuItem *newItem;
|
||||
uiMenuItem *openItem;
|
||||
uiMenuItem *shouldQuitItem;
|
||||
uiMenuItem *quitItem;
|
||||
uiMenu *editMenu;
|
||||
uiMenuItem *undoItem;
|
||||
uiMenuItem *checkItem;
|
||||
uiMenuItem *accelItem;
|
||||
uiMenuItem *prefsItem;
|
||||
uiMenu *testMenu;
|
||||
uiMenuItem *enabledItem;
|
||||
uiMenuItem *enableThisItem;
|
||||
uiMenuItem *forceCheckedItem;
|
||||
uiMenuItem *forceUncheckedItem;
|
||||
uiMenuItem *whatWindowItem;
|
||||
uiMenu *moreTestsMenu;
|
||||
uiMenuItem *quitEnabledItem;
|
||||
uiMenuItem *prefsEnabledItem;
|
||||
uiMenuItem *aboutEnabledItem;
|
||||
uiMenuItem *checkEnabledItem;
|
||||
uiMenu *multiMenu;
|
||||
uiMenu *helpMenu;
|
||||
uiMenuItem *helpItem;
|
||||
uiMenuItem *aboutItem;
|
||||
|
||||
static void enableItemTest(uiMenuItem *item, uiWindow *w, void *data)
|
||||
{
|
||||
if (uiMenuItemChecked(item))
|
||||
uiMenuItemEnable(uiMenuItem(data));
|
||||
else
|
||||
uiMenuItemDisable(uiMenuItem(data));
|
||||
}
|
||||
|
||||
static void forceOn(uiMenuItem *item, uiWindow *w, void *data)
|
||||
{
|
||||
uiMenuItemSetChecked(enabledItem, 1);
|
||||
}
|
||||
|
||||
static void forceOff(uiMenuItem *item, uiWindow *w, void *data)
|
||||
{
|
||||
uiMenuItemSetChecked(enabledItem, 0);
|
||||
}
|
||||
|
||||
static void whatWindow(uiMenuItem *item, uiWindow *w, void *data)
|
||||
{
|
||||
printf("menu item clicked on window %p\n", w);
|
||||
}
|
||||
|
||||
void initMenus(void)
|
||||
{
|
||||
fileMenu = uiNewMenu("File");
|
||||
newItem = uiMenuAppendItem(fileMenu, "New");
|
||||
openItem = uiMenuAppendItem(fileMenu, "Open");
|
||||
uiMenuAppendSeparator(fileMenu);
|
||||
shouldQuitItem = uiMenuAppendCheckItem(fileMenu, "Should Quit");
|
||||
quitItem = uiMenuAppendQuitItem(fileMenu);
|
||||
|
||||
editMenu = uiNewMenu("Edit");
|
||||
undoItem = uiMenuAppendItem(editMenu, "Undo");
|
||||
uiMenuItemDisable(undoItem);
|
||||
uiMenuAppendSeparator(editMenu);
|
||||
checkItem = uiMenuAppendCheckItem(editMenu, "Check Me\tTest");
|
||||
accelItem = uiMenuAppendItem(editMenu, "A&ccele&&rator T_es__t");
|
||||
prefsItem = uiMenuAppendPreferencesItem(editMenu);
|
||||
|
||||
testMenu = uiNewMenu("Test");
|
||||
enabledItem = uiMenuAppendCheckItem(testMenu, "Enable Below Item");
|
||||
uiMenuItemSetChecked(enabledItem, 1);
|
||||
enableThisItem = uiMenuAppendItem(testMenu, "This Will Be Enabled");
|
||||
uiMenuItemOnClicked(enabledItem, enableItemTest, enableThisItem);
|
||||
forceCheckedItem = uiMenuAppendItem(testMenu, "Force Above Checked");
|
||||
uiMenuItemOnClicked(forceCheckedItem, forceOn, NULL);
|
||||
forceUncheckedItem = uiMenuAppendItem(testMenu, "Force Above Unchecked");
|
||||
uiMenuItemOnClicked(forceUncheckedItem, forceOff, NULL);
|
||||
uiMenuAppendSeparator(testMenu);
|
||||
whatWindowItem = uiMenuAppendItem(testMenu, "What Window?");
|
||||
uiMenuItemOnClicked(whatWindowItem, whatWindow, NULL);
|
||||
|
||||
moreTestsMenu = uiNewMenu("More Tests");
|
||||
quitEnabledItem = uiMenuAppendCheckItem(moreTestsMenu, "Quit Item Enabled");
|
||||
uiMenuItemSetChecked(quitEnabledItem, 1);
|
||||
prefsEnabledItem = uiMenuAppendCheckItem(moreTestsMenu, "Preferences Item Enabled");
|
||||
uiMenuItemSetChecked(prefsEnabledItem, 1);
|
||||
aboutEnabledItem = uiMenuAppendCheckItem(moreTestsMenu, "About Item Enabled");
|
||||
uiMenuItemSetChecked(aboutEnabledItem, 1);
|
||||
uiMenuAppendSeparator(moreTestsMenu);
|
||||
checkEnabledItem = uiMenuAppendCheckItem(moreTestsMenu, "Check Me Item Enabled");
|
||||
uiMenuItemSetChecked(checkEnabledItem, 1);
|
||||
|
||||
multiMenu = uiNewMenu("Multi");
|
||||
uiMenuAppendSeparator(multiMenu);
|
||||
uiMenuAppendSeparator(multiMenu);
|
||||
uiMenuAppendItem(multiMenu, "Item");
|
||||
uiMenuAppendSeparator(multiMenu);
|
||||
uiMenuAppendSeparator(multiMenu);
|
||||
uiMenuAppendItem(multiMenu, "Item");
|
||||
uiMenuAppendSeparator(multiMenu);
|
||||
uiMenuAppendSeparator(multiMenu);
|
||||
|
||||
helpMenu = uiNewMenu("Help");
|
||||
helpItem = uiMenuAppendItem(helpMenu, "Help");
|
||||
aboutItem = uiMenuAppendAboutItem(helpMenu);
|
||||
|
||||
uiMenuItemOnClicked(quitEnabledItem, enableItemTest, quitItem);
|
||||
uiMenuItemOnClicked(prefsEnabledItem, enableItemTest, prefsItem);
|
||||
uiMenuItemOnClicked(aboutEnabledItem, enableItemTest, aboutItem);
|
||||
uiMenuItemOnClicked(checkEnabledItem, enableItemTest, checkItem);
|
||||
}
|
|
@ -0,0 +1,171 @@
|
|||
// 29 april 2015
|
||||
#include "test.h"
|
||||
|
||||
static uiEntry *entry;
|
||||
static uiCheckbox *spaced;
|
||||
|
||||
#define TEXT(name, type, getter, setter) \
|
||||
static void get ## name ## Text(uiButton *b, void *data) \
|
||||
{ \
|
||||
char *text; \
|
||||
text = getter(type(data)); \
|
||||
uiEntrySetText(entry, text); \
|
||||
uiFreeText(text); \
|
||||
} \
|
||||
static void set ## name ## Text(uiButton *b, void *data) \
|
||||
{ \
|
||||
char *text; \
|
||||
text = uiEntryText(entry); \
|
||||
setter(type(data), text); \
|
||||
uiFreeText(text); \
|
||||
}
|
||||
TEXT(Window, uiWindow, uiWindowTitle, uiWindowSetTitle)
|
||||
TEXT(Button, uiButton, uiButtonText, uiButtonSetText)
|
||||
TEXT(Checkbox, uiCheckbox, uiCheckboxText, uiCheckboxSetText)
|
||||
TEXT(Label, uiLabel, uiLabelText, uiLabelSetText)
|
||||
TEXT(Group, uiGroup, uiGroupTitle, uiGroupSetTitle)
|
||||
|
||||
static void onChanged(uiEntry *e, void *data)
|
||||
{
|
||||
printf("onChanged()\n");
|
||||
}
|
||||
|
||||
static void toggleSpaced(uiCheckbox *c, void *data)
|
||||
{
|
||||
setSpaced(uiCheckboxChecked(spaced));
|
||||
}
|
||||
|
||||
static void forceSpaced(uiButton *b, void *data)
|
||||
{
|
||||
uiCheckboxSetChecked(spaced, data != NULL);
|
||||
}
|
||||
|
||||
static void showSpaced(uiButton *b, void *data)
|
||||
{
|
||||
char s[12];
|
||||
|
||||
querySpaced(s);
|
||||
uiEntrySetText(entry, s);
|
||||
}
|
||||
|
||||
#define SHED(method, Method) \
|
||||
static void method ## Control(uiButton *b, void *data) \
|
||||
{ \
|
||||
uiControl ## Method(uiControl(data)); \
|
||||
}
|
||||
SHED(show, Show)
|
||||
SHED(hide, Hide)
|
||||
SHED(enable, Enable)
|
||||
SHED(disable, Disable)
|
||||
|
||||
uiBox *page1;
|
||||
|
||||
void makePage1(uiWindow *w)
|
||||
{
|
||||
uiButton *getButton, *setButton;
|
||||
uiBox *hbox;
|
||||
uiBox *testBox;
|
||||
uiLabel *label;
|
||||
|
||||
page1 = newVerticalBox();
|
||||
|
||||
entry = uiNewEntry();
|
||||
uiEntryOnChanged(entry, onChanged, NULL);
|
||||
uiBoxAppend(page1, uiControl(entry), 0);
|
||||
|
||||
spaced = uiNewCheckbox("Spaced");
|
||||
uiCheckboxOnToggled(spaced, toggleSpaced, NULL);
|
||||
label = uiNewLabel("Label");
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
getButton = uiNewButton("Get Window Text");
|
||||
uiButtonOnClicked(getButton, getWindowText, w);
|
||||
setButton = uiNewButton("Set Window Text");
|
||||
uiButtonOnClicked(setButton, setWindowText, w);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
uiBoxAppend(hbox, uiControl(setButton), 1);
|
||||
uiBoxAppend(page1, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
getButton = uiNewButton("Get Button Text");
|
||||
uiButtonOnClicked(getButton, getButtonText, getButton);
|
||||
setButton = uiNewButton("Set Button Text");
|
||||
uiButtonOnClicked(setButton, setButtonText, getButton);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
uiBoxAppend(hbox, uiControl(setButton), 1);
|
||||
uiBoxAppend(page1, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
getButton = uiNewButton("Get Checkbox Text");
|
||||
uiButtonOnClicked(getButton, getCheckboxText, spaced);
|
||||
setButton = uiNewButton("Set Checkbox Text");
|
||||
uiButtonOnClicked(setButton, setCheckboxText, spaced);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
uiBoxAppend(hbox, uiControl(setButton), 1);
|
||||
uiBoxAppend(page1, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
getButton = uiNewButton("Get Label Text");
|
||||
uiButtonOnClicked(getButton, getLabelText, label);
|
||||
setButton = uiNewButton("Set Label Text");
|
||||
uiButtonOnClicked(setButton, setLabelText, label);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
uiBoxAppend(hbox, uiControl(setButton), 1);
|
||||
uiBoxAppend(page1, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
getButton = uiNewButton("Get Group Text");
|
||||
uiButtonOnClicked(getButton, getGroupText, page2group);
|
||||
setButton = uiNewButton("Set Group Text");
|
||||
uiButtonOnClicked(setButton, setGroupText, page2group);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
uiBoxAppend(hbox, uiControl(setButton), 1);
|
||||
uiBoxAppend(page1, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
uiBoxAppend(hbox, uiControl(spaced), 1);
|
||||
getButton = uiNewButton("On");
|
||||
uiButtonOnClicked(getButton, forceSpaced, getButton);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 0);
|
||||
getButton = uiNewButton("Off");
|
||||
uiButtonOnClicked(getButton, forceSpaced, NULL);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 0);
|
||||
getButton = uiNewButton("Show");
|
||||
uiButtonOnClicked(getButton, showSpaced, NULL);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 0);
|
||||
uiBoxAppend(page1, uiControl(hbox), 0);
|
||||
|
||||
testBox = newHorizontalBox();
|
||||
setButton = uiNewButton("Button");
|
||||
uiBoxAppend(testBox, uiControl(setButton), 1);
|
||||
getButton = uiNewButton("Show");
|
||||
uiButtonOnClicked(getButton, showControl, setButton);
|
||||
uiBoxAppend(testBox, uiControl(getButton), 0);
|
||||
getButton = uiNewButton("Hide");
|
||||
uiButtonOnClicked(getButton, hideControl, setButton);
|
||||
uiBoxAppend(testBox, uiControl(getButton), 0);
|
||||
getButton = uiNewButton("Enable");
|
||||
uiButtonOnClicked(getButton, enableControl, setButton);
|
||||
uiBoxAppend(testBox, uiControl(getButton), 0);
|
||||
getButton = uiNewButton("Disable");
|
||||
uiButtonOnClicked(getButton, disableControl, setButton);
|
||||
uiBoxAppend(testBox, uiControl(getButton), 0);
|
||||
uiBoxAppend(page1, uiControl(testBox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
getButton = uiNewButton("Show Box");
|
||||
uiButtonOnClicked(getButton, showControl, testBox);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
getButton = uiNewButton("Hide Box");
|
||||
uiButtonOnClicked(getButton, hideControl, testBox);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
getButton = uiNewButton("Enable Box");
|
||||
uiButtonOnClicked(getButton, enableControl, testBox);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
getButton = uiNewButton("Disable Box");
|
||||
uiButtonOnClicked(getButton, disableControl, testBox);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
uiBoxAppend(page1, uiControl(hbox), 0);
|
||||
|
||||
uiBoxAppend(page1, uiControl(label), 0);
|
||||
}
|
|
@ -0,0 +1,202 @@
|
|||
// 29 april 2015
|
||||
#include "test.h"
|
||||
|
||||
uiGroup *page2group;
|
||||
|
||||
static uiLabel *movingLabel;
|
||||
static uiBox *movingBoxes[2];
|
||||
static int movingCurrent;
|
||||
|
||||
static void moveLabel(uiButton *b, void *data)
|
||||
{
|
||||
int from, to;
|
||||
|
||||
from = movingCurrent;
|
||||
to = 0;
|
||||
if (from == 0)
|
||||
to = 1;
|
||||
uiBoxDelete(movingBoxes[from], 0);
|
||||
uiBoxAppend(movingBoxes[to], uiControl(movingLabel), 0);
|
||||
movingCurrent = to;
|
||||
}
|
||||
|
||||
static int moveBack;
|
||||
#define moveOutText "Move Page 1 Out"
|
||||
#define moveBackText "Move Page 1 Back"
|
||||
|
||||
static void movePage1(uiButton *b, void *data)
|
||||
{
|
||||
if (moveBack) {
|
||||
uiBoxDelete(mainBox, 1);
|
||||
uiTabInsertAt(mainTab, "Page 1", 0, uiControl(page1));
|
||||
uiButtonSetText(b, moveOutText);
|
||||
moveBack = 0;
|
||||
return;
|
||||
}
|
||||
uiTabDelete(mainTab, 0);
|
||||
uiBoxAppend(mainBox, uiControl(page1), 1);
|
||||
uiButtonSetText(b, moveBackText);
|
||||
moveBack = 1;
|
||||
}
|
||||
|
||||
static void openAnotherWindow(uiButton *b, void *data)
|
||||
{
|
||||
uiControlShow(uiControl(uiNewWindow("Another Window", 100, 100, data != NULL)));
|
||||
}
|
||||
|
||||
static void openAnotherDisabledWindow(uiButton *b, void *data)
|
||||
{
|
||||
uiWindow *w;
|
||||
|
||||
w = uiNewWindow("Another Window", 100, 100, data != NULL);
|
||||
uiControlDisable(uiControl(w));
|
||||
uiControlShow(uiControl(w));
|
||||
}
|
||||
|
||||
#define SHED(method, Method) \
|
||||
static void method ## Control(uiButton *b, void *data) \
|
||||
{ \
|
||||
uiControl ## Method(uiControl(data)); \
|
||||
}
|
||||
SHED(show, Show)
|
||||
SHED(enable, Enable)
|
||||
SHED(disable, Disable)
|
||||
|
||||
static void echoReadOnlyText(uiEntry *e, void *data)
|
||||
{
|
||||
char *text;
|
||||
|
||||
text = uiEntryText(e);
|
||||
uiEntrySetText(uiEntry(data), text);
|
||||
uiFreeText(text);
|
||||
}
|
||||
|
||||
uiBox *makePage2(void)
|
||||
{
|
||||
uiBox *page2;
|
||||
uiBox *hbox;
|
||||
uiGroup *group;
|
||||
uiBox *vbox;
|
||||
uiButton *button;
|
||||
uiBox *nestedBox;
|
||||
uiBox *innerhbox;
|
||||
uiBox *innerhbox2;
|
||||
uiBox *innerhbox3;
|
||||
uiTab *disabledTab;
|
||||
uiEntry *entry;
|
||||
uiEntry *readonly;
|
||||
uiButton *button2;
|
||||
|
||||
page2 = newVerticalBox();
|
||||
|
||||
group = newGroup("Moving Label");
|
||||
page2group = group;
|
||||
uiBoxAppend(page2, uiControl(group), 0);
|
||||
vbox = newVerticalBox();
|
||||
uiGroupSetChild(group, uiControl(vbox));
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
button = uiNewButton("Move the Label!");
|
||||
uiButtonOnClicked(button, moveLabel, NULL);
|
||||
uiBoxAppend(hbox, uiControl(button), 1);
|
||||
// have a blank label for space
|
||||
uiBoxAppend(hbox, uiControl(uiNewLabel("")), 1);
|
||||
uiBoxAppend(vbox, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
movingBoxes[0] = newVerticalBox();
|
||||
uiBoxAppend(hbox, uiControl(movingBoxes[0]), 1);
|
||||
movingBoxes[1] = newVerticalBox();
|
||||
uiBoxAppend(hbox, uiControl(movingBoxes[1]), 1);
|
||||
uiBoxAppend(vbox, uiControl(hbox), 0);
|
||||
|
||||
movingCurrent = 0;
|
||||
movingLabel = uiNewLabel("This label moves!");
|
||||
uiBoxAppend(movingBoxes[movingCurrent], uiControl(movingLabel), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
button = uiNewButton(moveOutText);
|
||||
uiButtonOnClicked(button, movePage1, NULL);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
uiBoxAppend(page2, uiControl(hbox), 0);
|
||||
moveBack = 0;
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
uiBoxAppend(hbox, uiControl(uiNewLabel("Label Alignment Test")), 0);
|
||||
button = uiNewButton("Open Menued Window");
|
||||
uiButtonOnClicked(button, openAnotherWindow, button);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
button = uiNewButton("Open Menuless Window");
|
||||
uiButtonOnClicked(button, openAnotherWindow, NULL);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
button = uiNewButton("Disabled Menued");
|
||||
uiButtonOnClicked(button, openAnotherDisabledWindow, button);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
button = uiNewButton("Disabled Menuless");
|
||||
uiButtonOnClicked(button, openAnotherDisabledWindow, NULL);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
uiBoxAppend(page2, uiControl(hbox), 0);
|
||||
|
||||
nestedBox = newHorizontalBox();
|
||||
innerhbox = newHorizontalBox();
|
||||
uiBoxAppend(innerhbox, uiControl(uiNewButton("These")), 0);
|
||||
button = uiNewButton("buttons");
|
||||
uiControlDisable(uiControl(button));
|
||||
uiBoxAppend(innerhbox, uiControl(button), 0);
|
||||
uiBoxAppend(nestedBox, uiControl(innerhbox), 0);
|
||||
innerhbox = newHorizontalBox();
|
||||
uiBoxAppend(innerhbox, uiControl(uiNewButton("are")), 0);
|
||||
innerhbox2 = newHorizontalBox();
|
||||
button = uiNewButton("in");
|
||||
uiControlDisable(uiControl(button));
|
||||
uiBoxAppend(innerhbox2, uiControl(button), 0);
|
||||
uiBoxAppend(innerhbox, uiControl(innerhbox2), 0);
|
||||
uiBoxAppend(nestedBox, uiControl(innerhbox), 0);
|
||||
innerhbox = newHorizontalBox();
|
||||
innerhbox2 = newHorizontalBox();
|
||||
uiBoxAppend(innerhbox2, uiControl(uiNewButton("nested")), 0);
|
||||
innerhbox3 = newHorizontalBox();
|
||||
button = uiNewButton("boxes");
|
||||
uiControlDisable(uiControl(button));
|
||||
uiBoxAppend(innerhbox3, uiControl(button), 0);
|
||||
uiBoxAppend(innerhbox2, uiControl(innerhbox3), 0);
|
||||
uiBoxAppend(innerhbox, uiControl(innerhbox2), 0);
|
||||
uiBoxAppend(nestedBox, uiControl(innerhbox), 0);
|
||||
uiBoxAppend(page2, uiControl(nestedBox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
button = uiNewButton("Enable Nested Box");
|
||||
uiButtonOnClicked(button, enableControl, nestedBox);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
button = uiNewButton("Disable Nested Box");
|
||||
uiButtonOnClicked(button, disableControl, nestedBox);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
uiBoxAppend(page2, uiControl(hbox), 0);
|
||||
|
||||
disabledTab = newTab();
|
||||
uiTabAppend(disabledTab, "Disabled", uiControl(uiNewButton("Button")));
|
||||
uiTabAppend(disabledTab, "Tab", uiControl(uiNewLabel("Label")));
|
||||
uiControlDisable(uiControl(disabledTab));
|
||||
uiBoxAppend(page2, uiControl(disabledTab), 1);
|
||||
|
||||
entry = uiNewEntry();
|
||||
readonly = uiNewEntry();
|
||||
uiEntryOnChanged(entry, echoReadOnlyText, readonly);
|
||||
uiEntrySetText(readonly, "If you can see this, uiEntryReadOnly() isn't working properly.");
|
||||
uiEntrySetReadOnly(readonly, 1);
|
||||
if (uiEntryReadOnly(readonly))
|
||||
uiEntrySetText(readonly, "");
|
||||
uiBoxAppend(page2, uiControl(entry), 0);
|
||||
uiBoxAppend(page2, uiControl(readonly), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
button = uiNewButton("Show Button 2");
|
||||
button2 = uiNewButton("Button 2");
|
||||
uiButtonOnClicked(button, showControl, button2);
|
||||
uiControlHide(uiControl(button2));
|
||||
uiBoxAppend(hbox, uiControl(button), 1);
|
||||
uiBoxAppend(hbox, uiControl(button2), 0);
|
||||
uiBoxAppend(page2, uiControl(hbox), 0);
|
||||
|
||||
return page2;
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
// 7 may 2015
|
||||
#include "test.h"
|
||||
|
||||
static uiBox *makeSet(int omit, int hidden, int stretch)
|
||||
{
|
||||
uiBox *hbox;
|
||||
uiButton *buttons[4];
|
||||
|
||||
// don't use newHorizontalBox()
|
||||
// the point of this test is to test hidden controls and padded
|
||||
hbox = (*newhbox)();
|
||||
uiBoxSetPadded(hbox, 1);
|
||||
if (omit != 0) {
|
||||
buttons[0] = uiNewButton("First");
|
||||
uiBoxAppend(hbox, uiControl(buttons[0]), stretch);
|
||||
}
|
||||
if (omit != 1) {
|
||||
buttons[1] = uiNewButton("Second");
|
||||
uiBoxAppend(hbox, uiControl(buttons[1]), stretch);
|
||||
}
|
||||
if (omit != 2) {
|
||||
buttons[2] = uiNewButton("Third");
|
||||
uiBoxAppend(hbox, uiControl(buttons[2]), stretch);
|
||||
}
|
||||
if (omit != 3) {
|
||||
buttons[3] = uiNewButton("Fourth");
|
||||
uiBoxAppend(hbox, uiControl(buttons[3]), stretch);
|
||||
}
|
||||
if (hidden != -1)
|
||||
uiControlHide(uiControl(buttons[hidden]));
|
||||
return hbox;
|
||||
}
|
||||
|
||||
uiBox *makePage3(void)
|
||||
{
|
||||
uiBox *page3;
|
||||
uiBox *hbox;
|
||||
uiBox *hbox2;
|
||||
uiBox *vbox;
|
||||
int hidden;
|
||||
|
||||
page3 = newVerticalBox();
|
||||
|
||||
// first the non-stretchy type
|
||||
for (hidden = 0; hidden < 4; hidden++) {
|
||||
// these two must stay unpadded as well, otherwise the test isn't meaningful
|
||||
hbox2 = (*newhbox)();
|
||||
vbox = (*newvbox)();
|
||||
// reference set
|
||||
hbox = makeSet(hidden, -1, 0);
|
||||
uiBoxAppend(vbox, uiControl(hbox), 0);
|
||||
// real thing
|
||||
hbox = makeSet(-1, hidden, 0);
|
||||
uiBoxAppend(vbox, uiControl(hbox), 0);
|
||||
// pack vbox in
|
||||
uiBoxAppend(hbox2, uiControl(vbox), 0);
|
||||
// and have a button in there for showing right margins
|
||||
uiBoxAppend(hbox2, uiControl(uiNewButton("Right Margin Test")), 1);
|
||||
uiBoxAppend(page3, uiControl(hbox2), 0);
|
||||
}
|
||||
|
||||
// then the stretchy type
|
||||
for (hidden = 0; hidden < 4; hidden++) {
|
||||
hbox = makeSet(-1, hidden, 1);
|
||||
uiBoxAppend(page3, uiControl(hbox), 0);
|
||||
}
|
||||
|
||||
return page3;
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
// 19 may 2015
|
||||
#include "test.h"
|
||||
|
||||
static uiSpinbox *spinbox;
|
||||
static uiSlider *slider;
|
||||
static uiProgressBar *pbar;
|
||||
|
||||
#define CHANGED(what) \
|
||||
static void on ## what ## Changed(ui ## what *this, void *data) \
|
||||
{ \
|
||||
uintmax_t value; \
|
||||
printf("on %s changed\n", #what); \
|
||||
value = ui ## what ## Value(this); \
|
||||
uiSpinboxSetValue(spinbox, value); \
|
||||
uiSliderSetValue(slider, value); \
|
||||
uiProgressBarSetValue(pbar, value); \
|
||||
}
|
||||
CHANGED(Spinbox)
|
||||
CHANGED(Slider)
|
||||
|
||||
#define SETTOO(what, name, n) \
|
||||
static void set ## what ## Too ## name(uiButton *this, void *data) \
|
||||
{ \
|
||||
ui ## what ## SetValue(ui ## what(data), n); \
|
||||
}
|
||||
SETTOO(Spinbox, Low, -80)
|
||||
SETTOO(Spinbox, High, 80)
|
||||
SETTOO(Slider, Low, -80)
|
||||
SETTOO(Slider, High, 80)
|
||||
|
||||
static uiCombobox *cbox;
|
||||
static uiCombobox *editable;
|
||||
static uiRadioButtons *rb;
|
||||
|
||||
static void appendCBRB(uiButton *b, void *data)
|
||||
{
|
||||
uiComboboxAppend(cbox, "New Item");
|
||||
uiComboboxAppend(editable, "New Item");
|
||||
uiRadioButtonsAppend(rb, "New Item");
|
||||
}
|
||||
|
||||
uiBox *makePage4(void)
|
||||
{
|
||||
uiBox *page4;
|
||||
uiBox *hbox;
|
||||
uiSpinbox *xsb;
|
||||
uiButton *b;
|
||||
uiSlider *xsl;
|
||||
|
||||
page4 = newVerticalBox();
|
||||
|
||||
spinbox = uiNewSpinbox(0, 100);
|
||||
uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL);
|
||||
uiBoxAppend(page4, uiControl(spinbox), 0);
|
||||
|
||||
slider = uiNewSlider(0, 100);
|
||||
uiSliderOnChanged(slider, onSliderChanged, NULL);
|
||||
uiBoxAppend(page4, uiControl(slider), 0);
|
||||
|
||||
pbar = uiNewProgressBar();
|
||||
uiBoxAppend(page4, uiControl(pbar), 0);
|
||||
|
||||
uiBoxAppend(page4, uiControl(uiNewHorizontalSeparator()), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
xsb = uiNewSpinbox(-40, 40);
|
||||
uiBoxAppend(hbox, uiControl(xsb), 0);
|
||||
b = uiNewButton("Bad Low");
|
||||
uiButtonOnClicked(b, setSpinboxTooLow, xsb);
|
||||
uiBoxAppend(hbox, uiControl(b), 0);
|
||||
b = uiNewButton("Bad High");
|
||||
uiButtonOnClicked(b, setSpinboxTooHigh, xsb);
|
||||
uiBoxAppend(hbox, uiControl(b), 0);
|
||||
uiBoxAppend(page4, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
xsl = uiNewSlider(-40, 40);
|
||||
uiBoxAppend(hbox, uiControl(xsl), 0);
|
||||
b = uiNewButton("Bad Low");
|
||||
uiButtonOnClicked(b, setSliderTooLow, xsl);
|
||||
uiBoxAppend(hbox, uiControl(b), 0);
|
||||
b = uiNewButton("Bad High");
|
||||
uiButtonOnClicked(b, setSliderTooHigh, xsl);
|
||||
uiBoxAppend(hbox, uiControl(b), 0);
|
||||
uiBoxAppend(page4, uiControl(hbox), 0);
|
||||
|
||||
uiBoxAppend(page4, uiControl(uiNewHorizontalSeparator()), 0);
|
||||
|
||||
cbox = uiNewCombobox();
|
||||
uiComboboxAppend(cbox, "Item 1");
|
||||
uiComboboxAppend(cbox, "Item 2");
|
||||
uiComboboxAppend(cbox, "Item 3");
|
||||
uiBoxAppend(page4, uiControl(cbox), 0);
|
||||
|
||||
editable = uiNewEditableCombobox();
|
||||
uiComboboxAppend(editable, "Editable Item 1");
|
||||
uiComboboxAppend(editable, "Editable Item 2");
|
||||
uiComboboxAppend(editable, "Editable Item 3");
|
||||
uiBoxAppend(page4, uiControl(editable), 0);
|
||||
|
||||
rb = uiNewRadioButtons();
|
||||
uiRadioButtonsAppend(rb, "Item 1");
|
||||
uiRadioButtonsAppend(rb, "Item 2");
|
||||
uiRadioButtonsAppend(rb, "Item 3");
|
||||
uiBoxAppend(page4, uiControl(rb), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
b = uiNewButton("Append");
|
||||
uiButtonOnClicked(b, appendCBRB, NULL);
|
||||
uiBoxAppend(hbox, uiControl(b), 0);
|
||||
uiBoxAppend(page4, uiControl(hbox), 0);
|
||||
|
||||
uiBoxAppend(page4, uiControl(uiNewHorizontalSeparator()), 0);
|
||||
|
||||
uiBoxAppend(page4, uiControl(uiNewDateTimePicker()), 0);
|
||||
uiBoxAppend(page4, uiControl(uiNewDatePicker()), 0);
|
||||
uiBoxAppend(page4, uiControl(uiNewTimePicker()), 0);
|
||||
|
||||
return page4;
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
// 22 may 2015
|
||||
#include "test.h"
|
||||
|
||||
static void openFile(uiButton *b, void *data)
|
||||
{
|
||||
char *fn;
|
||||
|
||||
fn = uiOpenFile();
|
||||
if (fn == NULL)
|
||||
uiLabelSetText(uiLabel(data), "(cancelled)");
|
||||
else {
|
||||
uiLabelSetText(uiLabel(data), fn);
|
||||
uiFreeText(fn);
|
||||
}
|
||||
}
|
||||
|
||||
static void saveFile(uiButton *b, void *data)
|
||||
{
|
||||
char *fn;
|
||||
|
||||
fn = uiSaveFile();
|
||||
if (fn == NULL)
|
||||
uiLabelSetText(uiLabel(data), "(cancelled)");
|
||||
else {
|
||||
uiLabelSetText(uiLabel(data), fn);
|
||||
uiFreeText(fn);
|
||||
}
|
||||
}
|
||||
|
||||
static uiEntry *title, *description;
|
||||
|
||||
static void msgBox(uiButton *b, void *data)
|
||||
{
|
||||
char *t, *d;
|
||||
|
||||
t = uiEntryText(title);
|
||||
d = uiEntryText(description);
|
||||
uiMsgBox(t, d);
|
||||
uiFreeText(d);
|
||||
uiFreeText(t);
|
||||
}
|
||||
|
||||
static void msgBoxError(uiButton *b, void *data)
|
||||
{
|
||||
char *t, *d;
|
||||
|
||||
t = uiEntryText(title);
|
||||
d = uiEntryText(description);
|
||||
uiMsgBoxError(t, d);
|
||||
uiFreeText(d);
|
||||
uiFreeText(t);
|
||||
}
|
||||
|
||||
uiBox *makePage5(void)
|
||||
{
|
||||
uiBox *page5;
|
||||
uiBox *hbox;
|
||||
uiButton *button;
|
||||
uiLabel *label;
|
||||
|
||||
page5 = newVerticalBox();
|
||||
|
||||
#define D(n, f) \
|
||||
hbox = newHorizontalBox(); \
|
||||
button = uiNewButton(n); \
|
||||
label = uiNewLabel(""); \
|
||||
uiButtonOnClicked(button, f, label); \
|
||||
uiBoxAppend(hbox, uiControl(button), 0); \
|
||||
uiBoxAppend(hbox, uiControl(label), 0); \
|
||||
uiBoxAppend(page5, uiControl(hbox), 0);
|
||||
|
||||
D("Open File", openFile);
|
||||
D("Save File", saveFile);
|
||||
|
||||
title = uiNewEntry();
|
||||
uiEntrySetText(title, "Title");
|
||||
description = uiNewEntry();
|
||||
uiEntrySetText(description, "Description");
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
button = uiNewButton("Message Box");
|
||||
uiButtonOnClicked(button, msgBox, NULL);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
uiBoxAppend(hbox, uiControl(title), 0);
|
||||
uiBoxAppend(page5, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
button = uiNewButton("Error Box");
|
||||
uiButtonOnClicked(button, msgBoxError, NULL);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
uiBoxAppend(hbox, uiControl(description), 0);
|
||||
uiBoxAppend(page5, uiControl(hbox), 0);
|
||||
|
||||
return page5;
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
// 22 april 2015
|
||||
#include "test.h"
|
||||
|
||||
struct thing {
|
||||
void *ptr;
|
||||
int type;
|
||||
};
|
||||
|
||||
static struct thing *things = NULL;
|
||||
static uintmax_t len = 0;
|
||||
static uintmax_t cap = 0;
|
||||
|
||||
#define grow 32
|
||||
|
||||
static void *append(void *thing, int type)
|
||||
{
|
||||
if (len >= cap) {
|
||||
cap += grow;
|
||||
things = (struct thing *) realloc(things, cap * sizeof (struct thing));
|
||||
if (things == NULL)
|
||||
die("reallocating things array in test/spaced.c append()");
|
||||
}
|
||||
things[len].ptr = thing;
|
||||
things[len].type = type;
|
||||
len++;
|
||||
return things[len - 1].ptr;
|
||||
}
|
||||
|
||||
enum types {
|
||||
window,
|
||||
box,
|
||||
tab,
|
||||
group,
|
||||
};
|
||||
|
||||
void setSpaced(int spaced)
|
||||
{
|
||||
uintmax_t i;
|
||||
void *p;
|
||||
uintmax_t j, n;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
p = things[i].ptr;
|
||||
switch (things[i].type) {
|
||||
case window:
|
||||
uiWindowSetMargined(uiWindow(p), spaced);
|
||||
break;
|
||||
case box:
|
||||
uiBoxSetPadded(uiBox(p), spaced);
|
||||
break;
|
||||
case tab:
|
||||
n = uiTabNumPages(uiTab(p));
|
||||
for (j = 0; j < n; j++)
|
||||
uiTabSetMargined(uiTab(p), j, spaced);
|
||||
break;
|
||||
case group:
|
||||
uiGroupSetMargined(uiGroup(p), spaced);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void querySpaced(char out[12]) // more than enough
|
||||
{
|
||||
int m = 0;
|
||||
int p = 0;
|
||||
uintmax_t i;
|
||||
void *pp;
|
||||
uintmax_t j, n;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
pp = things[i].ptr;
|
||||
switch (things[i].type) {
|
||||
case window:
|
||||
if (uiWindowMargined(uiWindow(pp)))
|
||||
m++;
|
||||
break;
|
||||
case box:
|
||||
p = uiBoxPadded(uiBox(pp));
|
||||
break;
|
||||
case tab:
|
||||
n = uiTabNumPages(uiTab(pp));
|
||||
for (j = 0; j < n; j++)
|
||||
if (uiTabMargined(uiTab(pp), j))
|
||||
m++;
|
||||
break;
|
||||
case group:
|
||||
if (uiGroupMargined(uiGroup(pp)))
|
||||
m++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
out[0] = 'm';
|
||||
out[1] = ' ';
|
||||
out[2] = '0' + m;
|
||||
out[3] = ' ';
|
||||
out[4] = 'p';
|
||||
out[5] = ' ';
|
||||
out[6] = '0';
|
||||
if (p)
|
||||
out[6] = '1';
|
||||
out[7] = '\0';
|
||||
}
|
||||
|
||||
uiWindow *newWindow(const char *title, int width, int height, int hasMenubar)
|
||||
{
|
||||
uiWindow *w;
|
||||
|
||||
w = uiNewWindow(title, width, height, hasMenubar);
|
||||
append(w, window);
|
||||
return w;
|
||||
}
|
||||
|
||||
uiBox *newHorizontalBox(void)
|
||||
{
|
||||
uiBox *b;
|
||||
|
||||
b = (*newhbox)();
|
||||
append(b, box);
|
||||
return b;
|
||||
}
|
||||
|
||||
uiBox *newVerticalBox(void)
|
||||
{
|
||||
uiBox *b;
|
||||
|
||||
b = (*newvbox)();
|
||||
append(b, box);
|
||||
return b;
|
||||
}
|
||||
|
||||
uiTab *newTab(void)
|
||||
{
|
||||
uiTab *t;
|
||||
|
||||
t = uiNewTab();
|
||||
append(t, tab);
|
||||
return t;
|
||||
}
|
||||
|
||||
uiGroup *newGroup(const char *text)
|
||||
{
|
||||
uiGroup *g;
|
||||
|
||||
g = uiNewGroup(text);
|
||||
append(g, group);
|
||||
return g;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
// 22 april 2015
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include "../out/ui.h"
|
||||
|
||||
// main.c
|
||||
extern void die(const char *, ...);
|
||||
extern uiBox *mainBox;
|
||||
extern uiTab *mainTab;
|
||||
extern uiBox *(*newhbox)(void);
|
||||
extern uiBox *(*newvbox)(void);
|
||||
|
||||
// spaced.c
|
||||
extern void setSpaced(int);
|
||||
extern void querySpaced(char[12]);
|
||||
extern uiWindow *newWindow(const char *title, int width, int height, int hasMenubar);
|
||||
extern uiBox *newHorizontalBox(void);
|
||||
extern uiBox *newVerticalBox(void);
|
||||
extern uiTab *newTab(void);
|
||||
extern uiGroup *newGroup(const char *);
|
||||
|
||||
// menus.c
|
||||
extern uiMenuItem *shouldQuitItem;
|
||||
extern void initMenus(void);
|
||||
|
||||
// page1.c
|
||||
extern uiBox *page1;
|
||||
extern void makePage1(uiWindow *);
|
||||
|
||||
// page2.c
|
||||
extern uiGroup *page2group;
|
||||
extern uiBox *makePage2(void);
|
||||
|
||||
// page3.c
|
||||
extern uiBox *makePage3(void);
|
||||
|
||||
// page4.c
|
||||
extern uiBox *makePage4(void);
|
||||
|
||||
// page5.c
|
||||
extern uiBox *makePage5(void);
|
Loading…
Reference in New Issue