Improve popup snap to window with margin. (#225)

- Also update GPUI.

Ref: https://github.com/zed-industries/zed/pull/17159

<img width="866" alt="image"
src="https://github.com/user-attachments/assets/0737e4e4-7069-4554-a766-b9fc7b487fd6">
This commit is contained in:
Jason Lee 2024-09-07 11:50:38 +08:00 committed by GitHub
parent b6374313b2
commit 821487bed5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 27 additions and 25 deletions

36
Cargo.lock generated
View file

@ -474,7 +474,7 @@ dependencies = [
"bitflags 2.6.0",
"cexpr",
"clang-sys",
"itertools 0.11.0",
"itertools 0.13.0",
"log",
"prettyplease",
"proc-macro2",
@ -526,8 +526,8 @@ checksum = "3dcde5f311c85b8ca30c2e4198d4326bc342c76541590106f5fa4a50946ea499"
[[package]]
name = "blade-graphics"
version = "0.4.0"
source = "git+https://github.com/kvark/blade?rev=fee06c42f658b36dd9ac85444a9ee2a481383695#fee06c42f658b36dd9ac85444a9ee2a481383695"
version = "0.5.0"
source = "git+https://github.com/kvark/blade?rev=e142a3a5e678eb6a13e642ad8401b1f3aa38e969#e142a3a5e678eb6a13e642ad8401b1f3aa38e969"
dependencies = [
"ash",
"ash-window",
@ -556,8 +556,8 @@ dependencies = [
[[package]]
name = "blade-macros"
version = "0.2.1"
source = "git+https://github.com/kvark/blade?rev=fee06c42f658b36dd9ac85444a9ee2a481383695#fee06c42f658b36dd9ac85444a9ee2a481383695"
version = "0.3.0"
source = "git+https://github.com/kvark/blade?rev=e142a3a5e678eb6a13e642ad8401b1f3aa38e969#e142a3a5e678eb6a13e642ad8401b1f3aa38e969"
dependencies = [
"proc-macro2",
"quote",
@ -567,7 +567,7 @@ dependencies = [
[[package]]
name = "blade-util"
version = "0.1.0"
source = "git+https://github.com/kvark/blade?rev=fee06c42f658b36dd9ac85444a9ee2a481383695#fee06c42f658b36dd9ac85444a9ee2a481383695"
source = "git+https://github.com/kvark/blade?rev=e142a3a5e678eb6a13e642ad8401b1f3aa38e969#e142a3a5e678eb6a13e642ad8401b1f3aa38e969"
dependencies = [
"blade-graphics",
"bytemuck",
@ -944,7 +944,7 @@ dependencies = [
[[package]]
name = "collections"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#4f7507eb244527afcab0c186b39eba047d11a158"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#8e26a498fd91c68361d4e314bfe05244728d3246"
dependencies = [
"rustc-hash",
]
@ -1275,7 +1275,7 @@ dependencies = [
[[package]]
name = "derive_refineable"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#4f7507eb244527afcab0c186b39eba047d11a158"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#8e26a498fd91c68361d4e314bfe05244728d3246"
dependencies = [
"proc-macro2",
"quote",
@ -2149,9 +2149,9 @@ dependencies = [
[[package]]
name = "glow"
version = "0.13.1"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd348e04c43b32574f2de31c8bb397d96c9fcfa1371bd4ca6d8bdc464ab121b1"
checksum = "f865cbd94bd355b89611211e49508da98a1fce0ad755c1e8448fb96711b24528"
dependencies = [
"js-sys",
"slotmap",
@ -2203,7 +2203,7 @@ dependencies = [
[[package]]
name = "gpui"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#4f7507eb244527afcab0c186b39eba047d11a158"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#8e26a498fd91c68361d4e314bfe05244728d3246"
dependencies = [
"anyhow",
"as-raw-xcb-connection",
@ -2302,7 +2302,7 @@ dependencies = [
[[package]]
name = "gpui_macros"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#4f7507eb244527afcab0c186b39eba047d11a158"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#8e26a498fd91c68361d4e314bfe05244728d3246"
dependencies = [
"proc-macro2",
"quote",
@ -2497,7 +2497,7 @@ dependencies = [
[[package]]
name = "http_client"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#4f7507eb244527afcab0c186b39eba047d11a158"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#8e26a498fd91c68361d4e314bfe05244728d3246"
dependencies = [
"anyhow",
"derive_more",
@ -3048,7 +3048,7 @@ dependencies = [
[[package]]
name = "media"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#4f7507eb244527afcab0c186b39eba047d11a158"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#8e26a498fd91c68361d4e314bfe05244728d3246"
dependencies = [
"anyhow",
"bindgen",
@ -4149,7 +4149,7 @@ dependencies = [
[[package]]
name = "refineable"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#4f7507eb244527afcab0c186b39eba047d11a158"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#8e26a498fd91c68361d4e314bfe05244728d3246"
dependencies = [
"derive_refineable",
]
@ -4484,7 +4484,7 @@ checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a"
[[package]]
name = "semantic_version"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#4f7507eb244527afcab0c186b39eba047d11a158"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#8e26a498fd91c68361d4e314bfe05244728d3246"
dependencies = [
"anyhow",
"serde",
@ -4932,7 +4932,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "sum_tree"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#4f7507eb244527afcab0c186b39eba047d11a158"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#8e26a498fd91c68361d4e314bfe05244728d3246"
dependencies = [
"arrayvec",
"log",
@ -5551,7 +5551,7 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "util"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#4f7507eb244527afcab0c186b39eba047d11a158"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#8e26a498fd91c68361d4e314bfe05244728d3246"
dependencies = [
"anyhow",
"async-fs 1.6.0",

View file

@ -338,7 +338,7 @@ impl Render for ColorPicker {
deferred(
anchored()
.anchor(self.anchor)
.snap_to_window()
.snap_to_window_with_margin(px(8.))
.position(self.resolved_corner(self.bounds))
.child(
div()

View file

@ -1,7 +1,7 @@
use std::{cell::RefCell, rc::Rc};
use gpui::{
anchored, deferred, div, prelude::FluentBuilder, relative, AnchorCorner, AnyElement,
anchored, deferred, div, prelude::FluentBuilder, px, relative, AnchorCorner, AnyElement,
AppContext, DismissEvent, DispatchPhase, Element, ElementId, Focusable, GlobalElementId,
IntoElement, MouseButton, MouseDownEvent, ParentElement, Pixels, Point, Position, Stateful,
Style, View, ViewContext, WindowContext,
@ -120,7 +120,7 @@ impl Element for ContextMenu {
let mut menu_element = deferred(
anchored()
.position(*position)
.snap_to_window()
.snap_to_window_with_margin(px(8.))
.anchor(anchor)
.when_some(menu_view, |this, menu| {
// Focus the menu, so that can be handle the action.

View file

@ -662,7 +662,7 @@ where
.when(self.open, |this| {
this.child(
deferred(
anchored().snap_to_window().child(
anchored().snap_to_window_with_margin(px(8.)).child(
div()
.occlude()
.map(|this| match self.menu_width {

View file

@ -1,5 +1,5 @@
use gpui::{
actions, anchored, deferred, div, prelude::FluentBuilder as _, AnchorCorner, AnyElement,
actions, anchored, deferred, div, prelude::FluentBuilder as _, px, AnchorCorner, AnyElement,
AppContext, Bounds, DismissEvent, DispatchPhase, Element, ElementId, EventEmitter, FocusHandle,
FocusableView, GlobalElementId, Hitbox, InteractiveElement as _, IntoElement, KeyBinding,
LayoutId, ManagedView, MouseButton, MouseDownEvent, ParentElement, Pixels, Point, Render,
@ -230,7 +230,9 @@ impl<M: ManagedView> Element for Popover<M> {
if let Some(content_view) = element_state.content_view.borrow_mut().as_mut() {
is_open = true;
let mut anchored = anchored().snap_to_window().anchor(view.anchor);
let mut anchored = anchored()
.snap_to_window_with_margin(px(8.))
.anchor(view.anchor);
if let Some(trigger_bounds) = element_state.trigger_bounds {
anchored = anchored.position(view.resolved_corner(trigger_bounds));
}

View file

@ -244,7 +244,7 @@ impl Render for DatePicker {
.when(self.open, |this| {
this.child(
deferred(
anchored().snap_to_window().child(
anchored().snap_to_window_with_margin(px(8.)).child(
div()
.track_focus(&self.focus_handle)
.occlude()