#include <impl/libui.h>
+/**
+ DRAWING ROUTINES
+**/
+
#define COLOR(c) ((c) | ((c) >> 8))
void SetBackground(UIWin* win, int c)
XftDrawRect(win->xft, &(win->fg), px, py, width, height);
}
-void DrawGlyphs(UIWin* win, XftFont* font, XftGlyphSpec* specs, long nspecs)
+void DrawGlyphs(UIWin* win, UIFont font, XftGlyphSpec* specs, long nspecs)
+{
+ XftDrawGlyphSpec(win->xft, &(win->fg), (XftFont*)font, specs, nspecs);
+}
+
+void DrawString(UIWin* win, UIFont font, int posx, int posy, char* str)
+{
+ XftDrawStringUtf8(win->xft, &(win->fg), (XftFont*)font, posx, posy, (const FcChar8*)str, strlen(str));
+}
+
+/**
+ BASE WIDGET ROUTINES
+**/
+
+Widget* Widget_New(WidgetClass* class)
+{
+ Widget* self = calloc(1, sizeof(Widget));
+ self->class = class;
+ return self;
+}
+
+void Widget_Add(Widget* parent, Widget* child)
+{
+ if (parent)
+ {
+ child->parent = parent;
+ // Add to list here
+ }
+}
+
+
+/**
+ PANEL CODE
+**/
+void Pane_Layout(Widget* pane);
+void Pane_Paint(Widget* pane);
+
+WidgetClass PaneClass = {
+ .onlayout = Pane_Layout,
+ .onpaint = Pane_Paint
+};
+
+Widget* Pane(Widget* parent)
+{
+ Widget* self = Widget_New(&PaneClass);
+ Widget_Add(parent, self);
+ return self;
+}
+
+void Pane_Layout(Widget* pane)
{
- XftDrawGlyphSpec(win->xft, &(win->fg), font, specs, nspecs);
+ // Adjust region here based on layout and widget dimensions
}
-void DrawString(UIWin* win, XftFont* font, int posx, int posy, char* str)
+void Pane_Paint(Widget* pane)
{
- XftDrawStringUtf8(win->xft, &(win->fg), font, posx, posy, (const FcChar8*)str, strlen(str));
+ // Draw the widget here
}
+/**
+ BUTTON CODE
+**/
+void Button_Layout(Widget* pane);
+void Button_Paint(Widget* pane);
+
+WidgetClass ButtonClass = {
+ .onlayout = Button_Layout,
+ .onpaint = Button_Paint
+};
+
+Widget* Button(Widget* parent, char* label)
+{
+ Widget* self = Widget_New(&ButtonClass);
+ Widget_Add(parent, self);
+ return self;
+}
+
+void Button_Layout(Widget* pane)
+{
+ // Adjust region here based on layout and widget dimensions
+}
+
+void Button_Paint(Widget* pane)
+{
+ // Draw the widget here
+}
+
+
+/**
+ APPLICATION CODE
+**/
+
+Widget* initialize(void)
+{
+ Widget* pane = Pane(NULL);
+ Button(pane, "Click Me!");
+ return pane;
+}
void update(UIWin* win)
{
int main(int argc, char** argv)
{
UIWin* win = win_create("UI Test");
+ win->frame = initialize();
win_show(win);
XEvent ev;
return 0;
}
-
-typedef struct WidgetClass WidgetClass;
-typedef struct Widget Widget;
-
-struct WidgetClass {
- void (*onresize)();
- void (*onredraw)();
- void (*onaction)();
-};
-
-struct Widget {
- WidgetClass* class;
- Widget* first;
- Widget* last;
-};
-
-typedef struct UIFont UIFont;
+typedef void* UIFont;
typedef struct UIWin UIWin;
-typedef struct {
- /* keyboard events */
- void (*onkeyup)();
- void (*onkeydown)();
+typedef struct WidgetClass WidgetClass;
+typedef struct Widget Widget;
- /* mouse events */
- void (*onclick)();
- void (*onmousemove)();
-} UIEventHandlers;
+typedef struct { int x,y,w,h; } LayoutRegion;
+
+struct WidgetClass {
+ void (*onlayout)(Widget* self);
+ void (*onpaint)(Widget* self);
+// void (*onaction)(Widget* self);
+};
+
+struct Widget {
+ WidgetClass* class;
+ LayoutRegion dim;
+ int count;
+ Widget* parent;
+ Widget* first_child;
+ Widget* last_child;
+};
UIWin* win_create(char* title);
void win_delete(UIWin* win);
void win_hide(UIWin* win);
void win_repaint(UIWin* win);
-
UIFont font_load(char* patt);
void font_close(UIFont font);
-
-//typedef struct Attr {
-// struct Attr* next;
-// char* name;
-// char* value;
-//} Attr;
-//
-//typedef struct Widget {
-// Attr* attributes;
-// void (*render)(struct Widget* w);
-//} Widget;
-
-//
-//typdef stuct UIWindow {
-// void* model;
-// void (*update)(struct UIWindow*, struct UIEvent*);
-// void (*redraw)(struct UIWindow*);
-//} UIWindow;
\ No newline at end of file