use std::fmt::Debug;
use r3bl_rs_utils_core::*;
use serde::*;
use crate::*;
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
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: ChUnit,
pub scroll_offset_row_index: ChUnit,
}
impl DialogEngine {
pub fn new(
dialog_options: DialogEngineConfigOptions,
editor_options: EditorEngineConfig,
) -> Self {
let Size {
col_count,
row_count: _,
} = lookup_size().unwrap_or(size!(col_count: 200, row_count: 0));
Self {
dialog_options,
editor_engine: EditorEngine::new(editor_options),
color_wheel: ColorWheel::new(vec![
ColorWheelConfig::Rgb(
vec![
"#00ffff".into(),
"#ff00ff".into(),
"#0000ff".into(),
"#00ff00".into(),
"#ffff00".into(),
"#ff0000".into(),
],
ColorWheelSpeed::Fast,
ch!(@to_usize col_count + 50),
),
ColorWheelConfig::Ansi256(
Ansi256GradientIndex::LightGreenToLightBlue,
ColorWheelSpeed::Medium,
),
]),
..Default::default()
}
}
pub fn reset(&mut self) {
self.selected_row_index = ch!(0);
self.scroll_offset_row_index = ch!(0);
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct DialogEngineConfigOptions {
pub mode: DialogEngineMode,
pub result_panel_display_row_count: ChUnit,
pub maybe_style_border: Option<Style>,
pub maybe_style_title: Option<Style>,
pub maybe_style_editor: Option<Style>,
pub maybe_style_results_panel: Option<Style>,
}
mod dialog_engine_config_options_impl {
use super::*;
impl Default for DialogEngineConfigOptions {
fn default() -> Self {
Self {
mode: DialogEngineMode::ModalSimple,
result_panel_display_row_count: ch!(
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, Serialize, Deserialize)]
pub enum DialogEngineMode {
ModalSimple,
ModalAutocomplete,
}