use crate::{Point, Rect, Size};
pub trait Failable {
type Error;
}
pub trait Visible: Failable {
fn is_visible(&self) -> Result<bool, Self::Error>;
fn set_visible(&mut self, v: bool) -> Result<(), Self::Error>;
fn show(&mut self) -> Result<(), Self::Error> {
self.set_visible(true)
}
fn hide(&mut self) -> Result<(), Self::Error> {
self.set_visible(false)
}
}
pub trait Enable: Failable {
fn is_enabled(&self) -> Result<bool, Self::Error>;
fn set_enabled(&mut self, v: bool) -> Result<(), Self::Error>;
fn enable(&mut self) -> Result<(), Self::Error> {
self.set_enabled(true)
}
fn disable(&mut self) -> Result<(), Self::Error> {
self.set_enabled(false)
}
}
pub trait ToolTip: Failable {
fn tooltip(&self) -> Result<String, Self::Error>;
fn set_tooltip(&mut self, s: impl AsRef<str>) -> Result<(), Self::Error>;
}
pub trait TextWidget: Failable {
fn text(&self) -> Result<String, Self::Error>;
fn set_text(&mut self, s: impl AsRef<str>) -> Result<(), Self::Error>;
}
pub trait Layoutable: Failable {
fn loc(&self) -> Result<Point, Self::Error>;
fn set_loc(&mut self, p: Point) -> Result<(), Self::Error>;
fn size(&self) -> Result<Size, Self::Error>;
fn set_size(&mut self, s: Size) -> Result<(), Self::Error>;
fn rect(&self) -> Result<Rect, Self::Error> {
Ok(Rect::new(self.loc()?, self.size()?))
}
fn set_rect(&mut self, r: Rect) -> Result<(), Self::Error> {
self.set_loc(r.origin)?;
self.set_size(r.size)
}
fn preferred_size(&self) -> Result<Size, Self::Error> {
Ok(Size::zero())
}
fn min_size(&self) -> Result<Size, Self::Error> {
self.preferred_size()
}
}