changeset 492:c7b18475f640

ui: gridmenu -> mlk_gridmenu
author David Demelier <markand@malikania.fr>
date Tue, 28 Feb 2023 13:18:23 +0100
parents 734b598534c4
children fce3b3c4b496
files examples/example-gridmenu/example-gridmenu.c libmlk-rpg/mlk/rpg/battle-bar-default.c libmlk-rpg/mlk/rpg/battle-bar-default.h libmlk-ui/mlk/ui/gridmenu.c libmlk-ui/mlk/ui/gridmenu.h
diffstat 5 files changed, 28 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/examples/example-gridmenu/example-gridmenu.c	Tue Feb 28 13:16:47 2023 +0100
+++ b/examples/example-gridmenu/example-gridmenu.c	Tue Feb 28 13:18:23 2023 +0100
@@ -59,14 +59,14 @@
 static void
 handle(struct mlk_state *st, const union mlk_event *ev)
 {
-	struct gridmenu *menu = st->data;
+	struct mlk_gridmenu *menu = st->data;
 
 	switch (ev->type) {
 	case MLK_EVENT_QUIT:
 		mlk_game_quit();
 		break;
 	default:
-		if (gridmenu_handle(st->data, ev))
+		if (mlk_gridmenu_handle(st->data, ev))
 			mlk_tracef("selected index: %zu (%s)", menu->selected, menu->items[menu->selected]);
 		break;
 	}
@@ -77,7 +77,7 @@
 {
 	mlk_painter_set_color(0x4f8fbaff);
 	mlk_painter_clear();
-	gridmenu_draw(st->data);
+	mlk_gridmenu_draw(st->data);
 	mlk_painter_present();
 }
 
@@ -104,15 +104,15 @@
 	    "Double tour"
 	};
 
-	struct gridmenu menu = {0};
+	struct mlk_gridmenu menu = {0};
 	struct mlk_state state = {
 		.data = &menu,
 		.handle = handle,
 		.draw = draw,
 	};
 
-	gridmenu_init(&menu, 3, 2, items, MLK_UTIL_SIZE(items));
-	gridmenu_resize(&menu, 0, 0, 300, 100);
+	mlk_gridmenu_init(&menu, 3, 2, items, MLK_UTIL_SIZE(items));
+	mlk_gridmenu_resize(&menu, 0, 0, 300, 100);
 
 	mlk_align(MLK_ALIGN_CENTER, &menu.x, &menu.y, menu.w, menu.h, 0, 0, mlk_window.w, mlk_window.h);
 
--- a/libmlk-rpg/mlk/rpg/battle-bar-default.c	Tue Feb 28 13:16:47 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/battle-bar-default.c	Tue Feb 28 13:18:23 2023 +0100
@@ -445,7 +445,7 @@
 	/* Go back to main menu if I press escape. */
 	if (ev->key.key == MLK_KEY_ESCAPE)
 		bar->state = BATTLE_BAR_DEFAULT_STATE_MENU;
-	else if (gridmenu_handle(&bar->grid, ev)) {
+	else if (mlk_gridmenu_handle(&bar->grid, ev)) {
 		switch (bar->menu) {
 		case BATTLE_BAR_DEFAULT_MENU_MAGIC:
 			switch_selection_spell(bar, bt);
@@ -542,8 +542,8 @@
 
 	dimensions(geo, bar);
 
-	gridmenu_init(&bar->grid, 2, 2, NULL, 0);
-	gridmenu_resize(&bar->grid, bar->x, geo[0].y, geo[1].w, bar->h);
+	mlk_gridmenu_init(&bar->grid, 2, 2, NULL, 0);
+	mlk_gridmenu_resize(&bar->grid, bar->x, geo[0].y, geo[1].w, bar->h);
 	bar->grid.theme = bar->theme;
 }
 
@@ -668,7 +668,7 @@
 
 	/* Sub menu is only shown if state is set to it. */
 	if (bar->state == BATTLE_BAR_DEFAULT_STATE_GRID)
-		gridmenu_draw(&bar->grid);
+		mlk_gridmenu_draw(&bar->grid);
 }
 
 void
--- a/libmlk-rpg/mlk/rpg/battle-bar-default.h	Tue Feb 28 13:16:47 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/battle-bar-default.h	Tue Feb 28 13:18:23 2023 +0100
@@ -56,7 +56,7 @@
 	/* Private fields. */
 	const char **items;
 	size_t itemsz;
-	struct gridmenu grid;
+	struct mlk_gridmenu grid;
 };
 
 MLK_CORE_BEGIN_DECLS
