use std::borrow::Cow;
use {Default, Display, Script};
#[derive(Clone)]
pub struct KeyProperties {
boxed: bool,
hidden: bool,
justification: Option<Justification>,
order: Option<Order>,
position: Option<Position>,
stacked: Option<Stacked>,
title: Option<Cow<'static, str>>,
}
impl Default for KeyProperties {
fn default() -> KeyProperties {
KeyProperties {
boxed: false,
hidden: false,
justification: None,
order: None,
position: None,
stacked: None,
title: None,
}
}
}
impl KeyProperties {
pub fn hide(&mut self) -> &mut KeyProperties {
self.hidden = true;
self
}
pub fn show(&mut self) -> &mut KeyProperties {
self.hidden = false;
self
}
pub fn boxed(&mut self, boxed: bool) -> &mut KeyProperties {
self.boxed = boxed;
self
}
pub fn justification(&mut self, justification: Justification) -> &mut KeyProperties {
self.justification = Some(justification);
self
}
pub fn order(&mut self, order: Order) -> &mut KeyProperties {
self.order = Some(order);
self
}
pub fn position(&mut self, position: Position) -> &mut KeyProperties {
self.position = Some(position);
self
}
pub fn stacked(&mut self, stacked: Stacked) -> &mut KeyProperties {
self.stacked = Some(stacked);
self
}
pub fn title<S>(&mut self, title: S) -> &mut KeyProperties
where
S: Into<Cow<'static, str>>,
{
self.title = Some(title.into());
self
}
}
impl Script for KeyProperties {
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
}
}
#[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,
}