refactor: fallback at default on height

This commit is contained in:
drendog 2025-11-16 21:53:34 +01:00
parent 02c00d28cb
commit eb8e19cb9e
Signed by: dwenya
GPG key ID: 8DD77074645332D0
3 changed files with 11 additions and 15 deletions

View file

@ -135,9 +135,10 @@ impl LayerShika<NeedsComponent> {
} }
impl LayerShika<HasComponent> { impl LayerShika<HasComponent> {
pub fn with_height(mut self, height: u32) -> Result<Self> { #[must_use]
self.config.height = WindowHeight::new(height)?; pub fn with_height(mut self, height: u32) -> Self {
Ok(self) self.config.height = WindowHeight::new(height);
self
} }
#[must_use] #[must_use]

View file

@ -1,17 +1,14 @@
use crate::errors::{DomainError, Result};
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct WindowHeight(u32); pub struct WindowHeight(u32);
impl WindowHeight { impl WindowHeight {
pub fn new(height: u32) -> Result<Self> { pub fn new(height: u32) -> Self {
if height == 0 { if height == 0 {
return Err(DomainError::InvalidDimensions { Self::default()
width: 0, } else {
height: 0, Self(height)
});
} }
Ok(Self(height))
} }
pub const fn from_raw(height: u32) -> Self { pub const fn from_raw(height: u32) -> Self {
@ -29,10 +26,8 @@ impl Default for WindowHeight {
} }
} }
impl TryFrom<u32> for WindowHeight { impl From<u32> for WindowHeight {
type Error = DomainError; fn from(height: u32) -> Self {
fn try_from(height: u32) -> Result<Self> {
Self::new(height) Self::new(height)
} }
} }

View file

@ -23,7 +23,7 @@
//! use layer_shika::prelude::*; //! use layer_shika::prelude::*;
//! //!
//! let (window, system) = LayerShika::from_file("ui/main.slint", "AppWindow")? //! let (window, system) = LayerShika::from_file("ui/main.slint", "AppWindow")?
//! .with_height(42)? //! .with_height(42)
//! .with_anchor(AnchorEdges::top_bar()) //! .with_anchor(AnchorEdges::top_bar())
//! .with_exclusive_zone(42) //! .with_exclusive_zone(42)
//! .build()?; //! .build()?;