mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
fold single-use components into TransportToolbar
This commit is contained in:
parent
267f9f61d5
commit
0574eb79ef
2 changed files with 180 additions and 313 deletions
|
|
@ -118,24 +118,6 @@ impl<E: Engine, W: Widget<Engine = E>> Widget for Option<W> {
|
|||
self.as_ref().map(|widget|widget.render(to)).unwrap_or(Ok(()))
|
||||
}
|
||||
}
|
||||
/// A [Widget] that contains other [Widget]s
|
||||
pub trait Content: Send + Sync {
|
||||
type Engine: Engine;
|
||||
fn content (&self) -> impl Widget<Engine = <Self as Content>::Engine>;
|
||||
}
|
||||
/// Every struct that has [Content] is a renderable [Widget].
|
||||
impl<E: Engine, W: Content<Engine = E>> Widget for W {
|
||||
type Engine = E;
|
||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||
self.content().layout(to)
|
||||
}
|
||||
fn render (&self, to: &mut E::Output) -> Usually<()> {
|
||||
match self.layout(to.area().wh().into())? {
|
||||
Some(wh) => to.render_in(to.area().clip(wh).into(), &self.content()),
|
||||
None => Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
/// A custom [Widget] defined by passing layout and render closures in place.
|
||||
pub struct CustomWidget<
|
||||
E: Engine,
|
||||
|
|
@ -164,6 +146,24 @@ impl<
|
|||
self.1(to)
|
||||
}
|
||||
}
|
||||
/// A [Widget] that contains other [Widget]s
|
||||
pub trait Content: Send + Sync {
|
||||
type Engine: Engine;
|
||||
fn content (&self) -> impl Widget<Engine = <Self as Content>::Engine>;
|
||||
}
|
||||
/// Every struct that has [Content] is a renderable [Widget].
|
||||
impl<E: Engine, W: Content<Engine = E>> Widget for W {
|
||||
type Engine = E;
|
||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||
self.content().layout(to)
|
||||
}
|
||||
fn render (&self, to: &mut E::Output) -> Usually<()> {
|
||||
match self.layout(to.area().wh().into())? {
|
||||
Some(wh) => to.render_in(to.area().clip(wh).into(), &self.content()),
|
||||
None => Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Handle input
|
||||
pub trait Handle<E: Engine>: Send + Sync {
|
||||
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue