view libmlk-ui/mlk/ui/label.h @ 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 e205625015ba
children daf085bf8a8c
line wrap: on
line source

/*
 * label.h -- GUI label
 *
 * Copyright (c) 2020-2023 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef MLK_UI_LABEL_H
#define MLK_UI_LABEL_H

#include <mlk/core/core.h>

struct mlk_font;
struct mlk_label;

struct mlk_label_style {
	unsigned long color;
	struct mlk_font *font;
};

struct mlk_label_delegate {
	void *data;
	void (*query)(struct mlk_label_delegate *, const struct mlk_label *, unsigned int *, unsigned *);
	void (*update)(struct mlk_label_delegate *, struct mlk_label *, unsigned int);
	void (*draw)(struct mlk_label_delegate *, const struct mlk_label *);
};

struct mlk_label {
	int x, y;
	const char *text;
	struct mlk_label_style *style;
	struct mlk_label_delegate *delegate;
};

extern struct mlk_label_style mlk_label_style;
extern struct mlk_label_delegate mlk_label_delegate;

MLK_CORE_BEGIN_DECLS

int
mlk_label_ok(const struct mlk_label *);

int
mlk_label_query(const struct mlk_label *, unsigned int *, unsigned int *);

void
mlk_label_update(struct mlk_label *, unsigned int ticks);

void
mlk_label_draw(const struct mlk_label *);

MLK_CORE_END_DECLS

#endif /* !MLK_UI_LABEL_H */