title_bar: Fix TitleBar prefix padding when is zoomed and support double click to toggle zoom. (#357)
This commit is contained in:
parent
913775c632
commit
6b54396c9c
2 changed files with 26 additions and 22 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use gpui::{ClickEvent, Focusable, InteractiveElement, WindowContext};
|
use gpui::{ClickEvent, Focusable, InteractiveElement, Stateful, WindowContext};
|
||||||
|
|
||||||
pub trait InteractiveElementExt: InteractiveElement {
|
pub trait InteractiveElementExt: InteractiveElement {
|
||||||
/// Set the listener for a double click event.
|
/// Set the listener for a double click event.
|
||||||
|
|
@ -19,3 +19,4 @@ pub trait InteractiveElementExt: InteractiveElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: InteractiveElement> InteractiveElementExt for Focusable<E> {}
|
impl<E: InteractiveElement> InteractiveElementExt for Focusable<E> {}
|
||||||
|
impl<E: InteractiveElement> InteractiveElementExt for Stateful<E> {}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{h_flex, theme::ActiveTheme, Icon, IconName, Sizable as _};
|
use crate::{h_flex, theme::ActiveTheme, Icon, IconName, InteractiveElementExt as _, Sizable as _};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, prelude::FluentBuilder as _, px, AnyElement, Hsla, InteractiveElement as _, IntoElement,
|
div, prelude::FluentBuilder as _, px, AnyElement, Hsla, InteractiveElement as _, IntoElement,
|
||||||
ParentElement, RenderOnce, StatefulInteractiveElement as _, Styled, WindowContext,
|
ParentElement, RenderOnce, StatefulInteractiveElement as _, Styled, WindowContext,
|
||||||
|
|
@ -172,30 +172,33 @@ impl RenderOnce for WindowControls {
|
||||||
|
|
||||||
impl RenderOnce for TitleBar {
|
impl RenderOnce for TitleBar {
|
||||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||||
let mut title_bar = h_flex()
|
let macos_pl = if cfg!(target_os = "macos") {
|
||||||
|
Some(px(80.))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
h_flex()
|
||||||
.id("title-bar")
|
.id("title-bar")
|
||||||
.flex_shrink_0()
|
.flex_shrink_0()
|
||||||
.items_center()
|
.items_center()
|
||||||
.justify_between()
|
.justify_between()
|
||||||
|
.pl(px(12.))
|
||||||
|
.when(!cx.is_fullscreen(), |this| {
|
||||||
|
// Leave space for the macOS window controls.
|
||||||
|
this.when_some(macos_pl, |this, pl| this.pl(pl))
|
||||||
|
})
|
||||||
.border_b_1()
|
.border_b_1()
|
||||||
.border_color(cx.theme().border);
|
.border_color(cx.theme().border)
|
||||||
|
.on_double_click(|_, cx| cx.zoom_window())
|
||||||
title_bar = title_bar.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.h(px(34.))
|
.h(px(34.))
|
||||||
.justify_between()
|
.justify_between()
|
||||||
.flex_shrink_0()
|
.flex_shrink_0()
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.children(self.children),
|
.children(self.children),
|
||||||
);
|
)
|
||||||
|
.child(WindowControls {})
|
||||||
if cfg!(target_os = "macos") {
|
|
||||||
// Leave space for the macOS window controls.
|
|
||||||
title_bar = title_bar.pl(px(80.))
|
|
||||||
} else {
|
|
||||||
title_bar = title_bar.pl(px(12.))
|
|
||||||
}
|
|
||||||
|
|
||||||
title_bar.child(WindowControls {})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue