group.rs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. use crate::{
  2. layout::{LayoutChildIter, LayoutNode, LayoutNodeAccess, LayoutNodeContainer},
  3. platform::{render::Painter, PlatformPainter, PlatformSpec, TextInterface},
  4. Component, Widget,
  5. };
  6. pub struct PlainGroup<P: PlatformSpec, C: Component> {
  7. lnode: LayoutNode,
  8. children: Vec<Box<dyn Widget<P, C>>>,
  9. }
  10. impl<P: PlatformSpec, C: Component> LayoutNodeContainer for PlainGroup<P, C> {
  11. fn layout_node(&self) -> &LayoutNode {
  12. &self.lnode
  13. }
  14. fn layout_child(&self, ndx: usize) -> Option<LayoutNodeAccess> {
  15. self.children.get(ndx).map(|w| w.layout_node())
  16. }
  17. fn layout_child_count(&self) -> usize {
  18. self.children.len()
  19. }
  20. }
  21. impl<P: PlatformSpec, C: Component> Widget<P, C> for PlainGroup<P, C> {
  22. fn layout_node(&self) -> LayoutNodeAccess {
  23. LayoutNodeAccess::new(self)
  24. }
  25. fn layout_node_mut(&mut self) -> &mut LayoutNode {
  26. &mut self.lnode
  27. }
  28. fn poll(
  29. &mut self,
  30. input_state: Option<&crate::input::InputState>,
  31. ) -> Vec<<C as Component>::Msg> {
  32. vec![]
  33. }
  34. fn render(&self, painter: &mut PlatformPainter<P>, ti: &P::Text) {
  35. for child in self.children.iter() {
  36. child.render(painter, ti);
  37. }
  38. }
  39. }