Started a rewrite. Started the test program. Added ui.idl.
This commit is contained in:
parent
662146f46e
commit
bba58dbcb0
|
@ -0,0 +1,70 @@
|
|||
// 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 incr 32
|
||||
|
||||
static void *append(void *thing, int type)
|
||||
{
|
||||
if (len >= cap) {
|
||||
cap += grow;
|
||||
things = (struct thing *) realloc(uiBoxes, 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,
|
||||
};
|
||||
|
||||
void setSpaced(int spaced)
|
||||
{
|
||||
uintmax_t i;
|
||||
void *p;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO newWindow()
|
||||
|
||||
uiBox *newHorizontalBox(void)
|
||||
{
|
||||
uiBox *b;
|
||||
|
||||
b = uiNewHorizontalBox();
|
||||
append(b, box);
|
||||
return b;
|
||||
}
|
||||
|
||||
uiBox *newVerticalBox(void)
|
||||
{
|
||||
uiBox *b;
|
||||
|
||||
b = uiNewVerticalBox();
|
||||
append(b, box);
|
||||
return b;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
// 22 april 2015
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "../ui.h"
|
||||
|
||||
// spaced.c
|
||||
extern void setSpaced(int);
|
||||
extern uiBox *newHorizontalBox(void);
|
||||
extern uiBox *newVerticalBox(void);
|
|
@ -0,0 +1,149 @@
|
|||
// 6 april 2015
|
||||
|
||||
// This is not an IDL file for the conventional RPC or Microsoft IDLs.
|
||||
// Instead, this is for a custom IDL of my own creation.
|
||||
// You can find it at github.com/andlabs/pgidl
|
||||
|
||||
package ui {
|
||||
|
||||
// TODO autogenerate this somehow
|
||||
// TODO alternatively, move AFTER typedefs
|
||||
raw "#ifndef __UI_UI_H__";
|
||||
raw "#define __UI_UI_H__";
|
||||
|
||||
raw "#include <stdint.h>";
|
||||
|
||||
// TODO note that should be initialized to zero
|
||||
struct InitOptions {
|
||||
// TODO cbSize
|
||||
|
||||
// If nonzero, allocations will be logged to stderr.
|
||||
// See leaks.awk.
|
||||
field debugLogAllocations int;
|
||||
};
|
||||
|
||||
func Init(options *InitOptions) *const char;
|
||||
func FreeInitError(err *const char);
|
||||
|
||||
func Main(void);
|
||||
func Quit(void);
|
||||
|
||||
func FreeText(text *char);
|
||||
|
||||
raw "typedef struct uiSizingSys uiSizingSys;";
|
||||
|
||||
struct Sizing {
|
||||
field xPadding intmax_t;
|
||||
field yPadding intmax_t;
|
||||
field sys *uiSizingSys;
|
||||
};
|
||||
|
||||
interface Control {
|
||||
field Internal *void; // for use by ui only
|
||||
func Destroy(void);
|
||||
func Handle(void) uintptr_t;
|
||||
func SetHasParent(hasParent int);
|
||||
func SetOSContainer(c *OSContainer);
|
||||
func PreferredSize(d *Sizing, width *intmax_t, height *intmax_t);
|
||||
func Resize(x intmax_t, y intmax_t, width intmax_t, height intmax_t, d *Sizing);
|
||||
func Visible(void) int;
|
||||
func Show(void);
|
||||
func Hide(void);
|
||||
func ContainerShow(void);
|
||||
func ContainerHide(void);
|
||||
func Enable(void);
|
||||
func Disable(void);
|
||||
func ContainerEnable(void);
|
||||
func ContainerDisable(void);
|
||||
};
|
||||
|
||||
interface OSContainer {
|
||||
field Internal *void;
|
||||
func Destroy(void);
|
||||
func Handle(void) uintptr_t;
|
||||
func SetMainControl(c *Control);
|
||||
func SetMargins(left intmax_t, top intmax_t, right intmax_t, bottom intmax_t);
|
||||
func Update(void);
|
||||
};
|
||||
func NewOSContainer(osParent uintptr_t) *OSContainer;
|
||||
|
||||
interface Window {
|
||||
field Internal *void;
|
||||
func Destroy(void);
|
||||
func Handle(void) uintptr_t;
|
||||
func Title(void) *char;
|
||||
func SetTitle(title *const char);
|
||||
func Show(void);
|
||||
func Hide(void);
|
||||
func OnClosing(f *func(w *Window, data *void) int, data *void);
|
||||
func SetChild(c *Control);
|
||||
func Margined(void) int;
|
||||
func SetMargined(margined int);
|
||||
};
|
||||
func NewWindow(title *const char, width int, height int, hasMenubar int) *Window;
|
||||
|
||||
interface Button from Control {
|
||||
func Text(void) *char;
|
||||
func SetText(text *const char);
|
||||
func OnClicked(f *func(b *Button, data *void), data *void);
|
||||
};
|
||||
func NewButton(text *const char) *Button;
|
||||
|
||||
interface Box from Control {
|
||||
func Append(c *Control, stretchy int);
|
||||
func Delete(index uintmax_t);
|
||||
func Padded(void) int;
|
||||
func SetPadded(padded int);
|
||||
};
|
||||
func NewHorizontalBox(void) *Box;
|
||||
func NewVerticalBox(void) *Box;
|
||||
|
||||
interface Entry from Control {
|
||||
func Text(void) *char;
|
||||
func SetText(text *const char);
|
||||
};
|
||||
func NewEntry(void) *Entry;
|
||||
|
||||
interface Checkbox from Control {
|
||||
func Text(void) *char;
|
||||
func SetText(text *const char);
|
||||
func OnToggled(f *func(c *Checkbox, data *void), data *void);
|
||||
func Checked(void) int;
|
||||
func SetChecked(checked int);
|
||||
};
|
||||
func NewCheckbox(text *const char) *Checkbox;
|
||||
|
||||
interface Label from Control {
|
||||
func Text(void) *char;
|
||||
func SetText(text *const char);
|
||||
};
|
||||
func NewLabel(text *const char) *Label;
|
||||
|
||||
interface Tab from Control {
|
||||
// TODO rename to AppendPage()
|
||||
func AddPage(name *const char, c *Control);
|
||||
func DeletePage(index uintmax_t);
|
||||
};
|
||||
func NewTab(void) *Tab;
|
||||
|
||||
interface Menu {
|
||||
func AddItem(name string) *MenuItem;
|
||||
func AddCheckItem(name string) *MenuItem;
|
||||
func AddQuitItem(void) *MenuItem;
|
||||
func AddPreferencesItem(void) *MenuItem;
|
||||
func AddAboutItem(void) *MenuItem;
|
||||
func AddSeparator(void);
|
||||
};
|
||||
func NewMenu(name string) *Menu;
|
||||
|
||||
interface MenuItem {
|
||||
func Enable(void);
|
||||
func Disable(void);
|
||||
func OnClicked(f *func(sender *void, data *void), data *void);
|
||||
func Checked(void) int;
|
||||
func SetChecked(checked int);
|
||||
};
|
||||
|
||||
raw "#endif";
|
||||
|
||||
};
|
Loading…
Reference in New Issue