use std::collections::BTreeMap;
use std::rc::Rc;
use crate::draw::{FontDef, Rect};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TouchControl {
pub rect: Rect,
pub magnify: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ActionFrom {
pub rect: Rect,
pub point: Option<(i32, i32)>,
}
pub trait SkinHost {
fn image_size(&mut self, file: &str) -> Option<(i32, i32)>;
fn pixel(&mut self, _file: &str, _x: i32, _y: i32) -> Option<u32> {
None
}
fn pixels(&mut self, file: &str, x: i32, y: i32, w: i32, h: i32) -> Option<Vec<u32>> {
let n = (w.max(0) as usize) * (h.max(0) as usize);
let mut out = Vec::with_capacity(n);
for i in 0..n {
out.push(self.pixel(
file,
x + (i % w as usize) as i32,
y + (i / w as usize) as i32,
)?);
}
Some(out)
}
fn text_width(&mut self, text: &str, font: Option<&FontDef>, size: i32, bold: bool) -> i32;
fn text_advance(&mut self, text: &str, font: Option<&FontDef>, size: i32, bold: bool) -> f32 {
self.text_width(text, font, size, bold) as f32
}
fn smooth_text_advance(
&mut self,
_text: &str,
_font: Option<&FontDef>,
_size: i32,
_bold: bool,
) -> Option<f32> {
None
}
fn smooth_line_metrics(
&mut self,
_font: Option<&FontDef>,
_size: i32,
_bold: bool,
) -> Option<(f32, f32)> {
None
}
fn line_metrics(
&mut self,
_font: Option<&FontDef>,
_size: i32,
_bold: bool,
) -> Option<(f32, f32)> {
None
}
fn font_file(&mut self, _file: &str) -> Option<Rc<[u8]>> {
None
}
fn log(&mut self, message: &str);
fn invalidate(&mut self);
fn window_open(&mut self, _kind: &str) -> Option<bool> {
None
}
fn choose_from_menu(&mut self, _menu: &SkinMenu) -> Option<i32> {
Some(0)
}
fn windows_changed(&mut self, _windows: &[WindowId]) {}
fn host_action(&mut self, _action: &str, _param: Option<&str>, _from: Option<ActionFrom>) {}
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct SkinMenu {
pub items: Vec<MenuItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum MenuItem {
Command {
id: i32,
text: String,
checked: bool,
disabled: bool,
},
Separator,
Submenu {
text: String,
menu: SkinMenu,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct WindowId(pub u32);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Edge {
Start,
End,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WindowInfo {
pub id: WindowId,
pub size: (i32, i32),
pub min_w: i32,
pub min_h: i32,
pub max_w: i32,
pub max_h: i32,
pub resizable_both_ways: bool,
pub edge_x: Option<Edge>,
pub edge_y: Option<Edge>,
pub container: String,
pub layout: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ObjectInfo {
pub window: WindowId,
pub rect: Rect,
pub stack_rect: Rect,
pub visible: bool,
pub class_name: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UnknownObject {
pub tag: String,
pub id: String,
pub window: WindowId,
pub container: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct EngineStats {
pub script_steps: i64,
pub timer_fires: i64,
pub layout_passes: i64,
pub shapes_worked_out: i64,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Presentation {
pub view_size: Option<(i32, i32)>,
pub viewport: (i32, i32),
pub columns: i32,
pub column_width: i32,
pub stretch_last: bool,
pub touch_slop: i32,
pub free_windows: bool,
pub touch: bool,
pub skin_list_font: bool,
pub list_row_extra: i32,
}
impl Default for Presentation {
fn default() -> Self {
Presentation {
view_size: None,
viewport: (1080, 1920),
columns: 1,
column_width: 0,
stretch_last: true,
touch_slop: 6,
free_windows: false,
touch: false,
skin_list_font: false,
list_row_extra: 0,
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SavedSettings {
pub attributes: BTreeMap<String, String>,
pub strings: BTreeMap<String, String>,
pub ints: BTreeMap<String, i32>,
}
#[derive(Debug, Clone, Default)]
pub struct SkinOptions {
pub version: i32,
pub entries: Vec<OptionEntry>,
}
impl PartialEq for SkinOptions {
fn eq(&self, other: &Self) -> bool {
self.entries == other.entries
}
}
impl Eq for SkinOptions {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum OptionEntry {
Toggle {
key: OptionKey,
text: String,
checked: bool,
radio: bool,
},
Separator,
Submenu {
text: String,
entries: Vec<OptionEntry>,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct OptionKey {
pub item: String,
pub attribute: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SkinSetup {
pub skin_name: String,
pub have_library: bool,
pub host_actions: bool,
}
impl Default for SkinSetup {
fn default() -> Self {
SkinSetup {
skin_name: String::new(),
have_library: true,
host_actions: false,
}
}
}
pub type Clock = Rc<dyn Fn() -> i64>;