|
PatchworkOS
966e257
A non-POSIX operating system.
|
UI Elements. More...
UI Elements.
A window is made up of a tree of elements, each element is responsible for drawing a part of the window and handling events for that part. Elements can have child elements, which are drawn on top of the parent element.
Each element will on creation, copy the current global theme as its own theme, which can then be modified on a per-element basis.
Data Structures | |
| struct | text_props_t |
| Element text properties structure. More... | |
| struct | image_props_t |
| Element image properties structure. More... | |
| struct | element_t |
| Opaque element structure. More... | |
Macros | |
| #define | ELEMENT_NONE 0 |
| #define | ELEMENT_TOGGLE (1 << 0) |
| #define | ELEMENT_FLAT (1 << 1) |
| #define | ELEMENT_NO_BEZEL (1 << 2) |
| #define | ELEMENT_NO_OUTLINE (1 << 3) |
| #define | ELEMENT_ID_NONE UINT64_MAX |
| Element ID indicating no element. | |
Typedefs | |
| typedef uint64_t | element_flags_t |
| Element flags type. | |
| typedef struct element | element_t |
| typedef uint64_t | element_id_t |
| Element identifier type. | |
Functions | |
| element_t * | element_new (element_t *parent, element_id_t id, const rect_t *rect, const char *text, element_flags_t flags, procedure_t procedure, void *private) |
| Allocate and initialize a new element. | |
| void | element_free (element_t *elem) |
| Deinitialize and free an element and all its children. | |
| element_t * | element_find (element_t *elem, element_id_t id) |
| Find a child element by its ID. | |
| void | element_set_private (element_t *elem, void *private) |
| Set private data for an element. | |
| void * | element_get_private (element_t *elem) |
| Get private data for an element. | |
| element_id_t | element_get_id (element_t *elem) |
| Get the ID of an element. | |
| void | element_move (element_t *elem, const rect_t *rect) |
| Move an element to a new rectangle in its parent's coordinate space. | |
| rect_t | element_get_rect (element_t *elem) |
| Get the rectangle of an element in its parent's coordinate space. | |
| rect_t | element_get_content_rect (element_t *elem) |
| Get the element's rectangle in local coordinates. | |
| rect_t | element_get_window_rect (element_t *elem) |
| Get the rectangle of an element in window coordinates. | |
| point_t | element_get_window_point (element_t *elem) |
| Get the top-left point of an element in window coordinates. | |
| rect_t | element_rect_to_window (element_t *elem, const rect_t *src) |
| Convert a rectangle from element coordinates to window coordinates. | |
| point_t | element_point_to_window (element_t *elem, const point_t *src) |
| Convert a point from element coordinates to window coordinates. | |
| rect_t | element_window_to_rect (element_t *elem, const rect_t *src) |
| Convert a rectangle from window coordinates to element coordinates. | |
| point_t | element_window_to_point (element_t *elem, const point_t *src) |
| Convert a point from window coordinates to element coordinates. | |
| element_flags_t | element_get_flags (element_t *elem) |
| Get the flags of an element. | |
| void | element_set_flags (element_t *elem, element_flags_t flags) |
| Set the flags of an element. | |
| const char * | element_get_text (element_t *elem) |
| Get the text of an element. | |
| uint64_t | element_set_text (element_t *elem, const char *text) |
| Set the text of an element. | |
| text_props_t * | element_get_text_props (element_t *elem) |
| Get the text properties of an element. | |
| image_t * | element_get_image (element_t *elem) |
| Get the image of an element. | |
| void | element_set_image (element_t *elem, image_t *image) |
| Set the image of an element. | |
| image_props_t * | element_get_image_props (element_t *elem) |
| Get the image properties of an element. | |
| theme_t * | element_get_theme (element_t *elem) |
| Get the theme of an element. | |
| void | element_draw_begin (element_t *elem, drawable_t *draw) |
| Begin drawing to an element. | |
| void | element_draw_end (element_t *elem, drawable_t *draw) |
| End drawing to an element. | |
| void | element_redraw (element_t *elem, bool shouldPropagate) |
| Redraw an element. | |
| void | element_force_action (element_t *elem, action_type_t action) |
| Force an action on an element. | |
| uint64_t | element_dispatch (element_t *elem, const event_t *event) |
| Dispatch an event to an element. | |
| uint64_t | element_emit (element_t *elem, event_type_t type, const void *data, uint64_t size) |
| Emit an event to an element. | |
| #define ELEMENT_ID_NONE UINT64_MAX |
Element ID indicating no element.
Definition at line 28 of file element_id.h.
Element identifier type.
Used to send events to specific elements and to know which element sent an event, for example to know which button was pressed in a EVENT_LIB_ACTION event.
Definition at line 23 of file element_id.h.
| element_t * element_new | ( | element_t * | parent, |
| element_id_t | id, | ||
| const rect_t * | rect, | ||
| const char * | text, | ||
| element_flags_t | flags, | ||
| procedure_t | procedure, | ||
| void * | private | ||
| ) |
Allocate and initialize a new element.
Will send a fake EVENT_LIB_INIT event to the element after creation, followed by a real EVENT_LIB_REDRAW event.
A event being fake just means its sent by directly calling the element procedure, instead of being pushed to the display's event queue.
| parent | The parent element. |
| id | The element ID. |
| rect | The elements rectangle relative to its parent. |
| text | The elements text, if the element is for example a button, this will be the button label. |
| flags | The element flags. |
| procedure | The element procedure. |
| private | Pointer to private data for the element. |
NULL and errno is set. Definition at line 48 of file element.c.
| void element_free | ( | element_t * | elem | ) |
| element_t * element_find | ( | element_t * | elem, |
| element_id_t | id | ||
| ) |
Find a child element by its ID.
Will search recursively through all child elements.
| elem | The element to search from. |
| id | The element ID to search for. |
NULL if not found. Definition at line 134 of file element.c.
| void element_set_private | ( | element_t * | elem, |
| void * | private | ||
| ) |
| void * element_get_private | ( | element_t * | elem | ) |
| element_id_t element_get_id | ( | element_t * | elem | ) |
Move an element to a new rectangle in its parent's coordinate space.
Will NOT redraw the element, call element_redraw() if needed.
| elem | The element. |
| rect | The new rectangle. |
Definition at line 193 of file element.c.
Get the rectangle of an element in its parent's coordinate space.
Equivalent to RECT_INIT_DIM(x, y, width, height).
| elem | The element. |
elem is NULL. Get the element's rectangle in local coordinates.
Equivalent to RECT_INIT_DIM(0, 0, width, height).
| elem | The element. |
elem is NULL. Definition at line 213 of file element.c.
Get the rectangle of an element in window coordinates.
| elem | The element. |
elem is NULL. Definition at line 223 of file element.c.
Convert a rectangle from element coordinates to window coordinates.
| elem | The element. |
| src | The source rectangle in element coordinates. |
elem or src is NULL. Definition at line 253 of file element.c.
Convert a rectangle from window coordinates to element coordinates.
| elem | The element. |
| src | The source rectangle in window coordinates. |
elem or src is NULL. Definition at line 283 of file element.c.
| element_flags_t element_get_flags | ( | element_t * | elem | ) |
Get the flags of an element.
| elem | The element. |
ELEMENT_NONE if elem is NULL. | void element_set_flags | ( | element_t * | elem, |
| element_flags_t | flags | ||
| ) |
| const char * element_get_text | ( | element_t * | elem | ) |
Get the text of an element.
| elem | The element. |
NULL if elem is NULL. Set the text of an element.
Will NOT redraw the element, call element_redraw() if needed.
| elem | The element. |
| text | The new text. |
0. On failure, ERR and errno is set. Definition at line 343 of file element.c.
| text_props_t * element_get_text_props | ( | element_t * | elem | ) |
Get the image of an element.
| elem | The element. |
NULL if elem is NULL or has no image. Set the image of an element.
Will NOT redraw the element, call element_redraw() if needed.
| elem | The element. |
| image | Pointer to the new image or NULL to remove the image. |
Definition at line 381 of file element.c.
| image_props_t * element_get_image_props | ( | element_t * | elem | ) |
Get the image properties of an element.
The returned pointer can be used to modify the image properties.
| elem | The element. |
NULL if elem is NULL. | void element_draw_begin | ( | element_t * | elem, |
| drawable_t * | draw | ||
| ) |
Begin drawing to an element.
Note that since this will fill the drawable structure with the element's content rectangle, if the element is for example moved or resized the drawable will be invalid.
| elem | The element to draw to. |
| draw | Pointer to the drawable structure to initialize. |
Definition at line 411 of file element.c.
| void element_draw_end | ( | element_t * | elem, |
| drawable_t * | draw | ||
| ) |
End drawing to an element.
This will invalidate the area of the element that was drawn to and send redraw events to any child elements that overlap the invalid area.
| elem | The element that was drawn to. |
| draw | Pointer to the drawable structure that was used for drawing. |
Definition at line 427 of file element.c.
Redraw an element.
Will push a EVENT_LIB_REDRAW event to the display event queue for the element, meaning the redraw event is not processed immediately.
| elem | The element to redraw. |
| shouldPropagate | Whether the redraw event should propagate to child elements. |
Definition at line 450 of file element.c.
| void element_force_action | ( | element_t * | elem, |
| action_type_t | action | ||
| ) |
Force an action on an element.
Will push a EVENT_LIB_FORCE_ACTION event to the display event queue for the element, meaning the action event is not processed immediately.
| elem | The element. |
| action | The action to force. |
Definition at line 463 of file element.c.
Dispatch an event to an element.
This will call the element's procedure with the given event after some preprocessing.
Most events will also be propagated to child elements by the element's procedure.
| elem | The element. |
| event | The event to dispatch. |
Definition at line 476 of file element.c.
| uint64_t element_emit | ( | element_t * | elem, |
| event_type_t | type, | ||
| const void * | data, | ||
| uint64_t | size | ||
| ) |
Emit an event to an element.
This function will construct an event and dispatch it to the element.
| elem | The element. |
| type | The event type. |
| data | Pointer to the event data, can be NULL if size is 0. |
| size | The size of the event data. |
0. On failure, ERR and errno is set. Definition at line 555 of file element.c.