2015-04-06 11:20:51 -05:00
|
|
|
// 6 april 2015
|
|
|
|
|
|
|
|
#ifndef __UI_UI_H__
|
|
|
|
#define __UI_UI_H__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
typedef struct uiInitOptions uiInitOptions;
|
|
|
|
|
2015-04-09 21:38:11 -05:00
|
|
|
// TODO note that should be initialized to zero
|
|
|
|
struct uiInitOptions {
|
|
|
|
// TODO cbSize
|
|
|
|
|
|
|
|
// If nonzero, allocations will be logged to stderr.
|
|
|
|
// See leaks.awk.
|
|
|
|
int debugLogAllocations;
|
|
|
|
};
|
|
|
|
|
2015-04-10 15:54:06 -05:00
|
|
|
const char *uiInit(uiInitOptions *);
|
|
|
|
void uiFreeInitError(const char *);
|
2015-04-06 11:20:51 -05:00
|
|
|
|
|
|
|
void uiMain(void);
|
|
|
|
void uiQuit(void);
|
|
|
|
|
2015-04-09 01:43:49 -05:00
|
|
|
void uiFreeText(char *);
|
|
|
|
|
2015-04-09 15:37:04 -05:00
|
|
|
typedef struct uiSizing uiSizing;
|
2015-04-09 16:57:08 -05:00
|
|
|
typedef struct uiSizingSys uiSizingSys;
|
2015-04-09 15:37:04 -05:00
|
|
|
struct uiSizing {
|
|
|
|
intmax_t xPadding;
|
|
|
|
intmax_t yPadding;
|
2015-04-09 16:57:08 -05:00
|
|
|
uiSizingSys *sys;
|
2015-04-09 15:37:04 -05:00
|
|
|
};
|
|
|
|
|
2015-04-12 17:34:54 -05:00
|
|
|
typedef strut uiContainer uiContainer;
|
|
|
|
|
2015-04-07 03:02:21 -05:00
|
|
|
typedef struct uiControl uiControl;
|
2015-04-09 15:37:04 -05:00
|
|
|
struct uiControl {
|
|
|
|
void *data; // for use by implementations only
|
|
|
|
void *internal; // for use by ui only
|
|
|
|
void (*destroy)(uiControl *);
|
|
|
|
uintptr_t (*handle)(uiControl *);
|
2015-04-12 17:34:54 -05:00
|
|
|
void (*setParent)(uiControl *, uiContainer *);
|
2015-04-09 15:37:04 -05:00
|
|
|
void (*removeParent)(uiControl *);
|
|
|
|
void (*preferredSize)(uiControl *, uiSizing *, intmax_t *, intmax_t *);
|
|
|
|
void (*resize)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *);
|
2015-04-11 13:12:12 -05:00
|
|
|
int (*visible)(uiControl *);
|
|
|
|
void (*show)(uiControl *);
|
|
|
|
void (*hide)(uiControl *);
|
|
|
|
void (*containerShow)(uiControl *);
|
|
|
|
void (*containerHide)(uiControl *);
|
|
|
|
void (*enable)(uiControl *);
|
|
|
|
void (*disable)(uiControl *);
|
|
|
|
void (*containerEnable)(uiControl *);
|
|
|
|
void (*containerDisable)(uiControl *);
|
2015-04-09 15:37:04 -05:00
|
|
|
};
|
2015-04-07 23:43:35 -05:00
|
|
|
void uiControlDestroy(uiControl *);
|
2015-04-07 03:12:03 -05:00
|
|
|
uintptr_t uiControlHandle(uiControl *);
|
2015-04-12 17:34:54 -05:00
|
|
|
void uiControlSetParent(uiControl *, uiContainer *);
|
2015-04-09 15:37:04 -05:00
|
|
|
void uiControlRemoveParent(uiControl *);
|
|
|
|
void uiControlPreferredSize(uiControl *, uiSizing *, intmax_t *width, intmax_t *height);
|
|
|
|
void uiControlResize(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *);
|
2015-04-11 13:12:12 -05:00
|
|
|
int uiControlVisible(uiControl *);
|
|
|
|
void uiControlShow(uiControl *);
|
|
|
|
void uiControlHide(uiControl *);
|
|
|
|
void uiControlContainerShow(uiControl *);
|
|
|
|
void uiControlContainerHide(uiControl *);
|
|
|
|
void uiControlEnable(uiControl *);
|
|
|
|
void uiControlDisable(uiControl *);
|
|
|
|
void uiControlContainerEnable(uiControl *);
|
|
|
|
void uiControlContainerDisable(uiControl *);
|
2015-04-07 03:02:21 -05:00
|
|
|
|
2015-04-12 17:34:54 -05:00
|
|
|
// uiParent represents an OS control that hosts other OS controls.
|
|
|
|
// It is used internally by package ui and by implementations.
|
|
|
|
// uiWindow, uiTab, and uiGroup all use uiParents to store their controls.
|
|
|
|
struct uiParent {
|
|
|
|
// Internal points to internal data.
|
|
|
|
// Do not access or alter this field.
|
|
|
|
void *Internal;
|
|
|
|
|
|
|
|
// Handle returns the window handle of the uiParent.
|
|
|
|
// On Windows, this is a HWND.
|
|
|
|
// On GTK+, this is a GtkContainer.
|
|
|
|
// On Mac OS X, this is a NSView.
|
|
|
|
uintptr_t (*Handle)(uiParent *p);
|
|
|
|
#define uiParentHandle(p) ((*((p)->Handle))((p)))
|
|
|
|
|
|
|
|
// SetChild sets the uiControl that this uiParent relegates.
|
2015-04-12 18:19:06 -05:00
|
|
|
// It calls uiControl.SetParent() which should, in turn, call uiParent.Update().
|
|
|
|
// The uiParent should already not have a child and the uiControl should already not have a parent.
|
|
|
|
//
|
|
|
|
// child can be NULL, in which case the uiParent has no children.
|
|
|
|
// This form should be called by uiControl.RemoveParent().
|
2015-04-12 17:34:54 -05:00
|
|
|
void (*SetChild)(uiParent *p, uiControl *child);
|
|
|
|
#define uiParentSetChild(p, child) ((*((p)->SetChild))((p), (child)))
|
|
|
|
|
|
|
|
// SetMargins sets the margins of the uiParent to the given margins.
|
2015-04-12 18:19:06 -05:00
|
|
|
// It does not call uiParent.Update(); its caller must.
|
2015-04-12 17:34:54 -05:00
|
|
|
// The units of the margins are backend-defined.
|
|
|
|
// The initial margins are all 0.
|
|
|
|
void (*SetMargins)(uiParent *p, intmax_t left, intmax_t top, intmax_t right, intmax_t bottom);
|
|
|
|
#define uiParentSetMargins(p, left, top, right, bottom) ((*((p)->SetMargins))((p), (left), (top), (right), (bottom)))
|
|
|
|
|
|
|
|
// TODO Resize?
|
|
|
|
|
|
|
|
// Update tells the uiParent to re-layout its children immediately.
|
|
|
|
// It is called when a widget is shown or hidden or when a control is added or removed from a container such as uiStack.
|
|
|
|
void (*Update)(uiParent *p);
|
|
|
|
#define uiParentUpdate(p) ((*((p)->Update))((p)))
|
|
|
|
};
|
|
|
|
uiParent *uiNewParent(uintptr_t);
|
|
|
|
|
2015-04-06 11:20:51 -05:00
|
|
|
typedef struct uiWindow uiWindow;
|
|
|
|
uiWindow *uiNewWindow(char *, int, int);
|
|
|
|
void uiWindowDestroy(uiWindow *);
|
|
|
|
uintptr_t uiWindowHandle(uiWindow *);
|
2015-04-09 01:43:49 -05:00
|
|
|
char *uiWindowTitle(uiWindow *);
|
|
|
|
void uiWindowSetTitle(uiWindow *, const char *);
|
2015-04-06 11:20:51 -05:00
|
|
|
void uiWindowShow(uiWindow *);
|
|
|
|
void uiWindowHide(uiWindow *);
|
|
|
|
void uiWindowOnClosing(uiWindow *, int (*)(uiWindow *, void *), void *);
|
2015-04-07 03:02:21 -05:00
|
|
|
void uiWindowSetChild(uiWindow *, uiControl *);
|
2015-04-09 20:11:56 -05:00
|
|
|
int uiWindowMargined(uiWindow *);
|
2015-04-09 12:42:42 -05:00
|
|
|
void uiWindowSetMargined(uiWindow *, int);
|
2015-04-06 11:20:51 -05:00
|
|
|
|
2015-04-07 03:02:21 -05:00
|
|
|
uiControl *uiNewButton(const char *);
|
2015-04-09 01:43:49 -05:00
|
|
|
char *uiButtonText(uiControl *);
|
|
|
|
void uiButtonSetText(uiControl *, const char *);
|
2015-04-07 03:02:21 -05:00
|
|
|
void uiButtonOnClicked(uiControl *, void (*)(uiControl *, void *), void *);
|
2015-04-07 02:12:34 -05:00
|
|
|
|
2015-04-07 17:53:09 -05:00
|
|
|
uiControl *uiNewHorizontalStack(void);
|
|
|
|
uiControl *uiNewVerticalStack(void);
|
|
|
|
void uiStackAdd(uiControl *, uiControl *, int);
|
2015-04-09 19:04:18 -05:00
|
|
|
int uiStackPadded(uiControl *);
|
2015-04-09 14:59:40 -05:00
|
|
|
void uiStackSetPadded(uiControl *, int);
|
2015-04-07 17:53:09 -05:00
|
|
|
|
2015-04-08 22:22:59 -05:00
|
|
|
uiControl *uiNewEntry(void);
|
2015-04-09 01:43:49 -05:00
|
|
|
char *uiEntryText(uiControl *);
|
|
|
|
void uiEntrySetText(uiControl *, const char *);
|
2015-04-08 22:22:59 -05:00
|
|
|
|
2015-04-09 11:14:18 -05:00
|
|
|
uiControl *uiNewCheckbox(const char *);
|
2015-04-09 11:32:59 -05:00
|
|
|
char *uiCheckboxText(uiControl *);
|
2015-04-09 11:14:18 -05:00
|
|
|
void uiCheckboxSetText(uiControl *, const char *);
|
2015-04-09 11:26:59 -05:00
|
|
|
void uiCheckboxOnToggled(uiControl *, void (*)(uiControl *, void *), void *);
|
2015-04-09 11:52:34 -05:00
|
|
|
int uiCheckboxChecked(uiControl *);
|
2015-04-09 12:01:23 -05:00
|
|
|
void uiCheckboxSetChecked(uiControl *, int);
|
2015-04-09 11:14:18 -05:00
|
|
|
|
2015-04-11 20:53:49 -05:00
|
|
|
uiControl *uiNewLabel(const char *);
|
|
|
|
char *uiLabelText(uiControl *);
|
|
|
|
void uiLabelSetText(uiControl *, const char *);
|
|
|
|
|
2015-04-11 23:30:44 -05:00
|
|
|
uiControl *uiNewTab(void);
|
|
|
|
void uiTabAddPage(uiControl *, const char *, uiControl *);
|
|
|
|
|
2015-04-06 11:20:51 -05:00
|
|
|
#endif
|