--- a/libmlk-ui/mlk/ui/gridmenu.c	Tue Feb 28 13:16:47 2023 +0100
+++ b/libmlk-ui/mlk/ui/gridmenu.c	Tue Feb 28 13:18:23 2023 +0100
@@ -40,7 +40,7 @@
 };
 
 static struct index
-get_index(const struct gridmenu *menu)
+get_index(const struct mlk_gridmenu *menu)
 {
 	return (struct index) {
 		.row = menu->selected / menu->ncols,
@@ -49,7 +49,7 @@
 }
 
 static void
-geometry(struct gridmenu *menu)
+geometry(struct mlk_gridmenu *menu)
 {
 	const struct theme *theme = THEME(menu);
 	struct label label = {
@@ -99,7 +99,7 @@
 }
 
 static void
-draw_frame(const struct gridmenu *menu)
+draw_frame(const struct mlk_gridmenu *menu)
 {
 	const struct mlk_frame f = {
 		.x = menu->x,
@@ -113,7 +113,7 @@
 }
 
 static void
-draw_labels(const struct gridmenu *menu)
+draw_labels(const struct mlk_gridmenu *menu)
 {
 	size_t pagesz, pagenr, item, c = 0, r = 0;
 	struct label label = {0};
@@ -154,7 +154,7 @@
 }
 
 static int
-handle_keydown(struct gridmenu *menu, const struct mlk_event_key *key)
+handle_keydown(struct mlk_gridmenu *menu, const struct mlk_event_key *key)
 {
 	assert(key->type == MLK_EVENT_KEYDOWN);
 
@@ -191,7 +191,7 @@
 }
 
 static int
-handle_clickdown(struct gridmenu *menu, const struct mlk_event_click *click)
+handle_clickdown(struct mlk_gridmenu *menu, const struct mlk_event_click *click)
 {
 	assert(click->type == MLK_EVENT_CLICKDOWN);
 
@@ -226,7 +226,7 @@
 }
 
 void
-gridmenu_init(struct gridmenu *menu,
+mlk_gridmenu_init(struct mlk_gridmenu *menu,
               unsigned int nr,
               unsigned int nc,
               const char * const *items,
@@ -245,7 +245,7 @@
 }
 
 void
-gridmenu_resize(struct gridmenu *menu, int x, int y, unsigned int w, unsigned int h)
+mlk_gridmenu_resize(struct mlk_gridmenu *menu, int x, int y, unsigned int w, unsigned int h)
 {
 	assert(menu);
 
@@ -258,7 +258,7 @@
 }
 
 int
-gridmenu_handle(struct gridmenu *menu, const union mlk_event *ev)
+mlk_gridmenu_handle(struct mlk_gridmenu *menu, const union mlk_event *ev)
 {
 	assert(menu);
 	assert(ev);
@@ -278,7 +278,7 @@
 }
 
 void
-gridmenu_draw(const struct gridmenu *menu)
+mlk_gridmenu_draw(const struct mlk_gridmenu *menu)
 {
 	assert(menu);
 
--- a/libmlk-ui/mlk/ui/gridmenu.h	Tue Feb 28 13:16:47 2023 +0100
+++ b/libmlk-ui/mlk/ui/gridmenu.h	Tue Feb 28 13:18:23 2023 +0100
@@ -29,7 +29,8 @@
 
 union mlk_event;
 
-struct gridmenu {
+struct mlk_gridmenu {
+	/* public */
 	int x;
 	int y;
 	unsigned int w;
@@ -41,7 +42,7 @@
 	unsigned int nrows;
 	unsigned int ncols;
 
-	/* Private fields. */
+	/* private */
 	unsigned int eltw;      /* maximum entry label width */
 	unsigned int elth;      /* maximum entry label height */
 	unsigned int spacew;    /* space between element horizontally */
@@ -51,16 +52,16 @@
 MLK_CORE_BEGIN_DECLS
 
 void
-gridmenu_init(struct gridmenu *, unsigned int, unsigned int, const char * const *, size_t);
+mlk_gridmenu_init(struct mlk_gridmenu *, unsigned int, unsigned int, const char * const *, size_t);
 
 void
-gridmenu_resize(struct gridmenu *, int, int, unsigned int, unsigned int);
+mlk_gridmenu_resize(struct mlk_gridmenu *, int, int, unsigned int, unsigned int);
 
 int
-gridmenu_handle(struct gridmenu *, const union mlk_event *);
+mlk_gridmenu_handle(struct mlk_gridmenu *, const union mlk_event *);
 
 void
-gridmenu_draw(const struct gridmenu *);
+mlk_gridmenu_draw(const struct mlk_gridmenu *);
 
 MLK_CORE_END_DECLS