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]]
|
||||
name = "collections"
|
||||
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 = [
|
||||
"indexmap 2.7.1",
|
||||
"rustc-hash 2.1.0",
|
||||
|
|
@ -1739,7 +1739,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "derive_refineable"
|
||||
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 = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -2777,7 +2777,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gpui"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"as-raw-xcb-connection",
|
||||
|
|
@ -2945,7 +2945,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gpui_macros"
|
||||
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 = [
|
||||
"heck 0.5.0",
|
||||
"proc-macro2",
|
||||
|
|
@ -3215,7 +3215,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "http_client"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
|
|
@ -3232,7 +3232,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "http_client_tls"
|
||||
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 = [
|
||||
"rustls",
|
||||
"rustls-platform-verifier",
|
||||
|
|
@ -4002,7 +4002,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "media"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"bindgen 0.71.1",
|
||||
|
|
@ -5719,7 +5719,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "refineable"
|
||||
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 = [
|
||||
"derive_refineable",
|
||||
"workspace-hack",
|
||||
|
|
@ -5829,7 +5829,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "reqwest_client"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
|
|
@ -6378,7 +6378,7 @@ checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a"
|
|||
[[package]]
|
||||
name = "semantic_version"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"serde",
|
||||
|
|
@ -6876,7 +6876,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
|||
[[package]]
|
||||
name = "sum_tree"
|
||||
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 = [
|
||||
"arrayvec",
|
||||
"log",
|
||||
|
|
@ -8054,7 +8054,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
|||
[[package]]
|
||||
name = "util"
|
||||
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 = [
|
||||
"anyhow",
|
||||
"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 gpui::{
|
||||
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,
|
||||
WindowControlArea,
|
||||
};
|
||||
|
||||
pub const TITLE_BAR_HEIGHT: Pixels = px(34.);
|
||||
|
|
@ -26,7 +27,7 @@ pub struct TitleBar {
|
|||
impl TitleBar {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
base: div().id("title-bar").pl(TITLE_BAR_LEFT_PADDING),
|
||||
base: div().id("title-bar"),
|
||||
children: Vec::new(),
|
||||
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 {
|
||||
matches!(self, Self::Close { .. })
|
||||
}
|
||||
|
|
@ -140,12 +149,13 @@ impl ControlIcon {
|
|||
|
||||
impl RenderOnce for ControlIcon {
|
||||
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 hover_fg = self.hover_fg(cx);
|
||||
let hover_bg = self.hover_bg(cx);
|
||||
let icon = self.clone();
|
||||
let is_linux = cfg!(target_os = "linux");
|
||||
let on_close_window = match &icon {
|
||||
let on_close_window = match &self {
|
||||
ControlIcon::Close { on_close_window } => on_close_window.clone(),
|
||||
_ => None,
|
||||
};
|
||||
|
|
@ -159,20 +169,25 @@ impl RenderOnce for ControlIcon {
|
|||
.content_center()
|
||||
.items_center()
|
||||
.text_color(fg)
|
||||
.when(is_windows, |this| {
|
||||
this.window_control_area(self.window_control_area())
|
||||
})
|
||||
.when(is_linux, |this| {
|
||||
this.on_mouse_down(MouseButton::Left, move |_, window, cx| {
|
||||
window.prevent_default();
|
||||
cx.stop_propagation();
|
||||
})
|
||||
.on_click(move |_, window, cx| match icon {
|
||||
Self::Minimize => window.minimize_window(),
|
||||
Self::Restore => window.zoom_window(),
|
||||
Self::Maximize => window.zoom_window(),
|
||||
Self::Close { .. } => {
|
||||
if let Some(f) = on_close_window.clone() {
|
||||
f(&ClickEvent::default(), window, cx);
|
||||
} else {
|
||||
window.remove_window();
|
||||
.on_click(move |_, window, cx| {
|
||||
cx.stop_propagation();
|
||||
match icon {
|
||||
Self::Minimize => window.minimize_window(),
|
||||
Self::Restore | Self::Maximize => window.zoom_window(),
|
||||
Self::Close { .. } => {
|
||||
if let Some(f) = on_close_window.clone() {
|
||||
f(&ClickEvent::default(), window, cx);
|
||||
} else {
|
||||
window.remove_window();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -243,10 +258,15 @@ impl RenderOnce for TitleBar {
|
|||
.border_b_1()
|
||||
.border_color(cx.theme().title_bar_border)
|
||||
.bg(cx.theme().title_bar)
|
||||
.when(window.is_fullscreen(), |this| this.pl(px(12.)))
|
||||
.on_double_click(|_, window, _| window.zoom_window())
|
||||
.when(is_linux, |this| {
|
||||
this.on_double_click(|_, window, _| window.zoom_window())
|
||||
})
|
||||
.child(
|
||||
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()
|
||||
.justify_between()
|
||||
.flex_shrink_0()
|
||||
|
|
|
|||
Loading…
Reference in a new issue