C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
ui_backend.h File Reference

Backend API for terminal UI library. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Include dependency graph for ui_backend.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  UiColor
 Structure representing a color in the UI. More...
struct  UiColorPair
struct  UiConfig
 Structure representing the configuration options for the UI runtime. More...
struct  UiEvent
 Structure representing an input event in the UI. More...
struct  UiRect
 Structure representing a rectangular area in the UI. More...
struct  UiStyle
 Structure representing the style attributes for UI elements. More...

Macros

#define MAXWIN   30

Typedefs

typedef struct UiRuntime UiRuntime
typedef struct UiSurface UiSurface

Enumerations

enum  UiBorderKind { UI_BORDER_NONE = 0 , UI_BORDER_ASCII , UI_BORDER_LIGHT , UI_BORDER_ROUNDED }
 Enumeration of possible border styles for UI surfaces. More...
enum  UiKey {
  UI_KEY_NONE = 0 , UI_KEY_CHAR , UI_KEY_ENTER , UI_KEY_ESCAPE ,
  UI_KEY_BACKSPACE , UI_KEY_TAB , UI_KEY_BTAB , UI_KEY_UP ,
  UI_KEY_DOWN , UI_KEY_LEFT , UI_KEY_RIGHT , UI_KEY_HOME ,
  UI_KEY_END , UI_KEY_PGUP , UI_KEY_PGDN , UI_KEY_INSERT ,
  UI_KEY_DELETE , UI_KEY_RESIZE , UI_KEY_MOUSE , UI_KEY_F1 ,
  UI_KEY_F2 , UI_KEY_F3 , UI_KEY_F4 , UI_KEY_F5 ,
  UI_KEY_F6 , UI_KEY_F7 , UI_KEY_F8 , UI_KEY_F9 ,
  UI_KEY_F10 , UI_KEY_F11 , UI_KEY_F12
}
 Enumeration of possible key events in the UI. More...
enum  UiMouseAction {
  UI_MOUSE_NONE = 0 , UI_MOUSE_PRESS , UI_MOUSE_RELEASE , UI_MOUSE_DRAG ,
  UI_MOUSE_SCROLL_UP , UI_MOUSE_SCROLL_DOWN
}
 Enumeration of possible mouse actions in the UI. More...

Functions

int ui_bkgd_set (UiSurface *, const UiStyle *, const char *)
int ui_bkgrnd (UiSurface *, const UiStyle *, const char *)
int ui_clear_screen (UiRuntime *ui)
 Clear the entire screen.
int ui_cursor_enable (UiRuntime *ui, bool visible)
 Enable or disable the cursor visibility.
int ui_cursor_move (UiSurface *s, int y, int x)
 Move the cursor within a UI surface.
int ui_draw_border (UiSurface *s, UiBorderKind kind, const UiStyle *style)
 Draw a border around a UiSurface.This function draws a border around the UiSurface's window based on the specified UiBorderKind. It uses the ncurses box function to draw the border with the appropriate characters. If a style is provided, it applies that style before drawing the border.
int ui_draw_box_title (UiSurface *s, int x, const UiStyle *style, const char *title)
 Draw a title on the top border of a UiSurface.This function draws the provided title string at the specified x-coordinate on the top border of the UiSurface's window. It uses the ncurses mvwaddstr function to place the title. If a style is provided, it applies that style before drawing the title.
int ui_draw_hline (UiSurface *s, int y, int x, int len, const UiStyle *style)
 Draw a horizontal line on a UiSurface.This function uses the ncurses mvwhline function to draw a horizontal line of a specified length at the given (y, x) coordinates on the UiSurface's window. If a style is provided, it applies that style before drawing the line.
int ui_draw_text (UiSurface *s, int y, int x, const UiStyle *style, const char *text)
 Draw text on a UiSurface at a specified position with a given style.This function uses the ncurses mvwaddstr function to draw the provided text at the specified (y, x) coordinates on the UiSurface's window. If a style is provided, it applies that style before drawing the text.
int ui_draw_text_n (UiSurface *s, int y, int x, const UiStyle *style, const char *text, size_t n)
 Draw a specified number of characters from a string on a UiSurface.This function is similar to ui_draw_text but allows specifying the number of characters to draw from the provided string. It uses the ncurses mvwaddnstr function to achieve this. If a style is provided, it applies that style before drawing the text.
