mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2025-11-03 22:34:23 +00:00
refactor: remove redundancy between component def and compilation result
This commit is contained in:
parent
898568f358
commit
bc46570971
1 changed files with 28 additions and 22 deletions
|
|
@ -1,8 +1,6 @@
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
use crate::system::WindowingSystem;
|
use crate::system::WindowingSystem;
|
||||||
use layer_shika_adapters::platform::slint_interpreter::{
|
use layer_shika_adapters::platform::slint_interpreter::{CompilationResult, Compiler};
|
||||||
CompilationResult, Compiler, ComponentDefinition,
|
|
||||||
};
|
|
||||||
use layer_shika_domain::errors::DomainError;
|
use layer_shika_domain::errors::DomainError;
|
||||||
use layer_shika_domain::prelude::{
|
use layer_shika_domain::prelude::{
|
||||||
AnchorEdges, KeyboardInteractivity, Layer, Margins, WindowConfig,
|
AnchorEdges, KeyboardInteractivity, Layer, Margins, WindowConfig,
|
||||||
|
|
@ -13,8 +11,8 @@ use std::rc::Rc;
|
||||||
|
|
||||||
pub struct NeedsComponent;
|
pub struct NeedsComponent;
|
||||||
pub struct HasComponent {
|
pub struct HasComponent {
|
||||||
component_definition: ComponentDefinition,
|
component_name: String,
|
||||||
compilation_result: Option<Rc<CompilationResult>>,
|
compilation_result: Rc<CompilationResult>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LayerShika<State> {
|
pub struct LayerShika<State> {
|
||||||
|
|
@ -24,11 +22,14 @@ pub struct LayerShika<State> {
|
||||||
|
|
||||||
impl LayerShika<NeedsComponent> {
|
impl LayerShika<NeedsComponent> {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(component_definition: ComponentDefinition) -> LayerShika<HasComponent> {
|
pub fn new(
|
||||||
|
compilation_result: Rc<CompilationResult>,
|
||||||
|
component_name: impl Into<String>,
|
||||||
|
) -> LayerShika<HasComponent> {
|
||||||
LayerShika {
|
LayerShika {
|
||||||
state: HasComponent {
|
state: HasComponent {
|
||||||
component_definition,
|
component_name: component_name.into(),
|
||||||
compilation_result: None,
|
compilation_result,
|
||||||
},
|
},
|
||||||
config: WindowConfig::default(),
|
config: WindowConfig::default(),
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +65,7 @@ impl LayerShika<NeedsComponent> {
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let definition = compilation_result
|
compilation_result
|
||||||
.component(component_name)
|
.component(component_name)
|
||||||
.ok_or_else(|| DomainError::Configuration {
|
.ok_or_else(|| DomainError::Configuration {
|
||||||
message: format!(
|
message: format!(
|
||||||
|
|
@ -76,8 +77,8 @@ impl LayerShika<NeedsComponent> {
|
||||||
|
|
||||||
Ok(LayerShika {
|
Ok(LayerShika {
|
||||||
state: HasComponent {
|
state: HasComponent {
|
||||||
component_definition: definition,
|
component_name: component_name.to_string(),
|
||||||
compilation_result: Some(Rc::new(compilation_result)),
|
compilation_result: Rc::new(compilation_result),
|
||||||
},
|
},
|
||||||
config: WindowConfig::default(),
|
config: WindowConfig::default(),
|
||||||
})
|
})
|
||||||
|
|
@ -114,7 +115,7 @@ impl LayerShika<NeedsComponent> {
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let definition = compilation_result
|
compilation_result
|
||||||
.component(component_name)
|
.component(component_name)
|
||||||
.ok_or_else(|| DomainError::Configuration {
|
.ok_or_else(|| DomainError::Configuration {
|
||||||
message: format!(
|
message: format!(
|
||||||
|
|
@ -125,8 +126,8 @@ impl LayerShika<NeedsComponent> {
|
||||||
|
|
||||||
Ok(LayerShika {
|
Ok(LayerShika {
|
||||||
state: HasComponent {
|
state: HasComponent {
|
||||||
component_definition: definition,
|
component_name: component_name.to_string(),
|
||||||
compilation_result: Some(Rc::new(compilation_result)),
|
compilation_result: Rc::new(compilation_result),
|
||||||
},
|
},
|
||||||
config: WindowConfig::default(),
|
config: WindowConfig::default(),
|
||||||
})
|
})
|
||||||
|
|
@ -134,12 +135,6 @@ impl LayerShika<NeedsComponent> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayerShika<HasComponent> {
|
impl LayerShika<HasComponent> {
|
||||||
#[must_use]
|
|
||||||
pub fn with_compilation_result(mut self, compilation_result: Rc<CompilationResult>) -> Self {
|
|
||||||
self.state.compilation_result = Some(compilation_result);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn with_height(mut self, height: u32) -> Self {
|
pub const fn with_height(mut self, height: u32) -> Self {
|
||||||
self.config.height = height;
|
self.config.height = height;
|
||||||
|
|
@ -194,9 +189,20 @@ impl LayerShika<HasComponent> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(self) -> Result<WindowingSystem> {
|
pub fn build(self) -> Result<WindowingSystem> {
|
||||||
|
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(
|
WindowingSystem::new(
|
||||||
self.state.component_definition,
|
component_definition,
|
||||||
self.state.compilation_result,
|
Some(self.state.compilation_result),
|
||||||
self.config,
|
self.config,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue