|
C-Menu 0.2.9
A User Interface Toolkit
|
UI implementation using the ncurses library. More...
Files | |
| file | ui_ncurses.c |
| Ncurses-based UI implementation. | |
| file | ui_ncurses_draw.c |
| Implementation of drawing functions for the ncurses UI backend. | |
| file | ui_ncurses_input.c |
| Input handling for ncurses-based UI. | |
Functions | |
| 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. | |
| UiRuntime * | ui_init (const UiConfig *cfg) |
| Initialize NCUrses. | |
| int | ui_ncurses_color_pair_from_style (const UiStyle *style) |
| Convert an RGB value (0-255) to a 1000-based value for ncurses.Ncurses uses a 1000-based color system, so we need to convert our 0-255 RGB values to that scale. | |
| int | ui_ncurses_style_apply (WINDOW *win, const UiStyle *style) |
| Apply a UiStyle to an ncurses window.This function sets the appropriate attributes (bold, underline, reverse) on the given ncurses window based on the properties of the UiStyle. | |
| 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. | |
| UiSurface * | ui_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. | |
UI implementation using the ncurses library.
This module provides functions for creating and managing UI surfaces, handling input, and rendering the UI using ncurses. It is designed to be used as part of a larger UI framework and can be extended with additional features as needed.
| int ui_clear_screen | ( | UiRuntime * | ui | ) |
Clear the entire screen.
| ui | The UiRuntime instance. |
Definition at line 284 of file ui_ncurses.c.
| int ui_cursor_enable | ( | UiRuntime * | ui, |
| bool | visible ) |
Enable or disable the cursor visibility.
| ui | The UiRuntime instance. |
| visible | true to show the cursor, false to hide it. |
Definition at line 322 of file ui_ncurses.c.
References UiRuntime::cursor_visible.
| int ui_cursor_move | ( | UiSurface * | s, |
| int | y, | ||
| int | x ) |
Move the cursor within a UI surface.
| s | The UiSurface to move the cursor in. |
| y | The new y-coordinate of the cursor. |
| x | The new x-coordinate of the cursor. |
Definition at line 170 of file ui_ncurses.c.
References UiSurface::win.
| 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.
| s | The UiSurface on which to draw the border. |
| kind | The kind of border to draw (e.g., none, ASCII, light, rounded). |
| style | The UiStyle to apply to the border (can be NULL for default). |
Definition at line 194 of file ui_ncurses_draw.c.
References UI_BORDER_ASCII, UI_BORDER_LIGHT, UI_BORDER_NONE, UI_BORDER_ROUNDED, ui_ncurses_style_apply(), and UiSurface::win.
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.
| s | The UiSurface on which to draw the box title. |
| x | The x-coordinate (column) where the title should start. |
| style | The UiStyle to apply to the title (can be NULL for default). |
| title | The null-terminated string to use as the box title. |
Definition at line 226 of file ui_ncurses_draw.c.
References ui_ncurses_style_apply(), and UiSurface::win.
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.
| s | The UiSurface on which to draw the horizontal line. |
| y | The y-coordinate (row) where the line should be drawn. |
| x | The x-coordinate (column) where the line should start. |
| len | The length of the horizontal line to draw. |
| style | The UiStyle to apply to the line (can be NULL for default). |
Definition at line 153 of file ui_ncurses_draw.c.
References ui_ncurses_style_apply(), and UiSurface::win.
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.
| s | The UiSurface on which to draw the text. |
| y | The y-coordinate (row) where the text should be drawn. |
| x | The x-coordinate (column) where the text should be drawn. |
| style | The UiStyle to apply to the text (can be NULL for default). |
| text | The null-terminated string to draw. |
Definition at line 109 of file ui_ncurses_draw.c.
References ui_ncurses_style_apply(), and UiSurface::win.
| 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.
| s | The UiSurface on which to draw the text. |
| y | The y-coordinate (row) where the text should be drawn. |
| x | The x-coordinate (column) where the text should be drawn. |
| style | The UiStyle to apply to the text (can be NULL for default). |
| text | The string from which to draw characters (not necessarily null-terminated). |
| n | The number of characters to draw from the string. |
Definition at line 132 of file ui_ncurses_draw.c.
References ui_ncurses_style_apply(), and UiSurface::win.
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.
| s | The UiSurface on which to draw the vertical line. |
| y | The y-coordinate (row) where the line should start. |
| x | The x-coordinate (column) where the line should be drawn. |
| len | The length of the vertical line to draw. |
| style | The UiStyle to apply to the line (can be NULL for default). |
Definition at line 174 of file ui_ncurses_draw.c.
References ui_ncurses_style_apply(), and UiSurface::win.
Retrieves an input event from the specified UI surface.
This function waits for an input event on the given UI surface (or the standard screen if no surface is specified) and fills the provided UiEvent structure with the details of the event. It handles both keyboard and mouse events.
| ui | The UI runtime context (unused in this implementation). |
| target | The UI surface to monitor for events, or NULL to use stdscr. |
| ev | A pointer to a UiEvent structure to be filled with event details. |
| timeout_ms | The maximum time to wait for an event in milliseconds, or -1 to wait indefinitely. |
Definition at line 108 of file ui_ncurses_input.c.
References UiEvent::ch, UiEvent::key, UiEvent::mouse_action, UI_KEY_CHAR, UI_KEY_MOUSE, UI_MOUSE_PRESS, UI_MOUSE_RELEASE, UI_MOUSE_SCROLL_DOWN, UI_MOUSE_SCROLL_UP, UiSurface::win, UiEvent::x, and UiEvent::y.
| void ui_get_screen_size | ( | UiRuntime * | ui, |
| int * | rows, | ||
| int * | cols ) |
Get the current screen size.
| ui | The UiRuntime instance. |
| rows | Output parameter for the number of rows. |
| cols | Output parameter for the number of columns. |
Definition at line 257 of file ui_ncurses.c.
References UiRuntime::cols, and UiRuntime::rows.
Referenced by bare_box_new().
Initialize NCUrses.
| cfg | The UI runtime instance. |
Definition at line 180 of file ui_ncurses.c.
References UiRuntime::alt_screen, UiRuntime::cols, UiConfig::cursor_visible, UiRuntime::cursor_visible, UiConfig::enable_alt_screen, UiConfig::enable_mouse, f_curses_open, UiRuntime::mouse_enabled, Perror(), UiRuntime::rows, screen, tty_fp, ui_shutdown(), and win_ptr.
| int ui_ncurses_color_pair_from_style | ( | const UiStyle * | style | ) |
Convert an RGB value (0-255) to a 1000-based value for ncurses.Ncurses uses a 1000-based color system, so we need to convert our 0-255 RGB values to that scale.
| v | The RGB value (0-255). |
Convert a UiStyle to an ncurses color pair index.
This function maps the foreground and background colors from a UiStyle to an ncurses color pair index. For simplicity, this example assumes a limited set of colors and does not handle all possible combinations.
| style | The UiStyle containing the foreground and background colors. |
Definition at line 32 of file ui_ncurses_draw.c.
| int ui_ncurses_style_apply | ( | WINDOW * | win, |
| const UiStyle * | style ) |
Apply a UiStyle to an ncurses window.This function sets the appropriate attributes (bold, underline, reverse) on the given ncurses window based on the properties of the UiStyle.
| win | The ncurses window to which the style should be applied. |
| style | The UiStyle containing the attributes to apply. |
Definition at line 45 of file ui_ncurses_draw.c.
References UiStyle::blink, UiStyle::bold, UiStyle::dim, UiStyle::invis, UiStyle::italic, UiStyle::reverse, and UiStyle::underline.
Referenced by ui_draw_border(), ui_draw_box_title(), ui_draw_hline(), ui_draw_text(), ui_draw_text_n(), ui_draw_vline(), ui_surface_set_base(), and ui_surface_set_style().
| int ui_render | ( | UiRuntime * | ui | ) |
Render the UI by updating panels and refreshing the screen.
| ui | The UiRuntime instance. |
Definition at line 272 of file ui_ncurses.c.
| int ui_resume | ( | UiRuntime * | ui | ) |
Resume the UI after being suspended, reinitializing the screen.
| ui | The UiRuntime instance. |
Definition at line 307 of file ui_ncurses.c.
| void ui_shutdown | ( | UiRuntime * | ui | ) |
Shutdown the UI runtime and free its resources.
| ui | The UiRuntime instance to shutdown. |
Definition at line 240 of file ui_ncurses.c.
References f_curses_open, screen, and tty_fp.
Referenced by ui_init().
| int ui_surface_clear | ( | UiSurface * | s | ) |
Clear the contents of a UI surface.
| s | The UiSurface to clear. |
Definition at line 119 of file ui_ncurses.c.
References UiSurface::win.
| void ui_surface_destroy | ( | UiSurface * | s | ) |
Destroy a UI surface and free its resources.
| s | The UiSurface to destroy. |
Definition at line 74 of file ui_ncurses.c.
References UiSurface::pan, and UiSurface::win.
| int ui_surface_erase | ( | UiSurface * | s | ) |
Erase the contents of a UI surface.
| s | The UiSurface to erase. |
Definition at line 131 of file ui_ncurses.c.
References UiSurface::win.
| int ui_surface_hide | ( | UiSurface * | s | ) |
Hide a UI surface.
| s | The UiSurface to hide. |
Definition at line 155 of file ui_ncurses.c.
References UiSurface::hidden, and UiSurface::pan.
| int ui_surface_move | ( | UiSurface * | s, |
| int | y, | ||
| int | x ) |
Move a UI surface to a new position.
| s | The UiSurface to move. |
| y | The new y-coordinate of the surface. |
| x | The new x-coordinate of the surface. |
Definition at line 91 of file ui_ncurses.c.
References UiSurface::pan, UiSurface::x, and UiSurface::y.
Create a new UI surface.
*
| ui | The UI runtime instance. |
| parent | The parent surface, or NULL for a top-level surface. |
| rect | The rectangle defining the position and size of the surface. |
Definition at line 37 of file ui_ncurses.c.
References UiRect::cols, UiSurface::cols, UiSurface::pan, UiSurface::parent, UiRect::rows, UiSurface::rows, UiSurface::runtime, UiSurface::win, UiRect::x, UiSurface::x, UiRect::y, and UiSurface::y.
| int ui_surface_resize | ( | UiSurface * | s, |
| int | rows, | ||
| int | cols ) |
Resize a UI surface to new dimensions.
| s | The UiSurface to resize. |
| rows | The new number of rows for the surface. |
| cols | The new number of columns for the surface. |
Definition at line 106 of file ui_ncurses.c.
References UiSurface::cols, UiSurface::rows, and UiSurface::win.
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.
| s | The UiSurface to set the base for. |
| style | The UiStyle to apply to the surface. |
| fill_ch | The character to use for filling the background (0 for space). |
Definition at line 88 of file ui_ncurses_draw.c.
References ui_ncurses_style_apply(), and UiSurface::win.
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.
Definition at line 72 of file ui_ncurses_draw.c.
References ui_ncurses_style_apply(), and UiSurface::win.
| int ui_surface_show | ( | UiSurface * | s | ) |
Show a UI surface.
| s | The UiSurface to show. |
Definition at line 143 of file ui_ncurses.c.
References UiSurface::hidden, and UiSurface::pan.
| int ui_suspend | ( | UiRuntime * | ui | ) |
Suspend the UI, restoring the terminal to its normal state.
| ui | The UiRuntime instance. |
Definition at line 295 of file ui_ncurses.c.