GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
include
widgets
gp_widget_style.h
1
//SPDX-License-Identifier: LGPL-2.0-or-later
2
3
/*
4
5
Copyright (c) 2014-2024 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
16
static
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
21
static
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
39
static
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 */
gp_pixel
uint32_t gp_pixel
Pixel integer value.
Definition
gp_types.h:33
gp_text_style
A text style.
Definition
gp_text_style.h:39
gp_widget_render_ctx
Global widget (rendering) context.
Definition
gp_widget_render.h:29
gp_widget_render_ctx::col_disabled
gp_pixel col_disabled
A disabled widget color.
Definition
gp_widget_render.h:65
gp_widget_render_ctx::pixel_type
gp_pixel_type pixel_type
Pixel type used for drawing.
Definition
gp_widget_render.h:100
gp_widget_render_ctx::text_color
gp_pixel text_color
A text color.
Definition
gp_widget_render.h:47
gp_widget_render_ctx::font_bold
gp_text_style * font_bold
Default bold font.
Definition
gp_widget_render.h:89
gp_widget_render_ctx::font
gp_text_style * font
Default font.
Definition
gp_widget_render.h:87
gp_widget_render_ctx::sel_color
gp_pixel sel_color
A selection color.
Definition
gp_widget_render.h:55
gp_widget
A widget base.
Definition
gp_widget.h:28
gp_widget::focused
unsigned int focused
Set if widget is focused.
Definition
gp_widget.h:120
Generated by
1.9.8