use std::ffi::OsString;
use bincode::{Decode, Encode};
use crate::{
context::DuatSender,
form::Painter,
mode::{TwoPointsPlace, VPoint},
opts::PrintOpts,
text::{Point, Text, TwoPoints},
ui::{Columns, Coord, DynSpawnSpecs, PrintedLine, PushSpecs, SpawnId, StaticSpawnSpecs},
};
pub trait RawUi: Sized + Send + Sync + 'static {
type Area: RawArea;
fn open() -> Vec<OsString>;
fn close();
fn load(duat_tx: DuatSender) -> Self;
fn unload(&'static self);
fn new_root(&'static self, cache: <Self::Area as RawArea>::Cache) -> Self::Area;
fn new_dyn_spawned(
&'static self,
id: SpawnId,
specs: DynSpawnSpecs,
cache: <Self::Area as RawArea>::Cache,
win: usize,
) -> Self::Area;
fn new_static_spawned(
&'static self,
id: SpawnId,
specs: StaticSpawnSpecs,
cache: <Self::Area as RawArea>::Cache,
win: usize,
) -> Self::Area;
fn switch_window(&'static self, win: usize);
fn flush_layout(&'static self);
fn print(&'static self);
fn remove_window(&'static self, win: usize);
fn size(&'static self) -> Coord;
}
pub trait RawArea: Sized + PartialEq + 'static {
type Cache: Default + std::fmt::Debug + Encode + Decode<()> + 'static;
type PrintInfo: Default + Clone + Send + Sync + PartialEq + Eq + 'static;
fn push(
&self,
_: UiPass,
specs: PushSpecs,
on_files: bool,
cache: Self::Cache,
) -> Option<(Self, Option<Self>)>;
fn spawn(
&self,
_: UiPass,
id: SpawnId,
specs: DynSpawnSpecs,
cache: Self::Cache,
) -> Option<Self>;
fn delete(&self, _: UiPass) -> (bool, Vec<Self>);
fn swap(&self, _: UiPass, rhs: &Self) -> bool;
fn set_width(&self, _: UiPass, width: f32) -> Result<(), Text>;
fn set_height(&self, _: UiPass, height: f32) -> Result<(), Text>;
fn hide(&self, _: UiPass) -> Result<(), Text>;
fn reveal(&self, _: UiPass) -> Result<(), Text>;
fn size_of_text(&self, _: UiPass, opts: PrintOpts, text: &Text) -> Result<Coord, Text>;
fn set_as_active(&self, _: UiPass);
fn print(&self, _: UiPass, text: &Text, opts: PrintOpts, painter: Painter);
fn get_print_info(&self, _: UiPass) -> Self::PrintInfo;
fn set_print_info(&self, _: UiPass, info: Self::PrintInfo);
fn get_printed_lines(
&self,
_: UiPass,
text: &Text,
opts: PrintOpts,
) -> Option<Vec<PrintedLine>>;
fn move_ver(
&self,
_: UiPass,
by: i32,
text: &Text,
point: Point,
desired_col: Option<usize>,
opts: PrintOpts,
) -> VPoint;
fn move_ver_wrapped(
&self,
_: UiPass,
by: i32,
text: &Text,
point: Point,
desired_col: Option<usize>,
opts: PrintOpts,
) -> VPoint;
fn scroll_ver(&self, _: UiPass, text: &Text, dist: i32, opts: PrintOpts);
fn scroll_around_points(&self, _: UiPass, text: &Text, points: TwoPoints, opts: PrintOpts);
fn scroll_to_points(&self, _: UiPass, text: &Text, points: TwoPoints, opts: PrintOpts);
fn start_points(&self, _: UiPass, text: &Text, opts: PrintOpts) -> TwoPoints;
fn end_points(&self, _: UiPass, text: &Text, opts: PrintOpts) -> TwoPoints;
fn has_changed(&self, _: UiPass) -> bool;
fn is_master_of(&self, _: UiPass, other: &Self) -> bool;
fn get_cluster_master(&self, _: UiPass) -> Option<Self>;
fn cache(&self, _: UiPass) -> Option<Self::Cache>;
fn top_left(&self, _: UiPass) -> Coord;
fn bottom_right(&self, _: UiPass) -> Coord;
fn points_at_coord(
&self,
_: UiPass,
text: &Text,
coord: Coord,
opts: PrintOpts,
) -> Option<TwoPointsPlace>;
fn coord_at_points(
&self,
_: UiPass,
text: &Text,
points: TwoPoints,
opts: PrintOpts,
) -> Option<Coord>;
fn columns_at(
&self,
_: UiPass,
text: &Text,
points: TwoPoints,
opts: PrintOpts,
) -> Option<Columns>;
fn is_active(&self, _: UiPass) -> bool;
}
#[non_exhaustive]
#[derive(Clone, Copy)]
pub struct UiPass {}
impl UiPass {
pub(super) const fn new() -> Self {
UiPass {}
}
}