]> git.mdlowis.com Git - proto/aos.git/commitdiff
added skeleton code for button and pane widgets humane-interface
authorMike Lowis <mike.lowis@gentex.com>
Thu, 11 Jan 2024 21:27:46 +0000 (16:27 -0500)
committerMike Lowis <mike.lowis@gentex.com>
Thu, 11 Jan 2024 21:27:46 +0000 (16:27 -0500)
bin/uitest/main.c
inc/impl/libui.h
inc/libui.h
lib/ui/font_close.c
lib/ui/font_load.c

index 16cf74168dd2a9b89a9103dcc6471c6167178839..972455a7bbd4dc29889a83e75f9bd5a32617c885 100644 (file)
@@ -4,6 +4,10 @@
 
 #include <impl/libui.h>
 
+/**
+    DRAWING ROUTINES
+**/
+
 #define COLOR(c) ((c) | ((c) >> 8))
 
 void SetBackground(UIWin* win, int c)
@@ -31,17 +35,105 @@ void DrawRectangle(UIWin* win, int px, int py, int width, int height)
     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)
 {
@@ -54,6 +146,7 @@ void update(UIWin* win)
 int main(int argc, char** argv)
 {
     UIWin* win = win_create("UI Test");
+    win->frame = initialize();
     win_show(win);
 
     XEvent ev;
@@ -66,19 +159,3 @@ int main(int argc, char** argv)
     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;
-};
-
index 129766bb7212dd3d563a6cfcc929af153397fcd3..fd6e7c0b743923bd1d29ea5d18dea672cdd9e6e1 100644 (file)
@@ -2,10 +2,6 @@
 #include <X11/Xutil.h>
 #include <X11/Xft/Xft.h>
 
-struct UIFont {
-    XftFont* font;
-};
-
 struct UIWin
 {
     struct UIWin* next;
@@ -16,9 +12,9 @@ struct UIWin
     GC gc;
     XftDraw* xft;
     XftFont* font;
-
     XftColor bg;
     XftColor fg;
+    Widget* frame;
 };
 
 struct XConf
@@ -34,7 +30,3 @@ struct XConf
 };
 
 extern struct XConf X;
-
-enum {
-    WIN_BACKGROUND = 0xEAEAEA
-};
index f4a783bea116d4cfa2aa639e081319224f5d65b9..37c344e8388e7432141964626c10cc8da53d45cb 100644 (file)
@@ -1,15 +1,25 @@
-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);
@@ -17,24 +27,5 @@ void win_show(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
index c812ae875d1e099817a84d341a4cd7b481b8803d..08191f9b091d4c38ef274ecc231fa6cd7708ff7e 100644 (file)
@@ -4,5 +4,5 @@
 
 void font_close(UIFont font)
 {
-    XftFontClose(X.display, font.font);
+    XftFontClose(X.display, (XftFont*)font);
 }
\ No newline at end of file
index 24163efd52ba6996f74a0b9247f0d17384ca14e5..87767f721a93669e73f0e3a3258d604d0b99183e 100644 (file)
@@ -32,5 +32,5 @@ UIFont font_load(char* patt)
         fatal("failed to load font");
     }
 
-    return (UIFont){ .font = font };
+    return font;
 }