#![allow(dead_code)]
use teksilo_canvas::{Rect, SizeProposal};
use teksilo_core::widget::{LayoutContext, LayoutResponse, Widget, WidgetPlacement};
use teksilo_core::widget_id::WidgetId;
#[derive(Debug, Default)]
pub struct Leaf;
impl Leaf {
pub fn new() -> Self {
Self
}
}
impl Widget for Leaf {
fn layout_response(&self, proposal: SizeProposal, _ctx: &LayoutContext) -> LayoutResponse {
proposal.resolve(0.0, 0.0).into()
}
}
#[derive(Debug, Default)]
pub struct Stack {
children: Vec<WidgetId>,
}
impl Stack {
pub fn new() -> Self {
Self {
children: Vec::new(),
}
}
pub fn child(mut self, c: impl teksilo_core::IntoTeksiChild) -> Self {
match teksilo_core::IntoTeksiChild::into_pending(c) {
teksilo_core::PendingChild::Id(id) => self.children.push(id),
teksilo_core::PendingChild::Deferred(_) => unreachable!("Stack takes ids"),
}
self
}
}
impl Widget for Stack {
fn layout_response(&self, proposal: SizeProposal, _ctx: &LayoutContext) -> LayoutResponse {
proposal.resolve(0.0, 0.0).into()
}
fn place_children(
&self,
bounds: Rect,
_proposal: SizeProposal,
children: &mut [WidgetPlacement],
_ctx: &LayoutContext,
) {
for child in children.iter_mut() {
child.origin = bounds.origin();
child.size = bounds.size();
}
}
fn children(&self) -> Vec<WidgetId> {
self.children.clone()
}
}