use diaphragm_core::{ core_shapes::Text, text::FontDescription, types::{Bounds, Float, ShapeContext}, ComplexShape, DrawResult, DynClone, SolverContext, }; pub struct Labeled { pub label: String, pub label_font: FontDescription, pub content: Box, pub content_left: Float, } impl ComplexShape for Labeled { fn draw(&self, context: &ShapeContext, solver: &mut dyn SolverContext) -> DrawResult { let mut result = DrawResult::new(); // Label let label = Text { content: self.label.clone(), font: self.label_font.clone(), }; let mut label_context = context.clone(); // TODO: make the text constrain the width label_context.bounds.width = solver.new_free_float(); let label_right = solver.float_add(&[context.bounds.left, label_context.bounds.width]); let content_left_constrain = solver.float_eq(label_right, self.content_left); solver.constrain(content_left_constrain); result.push_shape(label, label_context); // Content let content_context = ShapeContext { bounds: Bounds { top: context.bounds.top, left: solver.float_add(&[context.bounds.left, self.content_left]), height: context.bounds.height, width: context.bounds.width, }, fill: context.fill.clone(), stroke: context.stroke.clone(), }; result.push_boxed_shape(self.content.dyn_clone(), content_context); result } } impl DynClone for Labeled { fn dyn_clone(&self) -> Box { Box::new(Labeled { label: self.label.clone(), label_font: self.label_font.clone(), content: self.content.dyn_clone(), content_left: self.content_left.clone(), }) } }