Mercurial > molko
view libmlk-ui/mlk/ui/frame.c @ 504:52a305833381
ui: rework styles
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 01 Mar 2023 14:07:10 +0100 |
parents | 2af25db99273 |
children | 6100c643dba0 |
line wrap: on
line source
/* * frame.h -- GUI frame * * 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. */ #include <assert.h> #include <mlk/core/painter.h> #include "frame.h" #define STYLE_INVOKE(s, f, ...) \ do { \ if (s && s->f) \ s->f(s, __VA_ARGS__); \ else if (mlk_frame_style.f) \ mlk_frame_style.f(s ? s : &mlk_frame_style, __VA_ARGS__); \ } while (0) static void draw(struct mlk_frame_style *style, const struct mlk_frame *frame) { mlk_painter_set_color(style->bg_color); mlk_painter_draw_rectangle(frame->x, frame->y, frame->w, frame->h); } struct mlk_frame_style mlk_frame_style = { .bg_color = 0xad7757ff, .draw = draw }; void mlk_frame_init(struct mlk_frame *frame) { assert(frame); STYLE_INVOKE(frame->style, init, frame); } void mlk_frame_draw(const struct mlk_frame *frame) { assert(frame); STYLE_INVOKE(frame->style, draw, frame); } void mlk_frame_finish(struct mlk_frame *frame) { assert(frame); STYLE_INVOKE(frame->style, finish, frame); }