mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2025-11-17 23:14:23 +00:00
refactor: fallback at default on height
This commit is contained in:
parent
02c00d28cb
commit
eb8e19cb9e
3 changed files with 11 additions and 15 deletions
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()?;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue