use crate::types::{CoreShapeContext, DefinedCoreShapeContext, DefinedPoint2D, Point2D}; pub use super::text::{DefinedText, Text}; pub struct CoreDrawable { pub(crate) shape: CoreShape, pub(crate) context: CoreShapeContext, } impl CoreDrawable { pub fn new(shape: CoreShape, context: CoreShapeContext) -> Self { Self { shape, context } } } pub enum CoreShape { Rectangle(Rectangle), Text(Text), StraightPath(StraightPath), } impl From for CoreShape { fn from(rectangle: Rectangle) -> Self { CoreShape::Rectangle(rectangle) } } impl From for CoreShape { fn from(text: Text) -> Self { CoreShape::Text(text) } } impl From for CoreShape { fn from(path: StraightPath) -> Self { CoreShape::StraightPath(path) } } pub struct DefinedCoreDrawable { pub(crate) shape: DefinedCoreShape, pub(crate) context: DefinedCoreShapeContext, } pub enum DefinedCoreShape { Rectangle(Rectangle), Text(DefinedText), StraightPath(DefinedStraightPath), } /* pub trait CoreShape { fn constrain( &self, _context: &ShapeContext, _solver: &mut dyn SolverContext, _renderer: &dyn Renderer, ) { } fn to_render(&self, model: &dyn SolverModel) -> Option>; } impl ComplexShape for T { fn as_core_shape(&self) -> Option<&dyn CoreShape> { Some(self) } fn draw(&self, _context: &ShapeContext, _solver: &mut dyn SolverContext) -> DrawResult { panic!("Tried to decompose core shape") } } */ #[derive(Copy, Clone, Debug, Default)] pub struct Rectangle {} /* impl CoreShape for Rectangle { fn to_render(&self, _model: &dyn SolverModel) -> Option> { Some(Box::new(*self)) } } */ // TODO: re-enable this in some way /* impl CoreShape for Text { fn constrain( &self, context: &ShapeContext, solver: &mut dyn SolverContext, renderer: &dyn Renderer, ) { let height_constraint = solver.float_eq(context.bounds.height, self.font.size); solver.constrain(height_constraint); // TODO: handle multiline let (width, height) = renderer.text_extents(&self.content, &self.font); dbg!(height); let scale = solver.float_div(self.font.size, Float::Fixed(height)); let calculated_width = solver.float_mul(&[Float::Fixed(width), scale]); let width_constraint = solver.float_eq(context.bounds.width, calculated_width); solver.constrain(width_constraint); } fn to_render(&self, model: &dyn SolverModel) -> Option> { self.fixate(model) .map(|path| -> Box { Box::new(path) }) } } */ #[derive(Clone, Debug, Default)] pub struct StraightPath { pub(crate) points: Vec, } impl StraightPath { pub fn new(points: Vec) -> Self { Self { points } } } pub struct DefinedStraightPath { pub(crate) points: Vec, } /* impl CoreShape for StraightPath { fn to_render(&self, model: &dyn SolverModel) -> Option> { self.fixate(model) .map(|path| -> Box { Box::new(path) }) } } */