ratatui_unity/ffi/style.rs
1//! Pending-style and background-color state setters.
2
3use crate::ffi::util::{state_mut, style_from_rgba};
4use std::ffi::c_void;
5
6/// Sets the RGB background color used by the rasterizer for cells whose
7/// background is [`Color::Reset`](ratatui::style::Color::Reset).
8///
9/// The value persists across frames until changed again. Setting this between
10/// frames is supported; setting it mid-frame only affects subsequent calls
11/// to `ratatui_end_frame*`.
12#[no_mangle]
13pub extern "C" fn ratatui_set_background_color(
14 handle: *mut c_void,
15 r: u8, g: u8, b: u8,
16) {
17 let Some(state) = state_mut(handle) else { return; };
18 state.background_color = [r, g, b];
19}
20
21/// Sets the pending style consumed by the next widget-producing FFI call.
22///
23/// The pending style is reset to default after each widget call and at the
24/// start of every frame. Widgets that do not accept a style (e.g. scrollbar,
25/// calendar, chart, canvas) ignore the pending style.
26///
27/// # Parameters
28/// - `fg_r`, `fg_g`, `fg_b`: foreground RGB components.
29/// - `use_default_fg`: non-zero to leave the foreground unset (terminal
30/// default); zero to apply the given RGB triple.
31/// - `bg_r`, `bg_g`, `bg_b`: background RGB components.
32/// - `use_default_bg`: non-zero to leave the background unset; zero to apply
33/// the given RGB triple.
34/// - `modifiers`: bit field — `0x01` Bold, `0x02` Italic, `0x04` Underlined,
35/// `0x08` Dim.
36#[no_mangle]
37pub extern "C" fn ratatui_set_style(
38 handle: *mut c_void,
39 fg_r: u8, fg_g: u8, fg_b: u8, use_default_fg: u8,
40 bg_r: u8, bg_g: u8, bg_b: u8, use_default_bg: u8,
41 modifiers: u8,
42) {
43 let Some(state) = state_mut(handle) else { return; };
44 state.pending_style = style_from_rgba(
45 fg_r, fg_g, fg_b, use_default_fg,
46 bg_r, bg_g, bg_b, use_default_bg,
47 modifiers,
48 );
49}