GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_widget_style.h
1//SPDX-License-Identifier: LGPL-2.0-or-later
2
3/*
4
5 Copyright (c) 2014-2023 Cyril Hrubis <metan@ucw.cz>
6
7 */
8
9/*
10 * Common functions to get widget font and colors based on a widget state e.g. focused/disabled/etc.
11 */
12
13#ifndef WIDGETS_GP_WIDGET_STYLE_H
14#define WIDGETS_GP_WIDGET_STYLE_H
15
16static inline const gp_text_style *gp_widget_focused_font(const gp_widget_render_ctx *ctx, int is_focused)
17{
18 return (is_focused && ctx->focused_is_bold) ? ctx->font_bold : ctx->font;
19}
20
21static inline gp_pixel gp_widget_text_color(gp_widget *self,
22 const gp_widget_render_ctx *ctx,
23 int render_flags)
24{
25 gp_pixel text_color = ctx->text_color;
26
27 switch (gp_pixel_size(ctx->pixel_type)) {
28 case 1:
29 break;
30 default:
31 if (gp_widget_is_disabled(self, render_flags))
32 text_color = ctx->col_disabled;
33 break;
34 }
35
36 return text_color;
37}
38
39static inline gp_pixel gp_widget_frame_color(gp_widget *self,
40 const gp_widget_render_ctx *ctx,
41 int render_flags)
42{
43 gp_pixel frame_color = ctx->text_color;
44
45 (void) render_flags;
46
47 switch (gp_pixel_size(ctx->pixel_type)) {
48 case 1:
49 break;
50 default:
51 if (self->focused)
52 frame_color = ctx->sel_color;
53 break;
54 }
55
56 return frame_color;
57}
58
59#endif /* WIDGETS_GP_WIDGET_STYLE_H */
uint32_t gp_pixel
Pixel integer value.
Definition gp_types.h:33