use std::fmt::Debug;
use smallvec::smallvec;
use crate::{get_terminal_width_no_default, row, u8, width, Ansi256GradientIndex,
ColorWheel, ColorWheelConfig, ColorWheelSpeed, DisplayConstants,
EditorEngine, EditorEngineConfig, PartialFlexBox, RowHeight, RowIndex, Size,
SurfaceBounds, TuiStyle};
#[derive(Default, Debug)]
pub struct DialogEngine {
pub dialog_options: DialogEngineConfigOptions,
pub editor_engine: EditorEngine,
pub color_wheel: ColorWheel,
pub maybe_flex_box: Option<(
/* window size: */ Size,
/* mode: */ DialogEngineMode,
/* flex box calculated by render_engine(): */ PartialFlexBox,
)>,
pub maybe_surface_bounds: Option<SurfaceBounds>,
pub selected_row_index: RowIndex,
pub scroll_offset_row_index: RowIndex,
}
impl DialogEngine {
#[must_use]
pub fn new(
dialog_options: DialogEngineConfigOptions,
editor_options: EditorEngineConfig,
) -> Self {
let width_col_count = *get_terminal_width_no_default().unwrap_or(width(200));
Self {
dialog_options,
editor_engine: EditorEngine::new(editor_options),
color_wheel: ColorWheel::new(smallvec![
ColorWheelConfig::Rgb(
smallvec::smallvec![
"#00ffff".into(),
"#ff00ff".into(),
"#0000ff".into(),
"#00ff00".into(),
"#ffff00".into(),
"#ff0000".into(),
],
ColorWheelSpeed::Fast,
u8(width_col_count + 50),
),
ColorWheelConfig::Ansi256(
Ansi256GradientIndex::LightGreenToLightBlue,
ColorWheelSpeed::Medium,
),
]),
..Default::default()
}
}
pub fn reset(&mut self) {
self.selected_row_index = row(0);
self.scroll_offset_row_index = row(0);
}
}
#[derive(Clone, Debug, PartialEq, Eq, Copy)]
pub struct DialogEngineConfigOptions {
pub mode: DialogEngineMode,
pub result_panel_display_row_count: RowHeight,
pub maybe_style_border: Option<TuiStyle>,
pub maybe_style_title: Option<TuiStyle>,
pub maybe_style_editor: Option<TuiStyle>,
pub maybe_style_results_panel: Option<TuiStyle>,
}
mod dialog_engine_config_options_impl {
use super::{DialogEngineConfigOptions, DialogEngineMode, DisplayConstants};
use crate::height;
impl Default for DialogEngineConfigOptions {
fn default() -> Self {
Self {
mode: DialogEngineMode::ModalSimple,
result_panel_display_row_count: height(
DisplayConstants::DefaultResultsPanelRowCount as u16,
),
maybe_style_border: None,
maybe_style_editor: None,
maybe_style_title: None,
maybe_style_results_panel: None,
}
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum DialogEngineMode {
ModalSimple,
ModalAutocomplete,
}