changeset 488:441c37e7474f

ui: button -> mlk_button
author David Demelier <markand@malikania.fr>
date Tue, 28 Feb 2023 13:12:05 +0100
parents f2d3c5a97884
children ad6e9970a191
files examples/example-ui/example-ui.c libmlk-ui/mlk/ui/button.c libmlk-ui/mlk/ui/button.h libmlk-ui/mlk/ui/theme.c libmlk-ui/mlk/ui/theme.h
diffstat 5 files changed, 30 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/examples/example-ui/example-ui.c	Tue Feb 28 13:08:58 2023 +0100
+++ b/examples/example-ui/example-ui.c	Tue Feb 28 13:12:05 2023 +0100
@@ -81,7 +81,7 @@
 	} autosave;
 
 	struct {
-		struct button button;
+		struct mlk_button button;
 	} quit;
 } ui = {
 	.panel = {
@@ -163,7 +163,7 @@
 {
 	unsigned int padding = theme_default()->padding;
 	struct frame *f = &ui.panel.frame;
-	struct button *b = &ui.quit.button;
+	struct mlk_button *b = &ui.quit.button;
 
 	/* Button. */
 	b->w = f->w / 4;
@@ -232,7 +232,7 @@
 
 	checkbox_handle(&ui.autosave.cb, ev);
 
-	if (button_handle(&ui.quit.button, ev))
+	if (mlk_button_handle(&ui.quit.button, ev))
 		mlk_game_quit();
 }
 
@@ -247,7 +247,7 @@
 	label_draw(&ui.header.label);
 	checkbox_draw(&ui.autosave.cb);
 	label_draw(&ui.autosave.label);
-	button_draw(&ui.quit.button);
+	mlk_button_draw(&ui.quit.button);
 	mlk_painter_present();
 }
 
--- a/libmlk-ui/mlk/ui/button.c	Tue Feb 28 13:08:58 2023 +0100
+++ b/libmlk-ui/mlk/ui/button.c	Tue Feb 28 13:12:05 2023 +0100
@@ -30,7 +30,7 @@
 #include "theme.h"
 
 static int
-is_boxed(const struct button *button, const struct mlk_event_click *click)
+is_boxed(const struct mlk_button *button, const struct mlk_event_click *click)
 {
 	assert(button);
 	assert(click);
@@ -41,7 +41,7 @@
 }
 
 void
-button_draw_default(const struct theme *t, const struct button *button)
+mlk_button_draw_default(const struct theme *t, const struct mlk_button *button)
 {
 	assert(t);
 	assert(button);
@@ -70,7 +70,7 @@
 }
 
 int
-button_handle(struct button *button, const union mlk_event *ev)
+mlk_button_handle(struct mlk_button *button, const union mlk_event *ev)
 {
 	assert(button);
 	assert(ev);
@@ -78,7 +78,7 @@
 	switch (ev->type) {
 	case MLK_EVENT_CLICKDOWN:
 		if (is_boxed(button, &ev->click))
-			button->state = BUTTON_STATE_PRESSED;
+			button->state = MLK_BUTTON_STATE_PRESSED;
 		break;
 	case MLK_EVENT_CLICKUP:
 		/*
@@ -87,27 +87,27 @@
 		 * outside the button to "forget" the press.
 		 */
 		if (!is_boxed(button, &ev->click))
-			button->state = BUTTON_STATE_NONE;
-		else if (button->state == BUTTON_STATE_PRESSED)
-			button->state = BUTTON_STATE_ACTIVATED;
+			button->state = MLK_BUTTON_STATE_NONE;
+		else if (button->state == MLK_BUTTON_STATE_PRESSED)
+			button->state = MLK_BUTTON_STATE_ACTIVATED;
 		break;
 	default:
 		break;
 	}
 
-	return button->state == BUTTON_STATE_ACTIVATED;
+	return button->state == MLK_BUTTON_STATE_ACTIVATED;
 }
 
 void
-button_reset(struct button *button)
+mlk_button_reset(struct mlk_button *button)
 {
 	assert(button);
 
-	button->state = BUTTON_STATE_NONE;
+	button->state = MLK_BUTTON_STATE_NONE;
 }
 
 void
-button_draw(const struct button *button)
+mlk_button_draw(const struct mlk_button *button)
 {
 	assert(button);
 
--- a/libmlk-ui/mlk/ui/button.h	Tue Feb 28 13:08:58 2023 +0100
+++ b/libmlk-ui/mlk/ui/button.h	Tue Feb 28 13:12:05 2023 +0100
@@ -25,35 +25,35 @@
 
 struct theme;
 
-enum button_state {
-	BUTTON_STATE_NONE,
-	BUTTON_STATE_PRESSED,
-	BUTTON_STATE_ACTIVATED
+enum mlk_button_state {
+	MLK_BUTTON_STATE_NONE,
+	MLK_BUTTON_STATE_PRESSED,
+	MLK_BUTTON_STATE_ACTIVATED
 };
 
-struct button {
+struct mlk_button {
 	int x;
 	int y;
 	unsigned int w;
 	unsigned int h;
 	const char *text;
-	enum button_state state;
+	enum mlk_button_state state;
 	const struct theme *theme;
 };
 
 MLK_CORE_BEGIN_DECLS
 
 int
-button_handle(struct button *, const union mlk_event *);
+mlk_button_handle(struct mlk_button *, const union mlk_event *);
 
 void
-button_reset(struct button *);
+mlk_button_reset(struct mlk_button *);
 
 void
-button_draw_default(const struct theme *, const struct button *);
+mlk_button_draw_default(const struct theme *, const struct mlk_button *);
 
 void
-button_draw(const struct button *);
+mlk_button_draw(const struct mlk_button *);
 
 MLK_CORE_END_DECLS
 
--- a/libmlk-ui/mlk/ui/theme.c	Tue Feb 28 13:08:58 2023 +0100
+++ b/libmlk-ui/mlk/ui/theme.c	Tue Feb 28 13:12:05 2023 +0100
@@ -55,7 +55,7 @@
 	.padding = 10,
 	.draw_frame = frame_draw_default,
 	.draw_label = label_draw_default,
-	.draw_button = button_draw_default,
+	.draw_button = mlk_button_draw_default,
 	.draw_checkbox = checkbox_draw_default
 };
 
@@ -130,7 +130,7 @@
 }
 
 void
-theme_draw_button(const struct theme *t, const struct button *button)
+theme_draw_button(const struct theme *t, const struct mlk_button *button)
 {
 	assert(button);
 
--- a/libmlk-ui/mlk/ui/theme.h	Tue Feb 28 13:08:58 2023 +0100
+++ b/libmlk-ui/mlk/ui/theme.h	Tue Feb 28 13:12:05 2023 +0100
@@ -21,7 +21,7 @@
 
 #include <mlk/core/core.h>
 
-struct button;
+struct mlk_button;
 struct checkbox;
 struct mlk_font;
 struct frame;
@@ -56,7 +56,7 @@
 
 	void (*draw_frame)(const struct theme *, const struct frame *);
 	void (*draw_label)(const struct theme *, const struct label *);
-	void (*draw_button)(const struct theme *, const struct button *);
+	void (*draw_button)(const struct theme *, const struct mlk_button *);
 	void (*draw_checkbox)(const struct theme *t, const struct checkbox *);
 };
 
@@ -78,7 +78,7 @@
 theme_draw_label(const struct theme *, const struct label *);
 
 void
-theme_draw_button(const struct theme *, const struct button *);
+theme_draw_button(const struct theme *, const struct mlk_button *);
 
 void
 theme_draw_checkbox(const struct theme *, const struct checkbox *);