use crate::kurbo::Insets;
use crate::piet::{PaintBrush, UnitPoint};
use super::{Align, Container, EnvScope, Padding, Parse, SizedBox};
use crate::{Data, Env, Lens, LensWrap, Widget};
pub trait WidgetExt<T: Data>: Widget<T> + Sized + 'static {
fn padding(self, insets: impl Into<Insets>) -> Padding<T> {
Padding::new(insets, self)
}
fn center(self) -> Align<T> {
Align::centered(self)
}
fn align_left(self) -> Align<T> {
Align::left(self)
}
fn align_right(self) -> Align<T> {
Align::right(self)
}
fn align_vertical(self, align: UnitPoint) -> Align<T> {
Align::vertical(align, self)
}
fn align_horizontal(self, align: UnitPoint) -> Align<T> {
Align::horizontal(align, self)
}
fn fix_width(self, width: f64) -> SizedBox<T> {
SizedBox::new(self).width(width)
}
fn fix_height(self, height: f64) -> SizedBox<T> {
SizedBox::new(self).height(height)
}
fn expand(self) -> SizedBox<T> {
SizedBox::new(self).expand()
}
fn background(self, brush: impl Into<PaintBrush>) -> Container<T> {
Container::new(self).background(brush)
}
fn border(self, brush: impl Into<PaintBrush>, width: f64) -> Container<T> {
Container::new(self).border(brush, width)
}
fn env_scope(self, f: impl Fn(&mut Env) + 'static) -> EnvScope<T, Self> {
EnvScope::new(f, self)
}
fn lens<S: Data, L: Lens<S, T>>(self, lens: L) -> LensWrap<T, L, Self> {
LensWrap::new(self, lens)
}
fn parse(self) -> Parse<Self>
where
Self: Widget<String>,
{
Parse::new(self)
}
}
impl<T: Data + 'static, W: Widget<T> + 'static> WidgetExt<T> for W {}
impl<T: Data + 'static> Container<T> {
pub fn with_background(self, brush: impl Into<PaintBrush>) -> Container<T> {
self.background(brush)
}
pub fn bordered(self, brush: impl Into<PaintBrush>, width: f64) -> Container<T> {
self.border(brush, width)
}
}
impl<T: Data + 'static> SizedBox<T> {
pub fn fixed_width(self, width: f64) -> SizedBox<T> {
self.width(width)
}
pub fn fixed_height(self, height: f64) -> SizedBox<T> {
self.height(height)
}
}