Mercurial > molko
comparison examples/example-ui/button-glower.c @ 507:d49a05e7a5b5
ui: separate delegate/style
Now UI elements do have different styling properties:
- _delegate: functions used to update, draw or perform specific actions on the
UI element.
- _style: basic properties that the delegate should support if possible.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 02 Mar 2023 21:36:43 +0100 |
parents | examples/example-ui/button-style-glow.h@e205625015ba |
children | 7e7c6786d21e |
comparison
equal
deleted
inserted
replaced
506:e205625015ba | 507:d49a05e7a5b5 |
---|---|
1 /* | |
2 * button-style-glow.c -- example of glowing button | |
3 * | |
4 * Copyright (c) 2020-2023 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 #include <assert.h> | |
20 | |
21 #include "button-glower.h" | |
22 | |
23 static void | |
24 update(struct mlk_button_delegate *delegate, struct mlk_button *button, unsigned int ticks) | |
25 { | |
26 (void)button; | |
27 | |
28 struct button_glower *glower = delegate->data; | |
29 | |
30 mlk_glower_update(&glower->glower, ticks); | |
31 glower->style.bg_color = glower->glower.color; | |
32 } | |
33 | |
34 void | |
35 button_glower_init(struct button_glower *glower, struct mlk_button *button) | |
36 { | |
37 assert(glower); | |
38 | |
39 glower->style.bg_color = glower->glower.start; | |
40 glower->delegate.data = glower; | |
41 glower->delegate.update = update; | |
42 | |
43 /* Link this style and delegate to the button. */ | |
44 button->style = &glower->style; | |
45 button->delegate = &glower->delegate; | |
46 | |
47 mlk_glower_init(&glower->glower); | |
48 } |