title_bar: Fix TitleBar drag area. (#936)
Ref https://github.com/zed-industries/zed/pull/30828 changed new GPUI API for better details for TitleBar drag area.
This commit is contained in:
parent
c5201e6de9
commit
a6b9c96a27
2 changed files with 47 additions and 27 deletions
24
Cargo.lock
generated
24
Cargo.lock
generated
|
|
@ -1226,7 +1226,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "collections"
|
name = "collections"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed.git#b15aef4310e86aa31c2ceab74184ec7e5627a2c5"
|
source = "git+https://github.com/zed-industries/zed.git#047a7f5d290448e026731123e912f8621c806031"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap 2.7.1",
|
"indexmap 2.7.1",
|
||||||
"rustc-hash 2.1.0",
|
"rustc-hash 2.1.0",
|
||||||
|
|
@ -1739,7 +1739,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "derive_refineable"
|
name = "derive_refineable"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed.git#b15aef4310e86aa31c2ceab74184ec7e5627a2c5"
|
source = "git+https://github.com/zed-industries/zed.git#047a7f5d290448e026731123e912f8621c806031"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
@ -2777,7 +2777,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gpui"
|
name = "gpui"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed.git#b15aef4310e86aa31c2ceab74184ec7e5627a2c5"
|
source = "git+https://github.com/zed-industries/zed.git#047a7f5d290448e026731123e912f8621c806031"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"as-raw-xcb-connection",
|
"as-raw-xcb-connection",
|
||||||
|
|
@ -2945,7 +2945,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gpui_macros"
|
name = "gpui_macros"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed.git#b15aef4310e86aa31c2ceab74184ec7e5627a2c5"
|
source = "git+https://github.com/zed-industries/zed.git#047a7f5d290448e026731123e912f8621c806031"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck 0.5.0",
|
"heck 0.5.0",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
|
|
@ -3215,7 +3215,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http_client"
|
name = "http_client"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed.git#b15aef4310e86aa31c2ceab74184ec7e5627a2c5"
|
source = "git+https://github.com/zed-industries/zed.git#047a7f5d290448e026731123e912f8621c806031"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
|
@ -3232,7 +3232,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http_client_tls"
|
name = "http_client_tls"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed.git#b15aef4310e86aa31c2ceab74184ec7e5627a2c5"
|
source = "git+https://github.com/zed-industries/zed.git#047a7f5d290448e026731123e912f8621c806031"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rustls",
|
"rustls",
|
||||||
"rustls-platform-verifier",
|
"rustls-platform-verifier",
|
||||||
|
|
@ -4002,7 +4002,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "media"
|
name = "media"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed.git#b15aef4310e86aa31c2ceab74184ec7e5627a2c5"
|
source = "git+https://github.com/zed-industries/zed.git#047a7f5d290448e026731123e912f8621c806031"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bindgen 0.71.1",
|
"bindgen 0.71.1",
|
||||||
|
|
@ -5719,7 +5719,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "refineable"
|
name = "refineable"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed.git#b15aef4310e86aa31c2ceab74184ec7e5627a2c5"
|
source = "git+https://github.com/zed-industries/zed.git#047a7f5d290448e026731123e912f8621c806031"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"derive_refineable",
|
"derive_refineable",
|
||||||
"workspace-hack",
|
"workspace-hack",
|
||||||
|
|
@ -5829,7 +5829,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reqwest_client"
|
name = "reqwest_client"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed.git#b15aef4310e86aa31c2ceab74184ec7e5627a2c5"
|
source = "git+https://github.com/zed-industries/zed.git#047a7f5d290448e026731123e912f8621c806031"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
|
@ -6378,7 +6378,7 @@ checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semantic_version"
|
name = "semantic_version"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed.git#b15aef4310e86aa31c2ceab74184ec7e5627a2c5"
|
source = "git+https://github.com/zed-industries/zed.git#047a7f5d290448e026731123e912f8621c806031"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
@ -6876,7 +6876,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sum_tree"
|
name = "sum_tree"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed.git#b15aef4310e86aa31c2ceab74184ec7e5627a2c5"
|
source = "git+https://github.com/zed-industries/zed.git#047a7f5d290448e026731123e912f8621c806031"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"log",
|
"log",
|
||||||
|
|
@ -8054,7 +8054,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "util"
|
name = "util"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/zed-industries/zed.git#b15aef4310e86aa31c2ceab74184ec7e5627a2c5"
|
source = "git+https://github.com/zed-industries/zed.git#047a7f5d290448e026731123e912f8621c806031"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-fs 2.1.2",
|
"async-fs 2.1.2",
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@ use std::rc::Rc;
|
||||||
use crate::{h_flex, ActiveTheme, Icon, IconName, InteractiveElementExt as _, Sizable as _};
|
use crate::{h_flex, ActiveTheme, Icon, IconName, InteractiveElementExt as _, Sizable as _};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, prelude::FluentBuilder as _, px, relative, AnyElement, App, ClickEvent, Div, Element,
|
div, prelude::FluentBuilder as _, px, relative, AnyElement, App, ClickEvent, Div, Element,
|
||||||
Hsla, InteractiveElement as _, IntoElement, MouseButton, ParentElement, Pixels, RenderOnce,
|
Hsla, InteractiveElement, IntoElement, MouseButton, ParentElement, Pixels, RenderOnce,
|
||||||
Stateful, StatefulInteractiveElement as _, Style, Styled, TitlebarOptions, Window,
|
Stateful, StatefulInteractiveElement as _, Style, Styled, TitlebarOptions, Window,
|
||||||
|
WindowControlArea,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const TITLE_BAR_HEIGHT: Pixels = px(34.);
|
pub const TITLE_BAR_HEIGHT: Pixels = px(34.);
|
||||||
|
|
@ -26,7 +27,7 @@ pub struct TitleBar {
|
||||||
impl TitleBar {
|
impl TitleBar {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
base: div().id("title-bar").pl(TITLE_BAR_LEFT_PADDING),
|
base: div().id("title-bar"),
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
on_close_window: None,
|
on_close_window: None,
|
||||||
}
|
}
|
||||||
|
|
@ -103,6 +104,14 @@ impl ControlIcon {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn window_control_area(&self) -> WindowControlArea {
|
||||||
|
match self {
|
||||||
|
Self::Minimize => WindowControlArea::Min,
|
||||||
|
Self::Restore | Self::Maximize => WindowControlArea::Max,
|
||||||
|
Self::Close { .. } => WindowControlArea::Close,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn is_close(&self) -> bool {
|
fn is_close(&self) -> bool {
|
||||||
matches!(self, Self::Close { .. })
|
matches!(self, Self::Close { .. })
|
||||||
}
|
}
|
||||||
|
|
@ -140,12 +149,13 @@ impl ControlIcon {
|
||||||
|
|
||||||
impl RenderOnce for ControlIcon {
|
impl RenderOnce for ControlIcon {
|
||||||
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
|
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||||
|
let is_linux = cfg!(target_os = "linux");
|
||||||
|
let is_windows = cfg!(target_os = "windows");
|
||||||
let fg = self.fg(cx);
|
let fg = self.fg(cx);
|
||||||
let hover_fg = self.hover_fg(cx);
|
let hover_fg = self.hover_fg(cx);
|
||||||
let hover_bg = self.hover_bg(cx);
|
let hover_bg = self.hover_bg(cx);
|
||||||
let icon = self.clone();
|
let icon = self.clone();
|
||||||
let is_linux = cfg!(target_os = "linux");
|
let on_close_window = match &self {
|
||||||
let on_close_window = match &icon {
|
|
||||||
ControlIcon::Close { on_close_window } => on_close_window.clone(),
|
ControlIcon::Close { on_close_window } => on_close_window.clone(),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
@ -159,20 +169,25 @@ impl RenderOnce for ControlIcon {
|
||||||
.content_center()
|
.content_center()
|
||||||
.items_center()
|
.items_center()
|
||||||
.text_color(fg)
|
.text_color(fg)
|
||||||
|
.when(is_windows, |this| {
|
||||||
|
this.window_control_area(self.window_control_area())
|
||||||
|
})
|
||||||
.when(is_linux, |this| {
|
.when(is_linux, |this| {
|
||||||
this.on_mouse_down(MouseButton::Left, move |_, window, cx| {
|
this.on_mouse_down(MouseButton::Left, move |_, window, cx| {
|
||||||
window.prevent_default();
|
window.prevent_default();
|
||||||
cx.stop_propagation();
|
cx.stop_propagation();
|
||||||
})
|
})
|
||||||
.on_click(move |_, window, cx| match icon {
|
.on_click(move |_, window, cx| {
|
||||||
Self::Minimize => window.minimize_window(),
|
cx.stop_propagation();
|
||||||
Self::Restore => window.zoom_window(),
|
match icon {
|
||||||
Self::Maximize => window.zoom_window(),
|
Self::Minimize => window.minimize_window(),
|
||||||
Self::Close { .. } => {
|
Self::Restore | Self::Maximize => window.zoom_window(),
|
||||||
if let Some(f) = on_close_window.clone() {
|
Self::Close { .. } => {
|
||||||
f(&ClickEvent::default(), window, cx);
|
if let Some(f) = on_close_window.clone() {
|
||||||
} else {
|
f(&ClickEvent::default(), window, cx);
|
||||||
window.remove_window();
|
} else {
|
||||||
|
window.remove_window();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -243,10 +258,15 @@ impl RenderOnce for TitleBar {
|
||||||
.border_b_1()
|
.border_b_1()
|
||||||
.border_color(cx.theme().title_bar_border)
|
.border_color(cx.theme().title_bar_border)
|
||||||
.bg(cx.theme().title_bar)
|
.bg(cx.theme().title_bar)
|
||||||
.when(window.is_fullscreen(), |this| this.pl(px(12.)))
|
.when(is_linux, |this| {
|
||||||
.on_double_click(|_, window, _| window.zoom_window())
|
this.on_double_click(|_, window, _| window.zoom_window())
|
||||||
|
})
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
|
.id("bar")
|
||||||
|
.pl(TITLE_BAR_LEFT_PADDING)
|
||||||
|
.when(window.is_fullscreen(), |this| this.pl(px(12.)))
|
||||||
|
.window_control_area(WindowControlArea::Drag)
|
||||||
.h_full()
|
.h_full()
|
||||||
.justify_between()
|
.justify_between()
|
||||||
.flex_shrink_0()
|
.flex_shrink_0()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue