ltkx

GUI toolkit for X11 (WIP)
git clone git://lumidify.org/ltkx.git
Log | Files | Refs | README | LICENSE

commit 8a3b7084765b5ce72d0e55adf283e737a0049e03
parent 38950329b35f33dd3bc8ccbe565cde6512ff2b51
Author: lumidify <nobody@lumidify.org>
Date:   Wed,  4 Jan 2017 09:48:11 +0100

Add even more documentation

Diffstat:
MMakefile | 2+-
Mbutton.h | 2--
Mcommon.c | 126+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Mcommon.h | 143+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Devent.c | 53-----------------------------------------------------
Devent.h | 31-------------------------------
Mgrid.h | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mltk.h | 29+++++++++++++++++++++++++++--
Mtheme.h | 12++++++++++++
Dwidget.c | 116-------------------------------------------------------------------------------
Dwidget.h | 87-------------------------------------------------------------------------------
11 files changed, 358 insertions(+), 311 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,7 +1,7 @@ LIBS = -lX11 -lm -ldl STD = -std=c89 FLAGS = -g -w -Wall -Werror -Wextra -pedantic -CFILES = ltk.c event.c cJSON.c common.c widget.c grid.c window.c theme.c button.c test1.c +CFILES = ltk.c cJSON.c common.c grid.c window.c theme.c button.c test1.c all: test1.c gcc $(STD) $(FLAGS) $(LIBS) $(CFILES) -o test diff --git a/button.h b/button.h @@ -24,8 +24,6 @@ #ifndef _LTK_BUTTON_H_ #define _LTK_BUTTON_H_ -#include "widget.h" - /* * Struct to represent a button widget. */ diff --git a/common.c b/common.c @@ -45,8 +45,6 @@ int ltk_collide_rect(LtkRect rect, int x, int y) return (rect.x <= x && (rect.x + rect.w) >= x && rect.y <= y && (rect.y + rect.h) >= y); } -/* Recursively set all active_widget states to LTK_NORMAL, redraw them, - * and remove the references to them in their parent functions */ void ltk_remove_active_widget(void *widget) { if (!widget) return; @@ -62,7 +60,6 @@ void ltk_remove_active_widget(void *widget) } } -/* Recursively set all active_widget states to state and redraw them */ void ltk_change_active_widget_state(void *widget, LtkWidgetState state) { if (!widget) return; @@ -74,8 +71,6 @@ void ltk_change_active_widget_state(void *widget, LtkWidgetState state) } } -/* Recursively set all hover_widget states to LTK_NORMAL, redraw them, - * and remove the references to them in their parent functions */ void ltk_remove_hover_widget(void *widget) { if (!widget) return; @@ -90,3 +85,124 @@ void ltk_remove_hover_widget(void *widget) parent = child; } } + +LtkWidget ltk_create_widget(LtkWindow *window, void (*draw)(void *), void (*destroy)(void *), int needs_redraw) +{ + LtkWidget widget; + widget.window = window; + widget.active_widget = NULL; + widget.hover_widget = NULL; + widget.parent = NULL; + + widget.key_press = NULL; + widget.key_release = NULL; + widget.mouse_press = NULL; + widget.mouse_release = NULL; + widget.motion_notify = NULL; + + widget.resize = NULL; + widget.draw = draw; + widget.destroy = destroy; + + widget.needs_redraw = needs_redraw; + widget.state = LTK_NORMAL; + widget.row = 0; + widget.rect.x = 0; + widget.rect.y = 0; + widget.rect.w = 100; + widget.rect.h = 100; + + widget.row = NULL; + widget.column = NULL; + widget.row_span = NULL; + widget.column_span = NULL; + widget.sticky = NULL; + + return widget; +} + +void ltk_mouse_press_event(void *widget, XEvent event) +{ + LtkWidget *ptr = widget; + if (!ptr || ptr->state == LTK_DISABLED) return; + if (event.xbutton.button == 1) + { + LtkWidget *parent = ptr->parent; + if (parent) + { + ltk_remove_active_widget(parent); + parent->active_widget = ptr; + } + ptr->state = LTK_PRESSED; + if (ptr->needs_redraw) ptr->draw(ptr); + } + if (ptr->mouse_press) + { + ptr->mouse_press(ptr, event); + } +} + +void ltk_mouse_release_event(void *widget, XEvent event) +{ + LtkWidget *ptr = widget; + if (!ptr || ptr->state == LTK_DISABLED) return; + if (ptr->state == LTK_PRESSED) + { + ptr->state = LTK_HOVERACTIVE; + if (ptr->needs_redraw) ptr->draw(ptr); + } + if (ptr->mouse_release) + { + ptr->mouse_release(ptr, event); + } +} + +void ltk_motion_notify_event(void *widget, XEvent event) +{ + LtkWidget *ptr = widget; + if (ptr && (ptr->state == LTK_NORMAL || ptr->state == LTK_ACTIVE) && + (event.xmotion.state & Button1Mask) != Button1Mask) + { + ptr->state = ptr->state == LTK_ACTIVE ? LTK_HOVERACTIVE : LTK_HOVER; + LtkWidget *parent = ptr->parent; + if (parent) + { + ltk_remove_hover_widget(parent); + parent->hover_widget = ptr; + } + if (ptr->needs_redraw) ptr->draw(ptr); + } + if (ptr->motion_notify) + { + ptr->motion_notify(ptr, event); + } +} + +void ltk_handle_event(XEvent event) +{ + LtkWindow *window; + LtkWidget *root_widget; + HASH_FIND_INT(ltk_global->window_hash, &event.xany.window, window); + if (!window) return; + root_widget = window->root_widget; + switch (event.type) + { + case KeyPress: + break; + case KeyRelease: + break; + case ButtonPress: + if (root_widget) ltk_mouse_press_event(root_widget, event); + break; + case ButtonRelease: + if (root_widget) ltk_mouse_release_event(root_widget, event); + break; + case MotionNotify: + if (root_widget) ltk_motion_notify_event(root_widget, event); + break; + default: + /* FIXME: users should be able to register other events like closing the window */ + if (window->other_event) + window->other_event(window, event); + } +} diff --git a/common.h b/common.h @@ -24,21 +24,8 @@ #ifndef _LTK_COMMON_H_ #define _LTK_COMMON_H_ -typedef void (*LTK_VOID_FUNC)(void *); typedef struct LtkWidget LtkWidget; - -/* - * An enumeration of all widget states. - */ -typedef enum -{ - LTK_NORMAL, - LTK_HOVER, - LTK_PRESSED, - LTK_ACTIVE, - LTK_HOVERACTIVE, - LTK_DISABLED -} LtkWidgetState; +typedef struct LtkWindow LtkWindow; /* * Struct to represent a rectangle. @@ -51,6 +38,79 @@ typedef struct int h; } LtkRect; +typedef enum { + LTK_STICKY_LEFT = 1 << 0, + LTK_STICKY_RIGHT = 1 << 1, + LTK_STICKY_TOP = 1 << 2, + LTK_STICKY_BOTTOM = 1 << 3 +} LtkStickyMask; + +/* + * An enumeration of all widget states. + */ +typedef enum +{ + LTK_NORMAL = 0, + LTK_HOVER = 1, + LTK_PRESSED = 2, + LTK_ACTIVE = 3, + LTK_HOVERACTIVE = 4, + LTK_DISABLED = 5 +} LtkWidgetState; + +/* + * A struct to contain all basic widget information. + * First element of every widget so the widget can + * be cast to LtkWidget. + */ +typedef struct LtkWidget +{ + /* The window the widget will be displayed on */ + LtkWindow *window; + /* For container widgets; the widget that is currently active */ + struct LtkWidget *active_widget; + /* For container widgets; the widget that is currently highlighted */ + struct LtkWidget *hover_widget; + /* Parent widget */ + struct LtkWidget *parent; + + /* Called on KeyPress events */ + void (*key_press)(void *, XEvent event); + /* Called on KeyRelease events */ + void (*key_release)(void *, XEvent event); + /* Called on ButtonPress events */ + void (*mouse_press)(void *, XEvent event); + /* Called on ButtonRelease event */ + void (*mouse_release)(void *, XEvent event); + /* Called on MotionNotify events */ + void (*motion_notify)(void *, XEvent event); + + /* Function to update the widget after its LtkRect has been modified */ + void (*resize)(void *); + /* Function to draw the widget */ + void (*draw)(void *); + /* Function to destroy the widget */ + void (*destroy)(void *); + + /* Position and size of the widget */ + LtkRect rect; + /* Row of widget if gridded */ + unsigned int row; + /* Column of widget if gridded */ + unsigned int column; + /* Row span of widget if gridded */ + unsigned int row_span; + /* Column span of widget if gridded */ + unsigned int column_span; + /* Specifies if the widget needs to be redrawn after a state change */ + int needs_redraw : 1; + /* State of the widget */ + LtkWidgetState state : 3; + /* Similar to sticky in tk */ + unsigned short sticky : 4; +} LtkWidget; + + /* * Check if a rectangle collides with a point. * rect: The rectangle. @@ -65,8 +125,63 @@ int ltk_collide_rect(LtkRect rect, int x, int y); */ char *ltk_read_file(const char *path); +/* + * Recursively set the state of all active_widgets in 'widget' to 'state'. + */ void ltk_change_active_widget_state(void *widget, LtkWidgetState state); + +/* + * Recursively set the state of all active_widgets in 'widget' to LTK_NORMAL, + * redraw the widgets, and remove the references to them from their parents. + */ void ltk_remove_active_widget(void *widget); + +/* + * Recursively set the state of all hover_widgets in 'widget' to LTK_NORMAL or + * LTK_ACTIVE, redraw the widgets, and remove the references to them from their parents. + */ void ltk_remove_hover_widget(void *widget); +/* + * Create a widget. + * window: The window the widget is to be shown on. + * draw: The function used to draw the widget. + * destroy: The function used to destroy the widget. + * needs_redraw: Flag to indicate if the widget needs to be + * be redrawn when it is resized. + * Returns: The new LtkWidget. + */ +LtkWidget ltk_create_widget(LtkWindow *window, void (*draw)(void *), void (*destroy)(void *), int needs_redraw); + +/* + * Handles mouse press events for all widgets and calls + * specific widget handlers if set. + * widget: Pointer to the widget the mouse is currrently on. + * event: The event to be handled. + */ +void ltk_mouse_press_event(void *widget, XEvent event); + +/* + * Handles mouse release events for all widgets and calls + * specific widget handlers if set. + * widget: Pointer to the widget the mouse is currrently on. + * event: The event to be handled. + */ +void ltk_mouse_release_event(void *widget, XEvent event); + +/* + * Handles mouse motion events for all widgets and calls + * specific widget handlers if set. + * widget: Pointer to the widget the mouse is currrently on. + * event: The event to be handled. + */ +void ltk_motion_notify_event(void *widget, XEvent event); + +/* + * Handles all events and dispatches them to their + * respective handlers. + * event: The event to be handled. + */ +void ltk_handle_event(XEvent event); + #endif diff --git a/event.c b/event.c @@ -1,53 +0,0 @@ -/* - * This file is part of the Lumidify ToolKit (LTK) - * Copyright (c) 2016, 2017 Lumidify Productions <lumidify@openmailbox.org> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "ltk.h" - -void ltk_handle_event(XEvent event) -{ - LtkWindow *window; - LtkWidget *root_widget; - HASH_FIND_INT(ltk_global->window_hash, &event.xany.window, window); - if (!window) return; - root_widget = window->root_widget; - switch (event.type) - { - case KeyPress: - break; - case KeyRelease: - break; - case ButtonPress: - if (root_widget) ltk_mouse_press_event(root_widget, event); - break; - case ButtonRelease: - if (root_widget) ltk_mouse_release_event(root_widget, event); - break; - case MotionNotify: - if (root_widget) ltk_motion_notify_event(root_widget, event); - break; - default: - /* FIXME: users should be able to register other events like closing the window */ - if (window->other_event) - window->other_event(window, event); - } -} diff --git a/event.h b/event.h @@ -1,31 +0,0 @@ -/* - * This file is part of the Lumidify ToolKit (LTK) - * Copyright (c) 2016, 2017 Lumidify Productions <lumidify@openmailbox.org> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "ltk.h" - -#ifndef _LTK_EVENT_H_ -#define _LTK_EVENT_H_ - -typedef void (*LTK_EVENT_FUNC)(void *, XEvent); - -#endif diff --git a/grid.h b/grid.h @@ -26,6 +26,9 @@ #include "ltk.h" +/* + * Struct to represent a grid widget. + */ typedef struct LtkGrid { LtkWidget widget; @@ -40,15 +43,80 @@ typedef struct LtkGrid unsigned int *column_pos; } LtkGrid; +/* + * Set the weight of a row in a grid. + * grid: The grid. + * row: The row. + * weight: The weight to set the row to. + */ void ltk_set_row_weight(LtkGrid *grid, int row, int weight); + +/* + * Set the weight of a column in a grid. + * grid: The grid. + * column: The column. + * weight: The weight to set the row to. + */ void ltk_set_column_weight(LtkGrid *grid, int column, int weight); + +/* + * Draw all the widgets in a grid. + * grid: The grid to draw the widgets of. + */ void ltk_draw_grid(LtkGrid *grid); + +/* + * Create a grid. + * window: The window the grid will displayed on. + * rows: The number of rows in the grid. + * columns: The number of columns in the grid. + */ LtkGrid *ltk_create_grid(LtkWindow *window, int rows, int columns); + +/* + * Destroy a grid. + * widget: Pointer to the grid. + */ void ltk_destroy_grid(void *widget); + +/* + * Recalculate the positions and dimensions of the + * columns, rows, and widgets in a grid. + * widget: Pointer to the grid. + */ void ltk_recalculate_grid(void *widget); + +/* + * Grid a widget. + * ptr: Pointer to the widget. + * grid: The grid. + * row: The row to grid the widget in. + * column: The column to grid the widget in. + * rowspan: The amount of rows the widget should span. + * columnspan: The amount of columns the widget should span. + * sticky: Mask of the sticky values (LTK_STICKY_*). + */ void ltk_grid_widget(void *ptr, LtkGrid *grid, int row, int column, int rowspan, int columnspan, unsigned short sticky); + +/* + * Delegate a mouse press event on the grid to the proper widget. + * widget: The grid. + * event: The event to be handled. + */ void ltk_grid_mouse_press(void *widget, XEvent event); + +/* + * Delegate a mouse release event on the grid to the proper widget. + * widget: The grid. + * event: The event to be handled. + */ void ltk_grid_mouse_release(void *widget, XEvent event); + +/* + * Delegate a mouse motion event on the grid to the proper widget. + * widget: The grid. + * event: The event to be handled. + */ void ltk_grid_motion_notify(void *widget, XEvent event); #endif diff --git a/ltk.h b/ltk.h @@ -31,28 +31,53 @@ #include "cJSON.h" #include "uthash.h" #include "common.h" -#include "widget.h" -#include "event.h" #include "window.h" #include "theme.h" #include "grid.h" #include "button.h" +/* + * Struct to contain all global information. + */ typedef struct { + /* The theme used by LTK */ LtkTheme *theme; + /* The connection to the X server */ Display *display; + /* The screen LTK is working on */ int screen; + /* The colormap used by the colors in the theme */ Colormap colormap; + /* A hash table of all windows */ LtkWindow *window_hash; + /* Needed for handling the WM_DELETE_WINDOW signal */ Atom wm_delete_msg; } Ltk; Ltk *ltk_global; +/* + * Initialize LTK. + * theme_path: The path to the theme. + */ void ltk_init(const char *theme_path); + +/* + * Print a message, clean up, and quit. + * msg: The message to print. + */ void ltk_fatal(const char *msg); + +/* + * Create an XColor struct from the hex code of a color. + * hex: The hex code. + */ XColor ltk_create_xcolor(const char *hex); + +/* + * Main event loop. + */ void ltk_mainloop(void); #endif diff --git a/theme.h b/theme.h @@ -27,13 +27,25 @@ typedef struct LtkWindowTheme LtkWindowTheme; typedef struct LtkButtonTheme LtkButtonTheme; +/* + * Struct to contain all styles needed by LTK. + */ typedef struct { LtkWindowTheme *window; LtkButtonTheme *button; } LtkTheme; +/* + * Load a theme from a JSON file. + * path: The path to the file. + */ LtkTheme *ltk_load_theme(const char *path); + +/* + * Destroy an LtkTheme struct. + * theme: Pointer to the struct. + */ void ltk_destroy_theme(LtkTheme *theme); #endif diff --git a/widget.c b/widget.c @@ -1,116 +0,0 @@ -/* - * This file is part of the Lumidify ToolKit (LTK) - * Copyright (c) 2016, 2017 Lumidify Productions <lumidify@openmailbox.org> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "ltk.h" - -LtkWidget ltk_create_widget(LtkWindow *window, void (*draw)(void *), void (*destroy)(void *), int needs_redraw) -{ - LtkWidget widget; - widget.window = window; - widget.active_widget = NULL; - widget.hover_widget = NULL; - widget.parent = NULL; - - widget.key_press = NULL; - widget.key_release = NULL; - widget.mouse_press = NULL; - widget.mouse_release = NULL; - widget.motion_notify = NULL; - - widget.resize = NULL; - widget.draw = draw; - widget.destroy = destroy; - - widget.needs_redraw = needs_redraw; - widget.state = LTK_NORMAL; - widget.row = 0; - widget.rect.x = 0; - widget.rect.y = 0; - widget.rect.w = 100; - widget.rect.h = 100; - - widget.row = NULL; - widget.column = NULL; - widget.row_span = NULL; - widget.column_span = NULL; - widget.sticky = NULL; - - return widget; -} - -void ltk_mouse_press_event(void *widget, XEvent event) -{ - LtkWidget *ptr = widget; - if (!ptr || ptr->state == LTK_DISABLED) return; - if (event.xbutton.button == 1) - { - LtkWidget *parent = ptr->parent; - if (parent) - { - ltk_remove_active_widget(parent); - parent->active_widget = ptr; - } - ptr->state = LTK_PRESSED; - if (ptr->needs_redraw) ptr->draw(ptr); - } - if (ptr->mouse_press) - { - ptr->mouse_press(ptr, event); - } -} - -void ltk_mouse_release_event(void *widget, XEvent event) -{ - LtkWidget *ptr = widget; - if (!ptr || ptr->state == LTK_DISABLED) return; - if (ptr->state == LTK_PRESSED) - { - ptr->state = LTK_HOVERACTIVE; - if (ptr->needs_redraw) ptr->draw(ptr); - } - if (ptr->mouse_release) - { - ptr->mouse_release(ptr, event); - } -} - -void ltk_motion_notify_event(void *widget, XEvent event) -{ - LtkWidget *ptr = widget; - if (ptr && (ptr->state == LTK_NORMAL || ptr->state == LTK_ACTIVE) && - (event.xmotion.state & Button1Mask) != Button1Mask) - { - ptr->state = ptr->state == LTK_ACTIVE ? LTK_HOVERACTIVE : LTK_HOVER; - LtkWidget *parent = ptr->parent; - if (parent) - { - ltk_remove_hover_widget(parent); - parent->hover_widget = ptr; - } - if (ptr->needs_redraw) ptr->draw(ptr); - } - if (ptr->motion_notify) - { - ptr->motion_notify(ptr, event); - } -} diff --git a/widget.h b/widget.h @@ -1,87 +0,0 @@ -/* - * This file is part of the Lumidify ToolKit (LTK) - * Copyright (c) 2016, 2017 Lumidify Productions <lumidify@openmailbox.org> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef _LTK_WIDGET_H_ -#define _LTK_WIDGET_H_ - -#include "event.h" - -typedef enum { - LTK_STICKY_LEFT = 1 << 0, - LTK_STICKY_RIGHT = 1 << 1, - LTK_STICKY_TOP = 1 << 2, - LTK_STICKY_BOTTOM = 1 << 3 -} LtkStickyMask; - -typedef struct LtkWindow LtkWindow; - -typedef struct LtkWidget -{ - /* The window the widget will be displayed on */ - LtkWindow *window; - /* For container widgets; the widget that is currently active */ - struct LtkWidget *active_widget; - /* For container widgets; the widget that is currently highlighted */ - struct LtkWidget *hover_widget; - /* Parent widget */ - struct LtkWidget *parent; - - /* Called on KeyPress events */ - void (*key_press)(void *, XEvent event); - /* Called on KeyRelease events */ - void (*key_release)(void *, XEvent event); - /* Called on ButtonPress events */ - void (*mouse_press)(void *, XEvent event); - /* Called on ButtonRelease event */ - void (*mouse_release)(void *, XEvent event); - /* Called on MotionNotify events */ - void (*motion_notify)(void *, XEvent event); - - /* Function to update the widget after its LtkRect has been modified */ - void (*resize)(void *); - /* Function to draw the widget */ - void (*draw)(void *); - /* Function to destroy the widget */ - void (*destroy)(void *); - - /* Specifies if the widget needs to be redrawn after a state change */ - int needs_redraw; - /* State of the widget */ - LtkWidgetState state; - /* Position and size of the widget */ - LtkRect rect; - /* Row of widget if gridded */ - unsigned int row; - /* Column of widget if gridded */ - unsigned int column; - /* Row span of widget if gridded */ - unsigned int row_span; - /* Column span of widget if gridded */ - unsigned int column_span; - /* Similar to sticky in tk */ - unsigned short sticky; -} LtkWidget; - -LtkWidget ltk_create_widget(LtkWindow *window, void (*draw)(void *), void (*destroy)(void *), int needs_redraw); - -#endif