C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
ui_layout.c File Reference

Backend-agnostic layout helpers. More...

#include "ui_layout.h"
#include "ui_backend.h"
#include <string.h>
Include dependency graph for ui_layout.c:

Go to the source code of this file.

Functions

void ui_framed_surface_destroy (UiFramedSurface *fs)
 Destroy a framed surface and release its resources.
UiFramedSurface ui_framed_surface_new (UiSurface *parent, UiRect rect)
 Create a framed surface (outer border + inner content area).

Detailed Description

Backend-agnostic layout helpers.

Implements utility functions that build higher-level layout concepts (framed surfaces, etc.) entirely through the portable UALUI API so they work with any compiled-in backend.

Definition in file ui_layout.c.

Function Documentation

◆ ui_framed_surface_destroy()

void ui_framed_surface_destroy ( UiFramedSurface * fs)

Destroy a framed surface and release its resources.

Destroys a framed surface and releases its resources.

Parameters
fsPointer to the UiFramedSurface to destroy.

Definition at line 54 of file ui_layout.c.

54 {
55 if (!fs)
56 return;
57 /* Destroy inner before outer (child before parent). */
58 if (fs->inner)
60 if (fs->outer)
62 fs->inner = NULL;
63 fs->outer = NULL;
64}
void ui_surface_destroy(UiSurface *s)
Definition ui_ncurses.c:377
UiSurface * inner
Definition ui_layout.h:20
UiSurface * outer
Definition ui_layout.h:19

References UiFramedSurface::inner, UiFramedSurface::outer, and ui_surface_destroy().

Here is the call graph for this function:

◆ ui_framed_surface_new()

UiFramedSurface ui_framed_surface_new ( UiSurface * parent,
UiRect rect )

Create a framed surface (outer border + inner content area).

Creates a new framed surface with the specified parent and rectangle.

The returned UiFramedSurface.outer is the frame panel; .inner is one row and one column smaller on each side (the drawable content area). The caller is responsible for destroying the framed surface with ui_framed_surface_destroy() when it is no longer needed.

Parameters
uiThe UiRuntime context.
parentParent surface, or NULL to make the frame a top-level panel.
rectPosition and size of the outer frame (including the border).
Returns
A UiFramedSurface; both fields are NULL on failure.

Definition at line 26 of file ui_layout.c.

26 {
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) {
45 fs.outer = NULL;
46 }
47
48 return fs;
49}
UiSurface * ui_surface_new(uint w, UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x)
Definition ui_ncurses.c:414
UiRuntime * ui
int cols
Definition ui_backend.h:121
int lines
Definition ui_backend.h:120

References UiRect::cols, UiFramedSurface::inner, UiRect::lines, UiFramedSurface::outer, ui, ui_surface_destroy(), ui_surface_new(), UiRect::x, and UiRect::y.

Here is the call graph for this function: