C-Menu
0.2.9
A User Interface Toolkit
Toggle main menu visibility
Loading...
Searching...
No Matches
ui_layout.c
Go to the documentation of this file.
1
/** @file ui_layout.c
2
@ingroup ui_backend
3
@brief Backend-agnostic layout helpers.
4
5
Implements utility functions that build higher-level layout concepts (framed
6
surfaces, etc.) entirely through the portable UALUI API so they work with
7
any compiled-in backend.
8
*/
9
10
#
include
"ui_layout.h"
11
#
include
"ui_backend.h"
12
#
include
<
string
.
h
>
13
14
/** @brief Create a framed surface (outer border + inner content area).
15
16
The returned UiFramedSurface.outer is the frame panel; .inner is one row
17
and one column smaller on each side (the drawable content area). The
18
caller is responsible for destroying the framed surface with
19
ui_framed_surface_destroy() when it is no longer needed.
20
21
@param ui The UiRuntime context.
22
@param parent Parent surface, or NULL to make the frame a top-level panel.
23
@param rect Position and size of the outer frame (including the border).
24
@return A UiFramedSurface; both fields are NULL on failure.
25
*/
26
UiFramedSurface
ui_framed_surface_new
(UiSurface *parent, UiRect rect) {
27
int
w = 0;
28
UiFramedSurface fs = {NULL, NULL};
29
30
if
(!
ui
|| rect
.
lines
< 3 || rect
.
cols
< 3)
31
return
fs;
32
33
// char title[64] = {0};
34
fs
.
outer
=
ui_surface_new
(
w
,
parent
,
0
,
rect
.
lines
,
rect
.
cols
,
rect
.
y
,
rect
.
x
)
;
35
if
(!fs
.
outer
)
36
return
fs;
37
38
rect
.
y
= 1,
39
rect
.
x
= 1,
40
rect
.
lines
= rect
.
lines
- 2,
41
rect
.
cols
= rect
.
cols
- 2,
42
fs
.
inner
=
ui_surface_new
(
w
,
fs
.
outer
,
0
,
rect
.
lines
,
rect
.
cols
,
rect
.
y
,
rect
.
x
)
;
43
if
(!fs
.
inner
) {
44
ui_surface_destroy
(
fs
.
outer
)
;
45
fs
.
outer
= NULL;
46
}
47
48
return
fs;
49
}
50
51
/** @brief Destroy a framed surface and release its resources.
52
@param fs Pointer to the UiFramedSurface to destroy.
53
*/
54
void
ui_framed_surface_destroy
(UiFramedSurface *fs) {
55
if
(!fs)
56
return
;
57
/* Destroy inner before outer (child before parent). */
58
if
(fs
->
inner
)
59
ui_surface_destroy
(
fs
->
inner
)
;
60
if
(fs
->
outer
)
61
ui_surface_destroy
(
fs
->
outer
)
;
62
fs
->
inner
= NULL;
63
fs
->
outer
= NULL;
64
}
ui_surface_new
UiSurface * ui_surface_new(uint w, UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x)
Definition
ui_ncurses.c:414
ui_surface_destroy
void ui_surface_destroy(UiSurface *s)
Definition
ui_ncurses.c:377
ui
UiRuntime * ui
Definition
ui_notcurses.c:31
ui_framed_surface_new
UiFramedSurface ui_framed_surface_new(UiSurface *parent, UiRect rect)
Creates a new framed surface with the specified parent and rectangle.
Definition
ui_layout.c:26
ui_framed_surface_destroy
void ui_framed_surface_destroy(UiFramedSurface *fs)
Destroys a framed surface and releases its resources.
Definition
ui_layout.c:54
UiRect::y
int y
Definition
ui_backend.h:118
UiRect::x
int x
Definition
ui_backend.h:119
UiRect::cols
int cols
Definition
ui_backend.h:121
UiRect::lines
int lines
Definition
ui_backend.h:120
UiFramedSurface::inner
UiSurface * inner
Definition
ui_layout.h:20
UiFramedSurface::outer
UiSurface * outer
Definition
ui_layout.h:19
ui
ui_layout.c
Generated by
1.17.0