par_term_config/types/rendering.rs
1//! Rendering-related configuration types: GPU, display modes, pane/divider layout.
2
3use serde::{Deserialize, Serialize};
4
5// ============================================================================
6// GPU / VSync / Power Types
7// ============================================================================
8
9/// VSync mode (presentation mode)
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Default)]
11#[serde(rename_all = "lowercase")]
12pub enum VsyncMode {
13 /// No VSync - render as fast as possible (lowest latency, highest GPU usage)
14 Immediate,
15 /// Mailbox VSync - cap at monitor refresh rate with triple buffering (balanced)
16 Mailbox,
17 /// FIFO VSync - strict vsync with double buffering (lowest GPU usage, most compatible)
18 #[default]
19 Fifo,
20}
21
22impl VsyncMode {
23 // wgpu::PresentMode conversion lives in par-term-render (AUDIT.md ARC-003):
24 // see `par_term_render::wgpu_conversions::VsyncModeWgpu`.
25}
26
27/// GPU power preference for adapter selection
28///
29/// Controls which GPU adapter is preferred when multiple GPUs are available
30/// (e.g., integrated Intel GPU vs discrete NVIDIA/AMD GPU).
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Default)]
32#[serde(rename_all = "snake_case")]
33pub enum PowerPreference {
34 /// No preference - let the system decide (default)
35 #[default]
36 None,
37 /// Prefer integrated GPU (Intel/AMD iGPU) - saves battery
38 LowPower,
39 /// Prefer discrete GPU (NVIDIA/AMD) - maximum performance
40 HighPerformance,
41}
42
43impl PowerPreference {
44 // wgpu::PowerPreference conversion lives in par-term-render (AUDIT.md ARC-003):
45 // see `par_term_render::wgpu_conversions::PowerPreferenceWgpu`.
46
47 /// Display name for UI
48 pub fn display_name(&self) -> &'static str {
49 match self {
50 PowerPreference::None => "None (System Default)",
51 PowerPreference::LowPower => "Low Power (Integrated GPU)",
52 PowerPreference::HighPerformance => "High Performance (Discrete GPU)",
53 }
54 }
55
56 /// All available power preferences for UI iteration
57 pub fn all() -> &'static [PowerPreference] {
58 &[
59 PowerPreference::None,
60 PowerPreference::LowPower,
61 PowerPreference::HighPerformance,
62 ]
63 }
64}
65
66// ============================================================================
67// Image / Background Types
68// ============================================================================
69
70/// Image scaling quality for inline graphics (Sixel, iTerm2, Kitty)
71///
72/// Controls the GPU texture sampling filter used when scaling inline images.
73#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
74#[serde(rename_all = "lowercase")]
75pub enum ImageScalingMode {
76 /// Nearest-neighbor filtering - sharp pixels, good for pixel art
77 Nearest,
78 /// Bilinear filtering - smooth scaling (default)
79 #[default]
80 Linear,
81}
82
83impl ImageScalingMode {
84 /// Display name for UI
85 pub fn display_name(&self) -> &'static str {
86 match self {
87 ImageScalingMode::Nearest => "Nearest (Sharp)",
88 ImageScalingMode::Linear => "Linear (Smooth)",
89 }
90 }
91
92 /// All available modes for UI iteration
93 pub fn all() -> &'static [ImageScalingMode] {
94 &[ImageScalingMode::Nearest, ImageScalingMode::Linear]
95 }
96
97 // wgpu::FilterMode conversion lives in par-term-render (AUDIT.md ARC-003):
98 // see `par_term_render::wgpu_conversions::ImageScalingModeWgpu`.
99}
100
101/// Background image display mode
102#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
103#[serde(rename_all = "lowercase")]
104pub enum BackgroundImageMode {
105 /// Scale to fit window while maintaining aspect ratio (may have letterboxing)
106 Fit,
107 /// Scale to fill window while maintaining aspect ratio (may crop edges)
108 Fill,
109 /// Stretch to fill window exactly (ignores aspect ratio)
110 #[default]
111 Stretch,
112 /// Repeat image in a tiled pattern at original size
113 Tile,
114 /// Center image at original size (no scaling)
115 Center,
116}
117
118/// Background source selection
119#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
120#[serde(rename_all = "lowercase")]
121pub enum BackgroundMode {
122 /// Use theme's default background color
123 #[default]
124 Default,
125 /// Use a custom solid color
126 Color,
127 /// Use a background image
128 Image,
129}
130
131/// Per-pane background image configuration (for config persistence)
132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
133pub struct PaneBackgroundConfig {
134 /// Pane index (0-based)
135 pub index: usize,
136 /// Image path
137 pub image: String,
138 /// Display mode
139 #[serde(default)]
140 pub mode: BackgroundImageMode,
141 /// Opacity
142 #[serde(default = "crate::defaults::background_image_opacity")]
143 pub opacity: f32,
144 /// Darken amount (0.0 = no darkening, 1.0 = fully black)
145 #[serde(default = "crate::defaults::pane_background_darken")]
146 pub darken: f32,
147}
148
149/// Per-pane background image configuration (runtime state)
150#[derive(Debug, Clone, Default)]
151pub struct PaneBackground {
152 /// Path to the background image (None = use global background)
153 pub image_path: Option<String>,
154 /// Display mode (fit/fill/stretch/tile/center)
155 pub mode: BackgroundImageMode,
156 /// Opacity (0.0-1.0)
157 pub opacity: f32,
158 /// Darken amount (0.0 = no darkening, 1.0 = fully black)
159 pub darken: f32,
160}
161
162impl PaneBackground {
163 /// Create a new PaneBackground with default settings
164 pub fn new() -> Self {
165 Self {
166 image_path: None,
167 mode: BackgroundImageMode::default(),
168 opacity: 1.0,
169 darken: 0.0,
170 }
171 }
172
173 /// Returns true if this pane has a custom background image set
174 pub fn has_image(&self) -> bool {
175 self.image_path.is_some()
176 }
177}
178
179// ============================================================================
180// Pane / Divider Layout Types
181// ============================================================================
182
183/// Position of pane title bars
184#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
185#[serde(rename_all = "snake_case")]
186pub enum PaneTitlePosition {
187 /// Title bar at the top of the pane (default)
188 #[default]
189 Top,
190 /// Title bar at the bottom of the pane
191 Bottom,
192}
193
194impl PaneTitlePosition {
195 /// All available positions for UI dropdowns
196 pub const ALL: &'static [PaneTitlePosition] =
197 &[PaneTitlePosition::Top, PaneTitlePosition::Bottom];
198
199 /// Display name for UI
200 pub fn display_name(&self) -> &'static str {
201 match self {
202 PaneTitlePosition::Top => "Top",
203 PaneTitlePosition::Bottom => "Bottom",
204 }
205 }
206}
207
208/// Auto-balance after a keyboard or menu split (UX.md PN7)
209#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
210#[serde(rename_all = "snake_case")]
211pub enum SplitBalance {
212 /// The split pane is halved; nothing else moves (default)
213 #[default]
214 None,
215 /// Even out the panes beside the new one along the split direction
216 Siblings,
217 /// Give every pane in the tab an equal area
218 All,
219}
220
221impl SplitBalance {
222 /// All options for UI dropdowns
223 pub const ALL: &'static [SplitBalance] = &[
224 SplitBalance::None,
225 SplitBalance::Siblings,
226 SplitBalance::All,
227 ];
228
229 /// Display name for UI
230 pub fn display_name(&self) -> &'static str {
231 match self {
232 SplitBalance::None => "Off (halve the split pane)",
233 SplitBalance::Siblings => "Even out the row or column",
234 SplitBalance::All => "Equalize the whole tab",
235 }
236 }
237}
238
239/// How unfocused panes are dimmed when `dim_inactive_panes` is on (UX.md PN9)
240#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
241#[serde(rename_all = "snake_case")]
242pub enum InactivePaneDimMode {
243 /// Scale colors toward black; text stays opaque (default)
244 #[default]
245 Darken,
246 /// Lower opacity, text included, so a background image or shader shows through
247 Fade,
248}
249
250impl InactivePaneDimMode {
251 /// All modes for UI dropdowns
252 pub const ALL: &'static [InactivePaneDimMode] =
253 &[InactivePaneDimMode::Darken, InactivePaneDimMode::Fade];
254
255 /// Display name for UI
256 pub fn display_name(&self) -> &'static str {
257 match self {
258 InactivePaneDimMode::Darken => "Darken",
259 InactivePaneDimMode::Fade => "Fade (transparent)",
260 }
261 }
262}
263
264/// Style of dividers between panes
265#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
266#[serde(rename_all = "snake_case")]
267pub enum DividerStyle {
268 /// Solid line (default)
269 #[default]
270 Solid,
271 /// Double line effect (two thin lines with gap)
272 Double,
273 /// Dashed line effect
274 Dashed,
275 /// Shadow effect (gradient fade)
276 Shadow,
277}
278
279impl DividerStyle {
280 /// All available styles for UI dropdowns
281 pub const ALL: &'static [DividerStyle] = &[
282 DividerStyle::Solid,
283 DividerStyle::Double,
284 DividerStyle::Dashed,
285 DividerStyle::Shadow,
286 ];
287
288 /// Display name for UI
289 pub fn display_name(&self) -> &'static str {
290 match self {
291 DividerStyle::Solid => "Solid",
292 DividerStyle::Double => "Double",
293 DividerStyle::Dashed => "Dashed",
294 DividerStyle::Shadow => "Shadow",
295 }
296 }
297}
298
299/// A divider rectangle between panes
300#[derive(Debug, Clone, Copy)]
301pub struct DividerRect {
302 /// X position in pixels
303 pub x: f32,
304 /// Y position in pixels
305 pub y: f32,
306 /// Width in pixels
307 pub width: f32,
308 /// Height in pixels
309 pub height: f32,
310 /// Whether this is a horizontal divider (vertical line)
311 pub is_horizontal: bool,
312}
313
314impl DividerRect {
315 /// Create a new divider rect
316 pub fn new(x: f32, y: f32, width: f32, height: f32, is_horizontal: bool) -> Self {
317 Self {
318 x,
319 y,
320 width,
321 height,
322 is_horizontal,
323 }
324 }
325
326 /// Check if a point is inside the divider (with optional padding for easier grabbing)
327 pub fn contains(&self, px: f32, py: f32, padding: f32) -> bool {
328 px >= self.x - padding
329 && px < self.x + self.width + padding
330 && py >= self.y - padding
331 && py < self.y + self.height + padding
332 }
333}
334
335// ============================================================================
336// Shared ID and Mark Types
337// ============================================================================
338
339/// Visible command separator mark: (row, col_offset, optional_color)
340pub type SeparatorMark = (usize, Option<i32>, Option<(u8, u8, u8)>);
341
342/// Unique identifier for a pane
343pub type PaneId = u64;
344
345/// Unique identifier for a tab
346pub type TabId = u64;