comparison libmlk-ui/ui/button.h @ 243:71b3b7036de7

misc: lot of cleanups, - prefix libraries with libmlk, - move assets from source directories closes #2520, - prefix header guards closes #2519
author David Demelier <markand@malikania.fr>
date Sat, 28 Nov 2020 22:37:30 +0100
parents libui/ui/button.h@6992085d47fd
children 08ab73b32832
comparison
equal deleted inserted replaced
242:4c24604efcab 243:71b3b7036de7
1 /*
2 * button.h -- GUI button
3 *
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #ifndef MOLKO_UI_BUTTON_H
20 #define MOLKO_UI_BUTTON_H
21
22 /**
23 * \file button.h
24 * \brief GUI button.
25 * \ingroup ui
26 */
27
28 union event;
29
30 struct action;
31 struct theme;
32
33 /**
34 * \brief Button state.
35 */
36 enum button_state {
37 BUTTON_STATE_NONE, /*!< Button is inactive. */
38 BUTTON_STATE_PRESSED, /*!< Button is currently pressed. */
39 BUTTON_STATE_ACTIVATED /*!< Button is considered activated. */
40 };
41
42 /**
43 * \brief GUI button.
44 */
45 struct button {
46 int x; /*!< (+) Position in x. */
47 int y; /*!< (+) Position in y. */
48 unsigned int w; /*!< (+) Width. */
49 unsigned int h; /*!< (+) Height. */
50 const char *text; /*!< (+&) Text to draw. */
51 enum button_state state; /*!< (+) Button state. */
52 const struct theme *theme; /*!< (+&?) Theme to use. */
53 };
54
55 /**
56 * Handle the event.
57 *
58 * You should always call this function even if the event is completely
59 * unrelated.
60 *
61 * \pre button != NULL
62 * \pre ev != NULL
63 * \param button the button
64 * \param ev the event
65 */
66 void
67 button_handle(struct button *button, const union event *ev);
68
69 /**
70 * Use this function once the button has been considered activated.
71 *
72 * \pre button != NULL
73 * \param button the button
74 */
75 void
76 button_reset(struct button *button);
77
78 /**
79 * Default drawing function.
80 *
81 * \pre t != NULL
82 * \pre frame != NULL
83 * \param t the theme
84 * \param button the button
85 */
86 void
87 button_draw_default(const struct theme *t, const struct button *button);
88
89 /**
90 * Draw the button.
91 *
92 * \pre button != NULL
93 * \param button the button
94 */
95 void
96 button_draw(const struct button *button);
97
98 /**
99 * Convert the button into an action.
100 *
101 * The following field will be set into the action:
102 *
103 * - act->data: points to button (reference),
104 * - act->handle: a wrapper to button_handle,
105 * - act->draw: a wrapper to button_draw.
106 *
107 * The button being an UI element is considered to never completes, as such
108 * you will need to handle this case or to use a custom update function.
109 *
110 * \note You will still need to check the button state and reset it at some
111 * point.
112 * \pre button != NULL
113 * \pre act != NULL
114 * \param button the button to reference
115 * \param act the action to fill
116 */
117 void
118 button_action(struct button *button, struct action *act);
119
120 #endif /* !MOLKO_UI_BUTTON_H */