int ui_draw_vline (UiSurface *s, int y, int x, int len, const UiStyle *style)
 Draw a vertical line on a UiSurface.This function uses the ncurses mvwvline function to draw a vertical line of a specified length at the given (y, x) coordinates on the UiSurface's window. If a style is provided, it applies that style before drawing the line.
int ui_get_event (UiRuntime *ui, UiSurface *target, UiEvent *ev, int timeout_ms)
 Retrieves an input event from the specified UI surface.
void ui_get_screen_size (UiRuntime *ui, int *rows, int *cols)
 Get the current screen size.
UiRuntimeui_init (const UiConfig *cfg)
 Initialize NCUrses.
int ui_render (UiRuntime *ui)
 Render the UI by updating panels and refreshing the screen.
int ui_resume (UiRuntime *ui)
 Resume the UI after being suspended, reinitializing the screen.
void ui_shutdown (UiRuntime *ui)
 Shutdown the UI runtime and free its resources.
int ui_surface_clear (UiSurface *s)
 Clear the contents of a UI surface.
void ui_surface_destroy (UiSurface *s)
 Destroy a UI surface and free its resources.
int ui_surface_erase (UiSurface *s)
 Erase the contents of a UI surface.
int ui_surface_hide (UiSurface *s)
 Hide a UI surface.
int ui_surface_move (UiSurface *s, int y, int x)
 Move a UI surface to a new position.
UiSurfaceui_surface_new (UiRuntime *ui, UiSurface *parent, UiRect rect)
 Create a new UI surface.
int ui_surface_resize (UiSurface *s, int rows, int cols)
 Resize a UI surface to new dimensions.
int ui_surface_set_base (UiSurface *s, const UiStyle *style, uint32_t fill_ch)
 Set the base fill character and style for a UiSurface.This function sets the background fill character for the UiSurface's ncurses window and applies the given UiStyle. If fill_ch is 0, it defaults to a space character.
int ui_surface_set_style (UiSurface *s, const UiStyle *style)
 Set the style for a UiSurface.This function applies the given UiStyle to the ncurses window associated with the UiSurface. It uses the ui_ncurses_style_apply function to set the appropriate attributes on the window.
int ui_surface_show (UiSurface *s)
 Show a UI surface.
int ui_suspend (UiRuntime *ui)
 Suspend the UI, restoring the terminal to its normal state.

Variables

UiSurfaceui_surface_box [MAXWIN]
UiSurfaceui_surface_win [MAXWIN]
UiSurfaceui_surface_win2 [MAXWIN]

Detailed Description

Backend API for terminal UI library.

Definition in file ui_backend.h.

Macro Definition Documentation

◆ MAXWIN

#define MAXWIN   30

Definition at line 13 of file ui_backend.h.

Typedef Documentation

◆ UiRuntime

typedef struct UiRuntime UiRuntime

Definition at line 39 of file ui_backend.h.

◆ UiSurface

typedef struct UiSurface UiSurface

Definition at line 49 of file ui_backend.h.

Function Documentation

◆ ui_bkgd_set()

int ui_bkgd_set ( UiSurface * ,
const UiStyle * ,
const char *  )

◆ ui_bkgrnd()

int ui_bkgrnd ( UiSurface * ,
const UiStyle * ,
const char *  )

Definition at line 330 of file ui_ncurses.c.

330 {
331 if (!s)
332 return -1;
333 cchar_t cch = ui_style_to_cch(style, c);
334 wbkgrnd(s->win, &cch);
335 return 0;
336}
cchar_t ui_style_to_cch(const UiStyle *style, const char *c)
Definition ui_ncurses.c:393

References ui_style_to_cch(), and UiSurface::win.

Here is the call graph for this function:

Variable Documentation

◆ ui_surface_box

UiSurface* ui_surface_box[MAXWIN]
extern

Definition at line 26 of file ui_ncurses.c.

◆ ui_surface_win

UiSurface* ui_surface_win[MAXWIN]
extern

Definition at line 27 of file ui_ncurses.c.

◆ ui_surface_win2

UiSurface* ui_surface_win2[MAXWIN]
extern

Definition at line 28 of file ui_ncurses.c.