changeset 494:35cc5d51bcb2

ui: notify -> mlk_notify
author David Demelier <markand@malikania.fr>
date Tue, 28 Feb 2023 13:32:01 +0100
parents fce3b3c4b496
children 2af25db99273
files examples/example-notify/example-notify.c libmlk-ui/mlk/ui/notify.c libmlk-ui/mlk/ui/notify.h
diffstat 3 files changed, 32 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/examples/example-notify/example-notify.c	Tue Feb 28 13:26:53 2023 +0100
+++ b/examples/example-notify/example-notify.c	Tue Feb 28 13:32:01 2023 +0100
@@ -67,7 +67,7 @@
 		break;
 	case MLK_EVENT_KEYDOWN:
 		if (ev->key.key == MLK_KEY_SPACE)
-			notify(icon, "Quest", "Quest finished.");
+			mlk_notify(icon, "Quest", "Quest finished.");
 		break;
 	default:
 		break;
@@ -79,7 +79,7 @@
 {
 	(void)st;
 
-	notify_update(ticks);
+	mlk_notify_update(ticks);
 }
 
 static void
@@ -90,7 +90,7 @@
 	mlk_painter_set_color(0xffffffff);
 	mlk_painter_clear();
 	mlk_label_draw(&help);
-	notify_draw();
+	mlk_notify_draw();
 	mlk_painter_present();
 }
 
--- a/libmlk-ui/mlk/ui/notify.c	Tue Feb 28 13:26:53 2023 +0100
+++ b/libmlk-ui/mlk/ui/notify.c	Tue Feb 28 13:32:01 2023 +0100
@@ -48,17 +48,17 @@
 	int body_y;
 };
 
-static void draw(const struct notify *, size_t);
+static void draw(const struct mlk_notify *, size_t);
 
-static const struct notify_system default_system = {
+static const struct mlk_notify_system default_system = {
 	.draw = draw
 };
-static const struct notify_system *system = &default_system;
-static struct notify stack[NOTIFY_MAX];
+static const struct mlk_notify_system *system = &default_system;
+static struct mlk_notify stack[MLK_NOTIFY_MAX];
 static size_t stacksz;
 
 static void
-geometry(struct geo *geo, const struct notify *n, size_t index)
+geometry(struct geo *geo, const struct mlk_notify *n, size_t index)
 {
 	int x, y;
 
@@ -113,7 +113,7 @@
 }
 
 static void
-draw_icon(const struct geo *geo, const struct notify *n)
+draw_icon(const struct geo *geo, const struct mlk_notify *n)
 {
 	mlk_texture_draw(n->icon, geo->icon_x, geo->icon_y);
 }
@@ -121,7 +121,7 @@
 #include <stdio.h>
 
 static void
-draw_title(const struct geo *geo, const struct notify *n)
+draw_title(const struct geo *geo, const struct mlk_notify *n)
 {
 	const struct mlk_label l = {
 		.x = geo->title_x,
@@ -134,7 +134,7 @@
 }
 
 static void
-draw_body(const struct geo *geo, const struct notify *n)
+draw_body(const struct geo *geo, const struct mlk_notify *n)
 {
 	const struct mlk_label l = {
 		.x = geo->body_x,
@@ -147,7 +147,7 @@
 }
 
 static void
-draw(const struct notify *n, size_t index)
+draw(const struct mlk_notify *n, size_t index)
 {
 	struct geo geo;
 
@@ -161,17 +161,17 @@
 }
 
 void
-notify(const struct mlk_texture *icon, const char *title, const char *body)
+mlk_notify(const struct mlk_texture *icon, const char *title, const char *body)
 {
 	assert(icon);
 	assert(title);
 	assert(body);
 
-	struct notify *n;
+	struct mlk_notify *n;
 
-	if (stacksz >= NOTIFY_MAX) {
-		memmove(&stack[0], &stack[1], sizeof (stack[0]) - NOTIFY_MAX - 1);
-		n = &stack[NOTIFY_MAX - 1];
+	if (stacksz >= MLK_NOTIFY_MAX) {
+		memmove(&stack[0], &stack[1], sizeof (stack[0]) - MLK_NOTIFY_MAX - 1);
+		n = &stack[MLK_NOTIFY_MAX - 1];
 	} else
 		n = &stack[stacksz++];
 
@@ -182,28 +182,28 @@
 }
 
 void
-notify_update(unsigned int ticks)
+mlk_notify_update(unsigned int ticks)
 {
-	struct notify *n;
+	struct mlk_notify *n;
 
 	for (size_t i = 0; i < stacksz; ++i) {
 		n = &stack[i];
 		n->elapsed += ticks;
 
-		if (n->elapsed >= NOTIFY_TIMEOUT_DEFAULT)
+		if (n->elapsed >= MLK_NOTIFY_TIMEOUT_DEFAULT)
 			memmove(n, n + 1, sizeof (*n) * (--stacksz - i));
 	}
 }
 
 void
-notify_draw(void)
+mlk_notify_draw(void)
 {
 	for (size_t i = 0; i < stacksz; ++i)
 		system->draw(&stack[i], i);
 }
 
 void
-notify_set_system(const struct notify_system *sys)
+mlk_notify_set_system(const struct mlk_notify_system *sys)
 {
 	system = sys ? sys : &default_system;
 }
--- a/libmlk-ui/mlk/ui/notify.h	Tue Feb 28 13:26:53 2023 +0100
+++ b/libmlk-ui/mlk/ui/notify.h	Tue Feb 28 13:32:01 2023 +0100
@@ -23,37 +23,38 @@
 
 #include <mlk/core/core.h>
 
-#define NOTIFY_MAX              (4)
-#define NOTIFY_TIMEOUT_DEFAULT  (5000)
+/* TODO: make this configurable at runtime. */
+#define MLK_NOTIFY_MAX                  (4)
+#define MLK_NOTIFY_TIMEOUT_DEFAULT      (5000)
 
 struct mlk_texture;
 struct theme;
 
-struct notify {
+struct mlk_notify {
 	const struct mlk_texture *icon;
 	const char *title;
 	const char *body;
 	unsigned int elapsed;
 };
 
-struct notify_system {
+struct mlk_notify_system {
 	struct theme *theme;
-	void (*draw)(const struct notify *, size_t);
+	void (*draw)(const struct mlk_notify *, size_t);
 };
 
 MLK_CORE_BEGIN_DECLS
 
 void
-notify(const struct mlk_texture *, const char *, const char *);
+mlk_notify(const struct mlk_texture *, const char *, const char *);
 
 void
-notify_update(unsigned int ticks);
+mlk_notify_update(unsigned int ticks);
 
 void
-notify_draw(void);
+mlk_notify_draw(void);
 
 void
-notify_set_system(const struct notify_system *);
+mlk_notify_set_system(const struct mlk_notify_system *);
 
 MLK_CORE_END_DECLS