modal: Fix Model, Drawer overlay size on tiling mode. (#518)
This commit is contained in:
parent
6851e53183
commit
0327df323d
5 changed files with 58 additions and 26 deletions
|
|
@ -1,6 +1,5 @@
|
|||
use anyhow::{Context, Result};
|
||||
use gpui::*;
|
||||
use prelude::FluentBuilder as _;
|
||||
use std::time::Duration;
|
||||
use story::{Assets, ButtonStory, IconStory, StoryContainer};
|
||||
use ui::{
|
||||
|
|
@ -159,12 +158,12 @@ impl StoryTiles {
|
|||
}
|
||||
|
||||
pub fn new_local(cx: &mut AppContext) -> Task<anyhow::Result<WindowHandle<Root>>> {
|
||||
let display_size = cx.primary_display().unwrap().bounds().size;
|
||||
let window_size = size(
|
||||
px(1600.0).min(display_size.width * 0.85),
|
||||
px(1200.0).min(display_size.height * 0.85),
|
||||
);
|
||||
|
||||
let mut window_size = size(px(1600.0), px(1200.0));
|
||||
if let Some(display) = cx.primary_display() {
|
||||
let display_size = display.bounds().size;
|
||||
window_size.width = window_size.width.min(display_size.width * 0.85);
|
||||
window_size.height = window_size.height.min(display_size.height * 0.85);
|
||||
}
|
||||
let window_bounds = Bounds::centered(None, window_size, cx);
|
||||
|
||||
cx.spawn(|mut cx| async move {
|
||||
|
|
|
|||
|
|
@ -332,11 +332,12 @@ impl StoryWorkspace {
|
|||
}
|
||||
|
||||
pub fn new_local(cx: &mut AppContext) -> Task<anyhow::Result<WindowHandle<Root>>> {
|
||||
let display_size = cx.primary_display().unwrap().bounds().size;
|
||||
let window_size = size(
|
||||
px(1600.0).min(display_size.width * 0.85),
|
||||
px(1200.0).min(display_size.height * 0.85),
|
||||
);
|
||||
let mut window_size = size(px(1600.0), px(1200.0));
|
||||
if let Some(display) = cx.primary_display() {
|
||||
let display_size = display.bounds().size;
|
||||
window_size.width = window_size.width.min(display_size.width * 0.85);
|
||||
window_size.height = window_size.height.min(display_size.height * 0.85);
|
||||
}
|
||||
|
||||
let window_bounds = Bounds::centered(None, window_size, cx);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,9 +15,7 @@ use crate::{
|
|||
scroll::ScrollbarAxis,
|
||||
theme::ActiveTheme,
|
||||
title_bar::TITLE_BAR_HEIGHT,
|
||||
v_flex,
|
||||
window_border::SHADOW_SIZE,
|
||||
IconName, Placement, Sizable, StyledExt as _,
|
||||
v_flex, IconName, Placement, Sizable, StyledExt as _,
|
||||
};
|
||||
|
||||
actions!(drawer, [Escape]);
|
||||
|
|
@ -121,11 +119,19 @@ impl RenderOnce for Drawer {
|
|||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
let placement = self.placement;
|
||||
let titlebar_height = self.margin_top;
|
||||
let size = cx.viewport_size() - gpui::size(SHADOW_SIZE * 2, SHADOW_SIZE * 2);
|
||||
let window_paddings = crate::window_border::window_paddings(cx);
|
||||
let size = cx.viewport_size()
|
||||
- gpui::size(
|
||||
window_paddings.left + window_paddings.right,
|
||||
window_paddings.top + window_paddings.bottom,
|
||||
);
|
||||
let on_close = self.on_close.clone();
|
||||
|
||||
anchored()
|
||||
.position(point(px(0.) + SHADOW_SIZE, titlebar_height + SHADOW_SIZE))
|
||||
.position(point(
|
||||
window_paddings.left,
|
||||
window_paddings.top + titlebar_height - px(1.),
|
||||
))
|
||||
.snap_to_window()
|
||||
.child(
|
||||
div()
|
||||
|
|
|
|||
|
|
@ -11,9 +11,7 @@ use crate::{
|
|||
animation::cubic_bezier,
|
||||
button::{Button, ButtonVariants as _},
|
||||
theme::ActiveTheme as _,
|
||||
v_flex,
|
||||
window_border::SHADOW_SIZE,
|
||||
ContextModal, IconName, Sizable as _,
|
||||
v_flex, ContextModal, IconName, Sizable as _,
|
||||
};
|
||||
|
||||
actions!(modal, [Escape]);
|
||||
|
|
@ -164,7 +162,12 @@ impl RenderOnce for Modal {
|
|||
fn render(self, cx: &mut WindowContext) -> impl gpui::IntoElement {
|
||||
let layer_ix = self.layer_ix;
|
||||
let on_close = self.on_close.clone();
|
||||
let view_size = cx.viewport_size() - gpui::size(SHADOW_SIZE * 2, SHADOW_SIZE * 2);
|
||||
let window_paddings = crate::window_border::window_paddings(cx);
|
||||
let view_size = cx.viewport_size()
|
||||
- gpui::size(
|
||||
window_paddings.left + window_paddings.right,
|
||||
window_paddings.top + window_paddings.bottom,
|
||||
);
|
||||
let bounds = Bounds {
|
||||
origin: Point::default(),
|
||||
size: view_size,
|
||||
|
|
@ -174,7 +177,7 @@ impl RenderOnce for Modal {
|
|||
let x = bounds.center().x - self.width / 2.;
|
||||
|
||||
anchored()
|
||||
.position(point(SHADOW_SIZE, SHADOW_SIZE))
|
||||
.position(point(window_paddings.left, window_paddings.top))
|
||||
.snap_to_window()
|
||||
.child(
|
||||
div()
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@
|
|||
// https://github.com/zed-industries/zed/blob/a8afc63a91f6b75528540dcffe73dc8ce0c92ad8/crates/gpui/examples/window_shadow.rs
|
||||
use gpui::{
|
||||
canvas, div, point, prelude::FluentBuilder as _, px, AnyElement, Bounds, CursorStyle,
|
||||
Decorations, Hsla, InteractiveElement as _, IntoElement, MouseButton, ParentElement, Pixels,
|
||||
Point, RenderOnce, ResizeEdge, Size, Styled as _, WindowContext,
|
||||
Decorations, Edges, Hsla, InteractiveElement as _, IntoElement, MouseButton, ParentElement,
|
||||
Pixels, Point, RenderOnce, ResizeEdge, Size, Styled as _, WindowContext,
|
||||
};
|
||||
|
||||
use crate::theme::ActiveTheme;
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub(crate) const SHADOW_SIZE: Pixels = Pixels(0.0);
|
||||
const SHADOW_SIZE: Pixels = Pixels(0.0);
|
||||
#[cfg(target_os = "linux")]
|
||||
pub(crate) const SHADOW_SIZE: Pixels = Pixels(12.0);
|
||||
const SHADOW_SIZE: Pixels = Pixels(12.0);
|
||||
const BORDER_SIZE: Pixels = Pixels(1.0);
|
||||
pub(crate) const BORDER_RADIUS: Pixels = Pixels(0.0);
|
||||
|
||||
|
|
@ -34,6 +34,29 @@ impl WindowBorder {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get the window paddings.
|
||||
pub fn window_paddings(cx: &WindowContext) -> Edges<Pixels> {
|
||||
match cx.window_decorations() {
|
||||
Decorations::Server => Edges::all(px(0.0)),
|
||||
Decorations::Client { tiling } => {
|
||||
let mut paddings = Edges::all(SHADOW_SIZE);
|
||||
if tiling.top {
|
||||
paddings.top = px(0.0);
|
||||
}
|
||||
if tiling.bottom {
|
||||
paddings.bottom = px(0.0);
|
||||
}
|
||||
if tiling.left {
|
||||
paddings.left = px(0.0);
|
||||
}
|
||||
if tiling.right {
|
||||
paddings.right = px(0.0);
|
||||
}
|
||||
paddings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ParentElement for WindowBorder {
|
||||
fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
|
||||
self.children.extend(elements);
|
||||
|
|
|
|||
Loading…
Reference in a new issue