Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion crates/ui/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ pub struct Root {
pub notification: Entity<NotificationList>,
sheet_size: Option<DefiniteLength>,
view: AnyView,
is_resizable: bool,
}

#[derive(Clone)]
Expand All @@ -244,9 +245,20 @@ impl Root {
notification: cx.new(|cx| NotificationList::new(window, cx)),
sheet_size: None,
view,
is_resizable: true,
}
}

pub fn set_resizable(&mut self, enabled: bool) -> &mut Self {
self.is_resizable = enabled;
self
}

pub fn with_resizable(mut self, enabled: bool) -> Self {
self.is_resizable = enabled;
self
}

pub fn update<F, R>(window: &mut Window, cx: &mut App, f: F) -> R
where
F: FnOnce(&mut Self, &mut Window, &mut Context<Self>) -> R,
Expand Down Expand Up @@ -390,7 +402,9 @@ impl Render for Root {
let base_font_size = cx.theme().font_size;
window.set_rem_size(base_font_size);

window_border().child(
window_border()
.with_resizable(self.is_resizable)
.child(
div()
.id("root")
.key_context(CONTEXT)
Expand Down
18 changes: 18 additions & 0 deletions crates/ui/src/window_border.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,27 @@ pub fn window_border() -> WindowBorder {
/// Window border use to render a custom window border and shadow for Linux.
#[derive(IntoElement, Default)]
pub struct WindowBorder {
is_resizable: bool,
children: Vec<AnyElement>,
}

impl WindowBorder {
pub fn new() -> Self {
Self {
is_resizable: true,
..Default::default()
}
}

pub fn set_resizable(&mut self, resizable: bool) -> &mut Self {
self.is_resizable = resizable;
self
}

pub fn with_resizable(mut self, resizable: bool) -> Self {
self.is_resizable = resizable;
self
}
}

/// Get the window paddings.
Expand Down Expand Up @@ -87,6 +99,9 @@ impl RenderOnce for WindowBorder {
)
},
move |_bounds, hitbox, window, _| {
if !self.is_resizable {
return;
}
let mouse = window.mouse_position();
let size = window.window_bounds().get_bounds().size;
let Some(edge) = resize_edge(mouse, SHADOW_SIZE, size) else {
Expand Down Expand Up @@ -125,6 +140,9 @@ impl RenderOnce for WindowBorder {
.when(!tiling.left, |div| div.pl(SHADOW_SIZE))
.when(!tiling.right, |div| div.pr(SHADOW_SIZE))
.on_mouse_down(MouseButton::Left, move |_, window, _| {
if !self.is_resizable {
return;
}
let size = window.window_bounds().get_bounds().size;
let pos = window.mouse_position();

Expand Down