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> {
pub fn with_height(mut self, height: u32) -> Result<Self> {
self.config.height = WindowHeight::new(height)?;
Ok(self)
#[must_use]
pub fn with_height(mut self, height: u32) -> Self {
self.config.height = WindowHeight::new(height);
self
}
#[must_use]

View file

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

View file

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