diff libui/ui/checkbox.h @ 152:1008a796a9e7

ui: make UI widgets usable as actions While here add a example-ui program with move support.
author David Demelier <markand@malikania.fr>
date Thu, 15 Oct 2020 18:09:45 +0200
parents b19d076856d2
children 6992085d47fd
line wrap: on
line diff
--- a/libui/ui/checkbox.h	Thu Oct 15 14:01:24 2020 +0200
+++ b/libui/ui/checkbox.h	Thu Oct 15 18:09:45 2020 +0200
@@ -22,12 +22,16 @@
 /**
  * \file checkbox.h
  * \brief GUI checkbox.
+ * \ingroup ui
  */
 
 #include <stdbool.h>
 
 union event;
 
+struct action;
+struct theme;
+
 /**
  * \brief GUI checkbox.
  */
@@ -71,4 +75,26 @@
 void
 checkbox_draw(const struct checkbox *cb);
 
+/**
+ * Convert the checkbox into an action.
+ *
+ * The following field will be set into the action:
+ *
+ * - act->data: points to cb (reference),
+ * - act->handle: a wrapper to checkbox_handle,
+ * - act->draw: a wrapper to checkbox_draw.
+ *
+ * The checkbox being an UI element is considered to never completes, as such
+ * you will need to handle this case or to use a custom update function.
+ *
+ * \note You will still need to check the checkbox state and reset it at some
+ *       point.
+ * \pre cb != NULL
+ * \pre act != NULL
+ * \param cb the checkbox to reference
+ * \param act the action to fill
+ */
+void
+checkbox_action(struct checkbox *cb, struct action *act);
+
 #endif /* !MOLKO_CHECKBOX_H */