layer-shika/src/windowing/builder.rs

93 lines
2.3 KiB
Rust

use super::{
config::{Margins, WindowConfig},
WindowingSystem,
};
use crate::errors::Result;
use slint_interpreter::ComponentDefinition;
use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::{
zwlr_layer_shell_v1::{self},
zwlr_layer_surface_v1::{Anchor, KeyboardInteractivity},
};
use std::marker::PhantomData;
pub struct NeedsComponent;
pub struct HasComponent;
pub struct WindowingSystemBuilder<State = NeedsComponent> {
config: WindowConfig,
_state: PhantomData<State>,
}
impl WindowingSystemBuilder<NeedsComponent> {
#[inline]
#[must_use]
pub fn new(component_definition: ComponentDefinition) -> WindowingSystemBuilder<HasComponent> {
WindowingSystemBuilder {
config: WindowConfig::new(component_definition),
_state: PhantomData,
}
}
}
impl WindowingSystemBuilder<HasComponent> {
#[must_use]
pub const fn with_height(mut self, height: u32) -> Self {
self.config.height = height;
self
}
#[must_use]
pub const fn with_layer(mut self, layer: zwlr_layer_shell_v1::Layer) -> Self {
self.config.layer = layer;
self
}
#[must_use]
pub const fn with_margin(mut self, top: i32, right: i32, bottom: i32, left: i32) -> Self {
self.config.margin = Margins {
top,
right,
bottom,
left,
};
self
}
#[must_use]
pub const fn with_anchor(mut self, anchor: Anchor) -> Self {
self.config.anchor = anchor;
self
}
#[must_use]
pub const fn with_keyboard_interactivity(
mut self,
interactivity: KeyboardInteractivity,
) -> Self {
self.config.keyboard_interactivity = interactivity;
self
}
#[must_use]
pub const fn with_exclusive_zone(mut self, zone: i32) -> Self {
self.config.exclusive_zone = zone;
self
}
#[must_use]
pub fn with_namespace(mut self, namespace: String) -> Self {
self.config.namespace = namespace;
self
}
#[must_use]
pub const fn with_scale_factor(mut self, scale_factor: f32) -> Self {
self.config.scale_factor = scale_factor;
self
}
#[allow(clippy::missing_errors_doc)]
pub fn build(self) -> Result<WindowingSystem> {
WindowingSystem::new(self.config)
}
}