use std::borrow::Cow;
use crate::traits::Set;
use crate::{Default, Display, Script, Title};
#[derive(Clone)]
pub struct Properties {
boxed: bool,
hidden: bool,
justification: Option<Justification>,
order: Option<Order>,
position: Option<Position>,
stacked: Option<Stacked>,
title: Option<Cow<'static, str>>,
}
impl Default for Properties {
fn default() -> Properties {
Properties {
boxed: false,
hidden: false,
justification: None,
order: None,
position: None,
stacked: None,
title: None,
}
}
}
impl Properties {
pub fn hide(&mut self) -> &mut Properties {
self.hidden = true;
self
}
pub fn show(&mut self) -> &mut Properties {
self.hidden = false;
self
}
}
impl Script for Properties {
#[allow(clippy::all)]
fn script(&self) -> String {
let mut script = if self.hidden {
return String::from("set key off\n");
} else {
String::from("set key on ")
};
match self.position {
None => {}
Some(Position::Inside(v, h)) => {
script.push_str(&format!("inside {} {} ", v.display(), h.display()))
}
Some(Position::Outside(v, h)) => {
script.push_str(&format!("outside {} {} ", v.display(), h.display()))
}
}
if let Some(stacked) = self.stacked {
script.push_str(stacked.display());
script.push(' ');
}
if let Some(justification) = self.justification {
script.push_str(justification.display());
script.push(' ');
}
if let Some(order) = self.order {
script.push_str(order.display());
script.push(' ');
}
if let Some(ref title) = self.title {
script.push_str(&format!("title '{}' ", title))
}
if self.boxed {
script.push_str("box ")
}
script.push('\n');
script
}
}
impl Set<Boxed> for Properties {
fn set(&mut self, boxed: Boxed) -> &mut Properties {
match boxed {
Boxed::No => self.boxed = false,
Boxed::Yes => self.boxed = true,
}
self
}
}
impl Set<Justification> for Properties {
fn set(&mut self, justification: Justification) -> &mut Properties {
self.justification = Some(justification);
self
}
}
impl Set<Order> for Properties {
fn set(&mut self, order: Order) -> &mut Properties {
self.order = Some(order);
self
}
}
impl Set<Position> for Properties {
fn set(&mut self, position: Position) -> &mut Properties {
self.position = Some(position);
self
}
}
impl Set<Stacked> for Properties {
fn set(&mut self, stacked: Stacked) -> &mut Properties {
self.stacked = Some(stacked);
self
}
}
impl Set<Title> for Properties {
fn set(&mut self, title: Title) -> &mut Properties {
self.title = Some(title.0);
self
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy)]
pub enum Boxed {
No,
Yes,
}
#[derive(Clone, Copy)]
pub enum Horizontal {
Center,
Left,
Right,
}
#[allow(missing_docs)]
#[derive(Clone, Copy)]
pub enum Justification {
Left,
Right,
}
#[derive(Clone, Copy)]
pub enum Order {
SampleText,
TextSample,
}
#[derive(Clone, Copy)]
pub enum Position {
Inside(Vertical, Horizontal),
Outside(Vertical, Horizontal),
}
#[allow(missing_docs)]
#[derive(Clone, Copy)]
pub enum Stacked {
Horizontally,
Vertically,
}
#[derive(Clone, Copy)]
pub enum Vertical {
Bottom,
Center,
Top,
}