From bc46570971a7466ae05b0d47b12a80d85bd7dbf3 Mon Sep 17 00:00:00 2001 From: drendog Date: Mon, 3 Nov 2025 08:53:33 +0100 Subject: [PATCH] refactor: remove redundancy between component def and compilation result --- composition/src/builder.rs | 50 +++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/composition/src/builder.rs b/composition/src/builder.rs index 641af42..55524b6 100644 --- a/composition/src/builder.rs +++ b/composition/src/builder.rs @@ -1,8 +1,6 @@ use crate::Result; use crate::system::WindowingSystem; -use layer_shika_adapters::platform::slint_interpreter::{ - CompilationResult, Compiler, ComponentDefinition, -}; +use layer_shika_adapters::platform::slint_interpreter::{CompilationResult, Compiler}; use layer_shika_domain::errors::DomainError; use layer_shika_domain::prelude::{ AnchorEdges, KeyboardInteractivity, Layer, Margins, WindowConfig, @@ -13,8 +11,8 @@ use std::rc::Rc; pub struct NeedsComponent; pub struct HasComponent { - component_definition: ComponentDefinition, - compilation_result: Option>, + component_name: String, + compilation_result: Rc, } pub struct LayerShika { @@ -24,11 +22,14 @@ pub struct LayerShika { impl LayerShika { #[must_use] - pub fn new(component_definition: ComponentDefinition) -> LayerShika { + pub fn new( + compilation_result: Rc, + component_name: impl Into, + ) -> LayerShika { LayerShika { state: HasComponent { - component_definition, - compilation_result: None, + component_name: component_name.into(), + compilation_result, }, config: WindowConfig::default(), } @@ -64,7 +65,7 @@ impl LayerShika { .into()); } - let definition = compilation_result + compilation_result .component(component_name) .ok_or_else(|| DomainError::Configuration { message: format!( @@ -76,8 +77,8 @@ impl LayerShika { Ok(LayerShika { state: HasComponent { - component_definition: definition, - compilation_result: Some(Rc::new(compilation_result)), + component_name: component_name.to_string(), + compilation_result: Rc::new(compilation_result), }, config: WindowConfig::default(), }) @@ -114,7 +115,7 @@ impl LayerShika { .into()); } - let definition = compilation_result + compilation_result .component(component_name) .ok_or_else(|| DomainError::Configuration { message: format!( @@ -125,8 +126,8 @@ impl LayerShika { Ok(LayerShika { state: HasComponent { - component_definition: definition, - compilation_result: Some(Rc::new(compilation_result)), + component_name: component_name.to_string(), + compilation_result: Rc::new(compilation_result), }, config: WindowConfig::default(), }) @@ -134,12 +135,6 @@ impl LayerShika { } impl LayerShika { - #[must_use] - pub fn with_compilation_result(mut self, compilation_result: Rc) -> Self { - self.state.compilation_result = Some(compilation_result); - self - } - #[must_use] pub const fn with_height(mut self, height: u32) -> Self { self.config.height = height; @@ -194,9 +189,20 @@ impl LayerShika { } pub fn build(self) -> Result { + let component_definition = self + .state + .compilation_result + .component(&self.state.component_name) + .ok_or_else(|| DomainError::Configuration { + message: format!( + "Component '{}' not found in compilation result", + self.state.component_name + ), + })?; + WindowingSystem::new( - self.state.component_definition, - self.state.compilation_result, + component_definition, + Some(self.state.compilation_result), self.config, ) }