tauri_plugin_snap_layout/
lib.rs1use tauri::{plugin::TauriPlugin, Manager, Runtime};
2
3mod desktop;
4mod error;
5
6pub use desktop::Snap;
7pub use error::{Error, Result};
8
9#[cfg(windows)]
10#[path = "lib_win_impl.rs"]
11mod platform;
12
13#[cfg(windows)]
14pub use platform::SnapCursor;
15
16#[cfg(not(windows))]
17#[path = "lib_dummy_impl.rs"]
18mod platform;
19
20#[cfg(not(windows))]
21#[derive(Debug, Clone, Copy, PartialEq)]
22pub enum SnapCursor {
23 Arrow,
24 Hand,
25}
26
27pub struct SnapLayoutArea {
28 inner: platform::AreaBuilder,
29}
30
31impl Default for SnapLayoutArea {
32 fn default() -> Self {
33 Self::new()
34 }
35}
36
37impl SnapLayoutArea {
38 pub fn new() -> Self {
39 Self {
40 inner: platform::AreaBuilder::new(),
41 }
42 }
43 pub fn button_id(mut self, id: impl Into<String>) -> Self {
44 self.inner = self.inner.button_id(id);
45 self
46 }
47 pub fn padding_left(mut self, padding_left: i32) -> Self {
48 self.inner = self.inner.padding_left(padding_left);
49 self
50 }
51 pub fn padding_right(mut self, padding_right: i32) -> Self {
52 self.inner = self.inner.padding_right(padding_right);
53 self
54 }
55 pub fn padding_top(mut self, padding_top: i32) -> Self {
56 self.inner = self.inner.padding_top(padding_top);
57 self
58 }
59 pub fn padding_bottom(mut self, padding_bottom: i32) -> Self {
60 self.inner = self.inner.padding_bottom(padding_bottom);
61 self
62 }
63 pub fn padding_all(mut self, padding_all: i32) -> Self {
64 self.inner = self.inner.padding_all(padding_all);
65 self
66 }
67 pub fn display(mut self, is_display: bool) -> Self {
68 self.inner = self.inner.display(is_display);
69 self
70 }
71 pub fn debug_color(mut self, color: impl Into<String>) -> Self {
72 self.inner = self.inner.debug_color(color);
73 self
74 }
75 pub fn cursor(mut self, cursor: SnapCursor) -> Self {
76 self.inner = self.inner.cursor(cursor);
77 self
78 }
79 pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
80 self.inner.build()
81 }
82}
83
84pub fn init() -> SnapLayoutArea {
85 SnapLayoutArea::new()
86}
87
88pub trait SnapExt<R: Runtime> {
89 fn snap(&self) -> &Snap<R>;
90}
91impl<R: Runtime, T: Manager<R>> SnapExt<R> for T {
92 fn snap(&self) -> &Snap<R> {
93 self.state::<Snap<R>>().inner()
94 }
95}