fix: make full titlebar strip draggable in dock and sidebar
This commit is contained in:
+12
-11
@@ -1085,18 +1085,19 @@ fn render_pane(
|
||||
})
|
||||
.pr(padding_x)
|
||||
.child(tabs)
|
||||
.child(titlebar_strip(
|
||||
div()
|
||||
.id(SharedString::from(format!(
|
||||
"{dock_id}-pane-{}-strip",
|
||||
pane.key
|
||||
)))
|
||||
.flex_1()
|
||||
.self_stretch(),
|
||||
window,
|
||||
cx,
|
||||
))
|
||||
.when(titlebar.window_controls, |bar| {
|
||||
bar.child(titlebar_strip(
|
||||
div()
|
||||
.id(SharedString::from(format!(
|
||||
"{dock_id}-pane-{}-strip",
|
||||
pane.key
|
||||
)))
|
||||
.flex_1(),
|
||||
window,
|
||||
cx,
|
||||
))
|
||||
.child(WindowControls::new(SharedString::from(format!(
|
||||
bar.child(WindowControls::new(SharedString::from(format!(
|
||||
"{dock_id}-pane-{}-controls",
|
||||
pane.key
|
||||
))))
|
||||
|
||||
+29
-22
@@ -286,36 +286,43 @@ fn sidebar_region(
|
||||
.h(strip_height)
|
||||
.bg(strip_background)
|
||||
.items_center()
|
||||
.justify_end()
|
||||
.map(|strip| titlebar_strip(strip, window, cx))
|
||||
.map(|strip| match side {
|
||||
Side::Left => strip.when(cfg!(target_os = "macos"), |strip| {
|
||||
strip.pl(px(TRAFFIC_LIGHT_PAD))
|
||||
}),
|
||||
Side::Right => strip.child(WindowControls::new("sidebar-window-controls")),
|
||||
Side::Right => strip,
|
||||
})
|
||||
.px(padding_x)
|
||||
.child(
|
||||
Button::new(SharedString::from(format!(
|
||||
"sidebar-toggle-{}",
|
||||
side.name()
|
||||
)))
|
||||
.icon(side.toggle_icon())
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.small()
|
||||
.accessibility_label(side.toggle_label())
|
||||
.on_click({
|
||||
let state = state.clone();
|
||||
move |_, _, cx| match side {
|
||||
Side::Left => {
|
||||
.child(titlebar_strip(
|
||||
div()
|
||||
.id(SharedString::from(format!(
|
||||
"sidebar-strip-drag-{}",
|
||||
side.name()
|
||||
)))
|
||||
.flex_1()
|
||||
.self_stretch(),
|
||||
window,
|
||||
cx,
|
||||
))
|
||||
.map(|strip| match side {
|
||||
Side::Left => strip.child(
|
||||
Button::new(SharedString::from(format!(
|
||||
"sidebar-toggle-{}",
|
||||
side.name()
|
||||
)))
|
||||
.icon(side.toggle_icon())
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.small()
|
||||
.accessibility_label(side.toggle_label())
|
||||
.on_click({
|
||||
let state = state.clone();
|
||||
move |_, _, cx| {
|
||||
state.update(cx, |state, cx| state.set_left_sidebar_visible(false, cx))
|
||||
}
|
||||
Side::Right => {
|
||||
state.update(cx, |state, cx| state.set_right_sidebar_visible(false, cx))
|
||||
}
|
||||
}
|
||||
}),
|
||||
);
|
||||
}),
|
||||
),
|
||||
Side::Right => strip.child(WindowControls::new("sidebar-window-controls")),
|
||||
});
|
||||
|
||||
v_flex()
|
||||
.w(width)
|
||||
|
||||
@@ -166,9 +166,7 @@ pub fn maximize_on_double_click() -> impl Fn(&ClickEvent, &mut Window, &mut App)
|
||||
}
|
||||
}
|
||||
|
||||
/// Makes an element a titlebar strip: pressing and dragging it moves the
|
||||
/// window, double-clicking maximizes, and Windows keeps its native caption
|
||||
/// behavior through the `Drag` control area.
|
||||
/// Makes an element a titlebar strip.
|
||||
pub fn titlebar_strip(this: Stateful<Div>, window: &mut Window, cx: &mut App) -> Stateful<Div> {
|
||||
let should_move = window.use_state(cx, |_, _| false);
|
||||
this.window_control_area(WindowControlArea::Drag)
|
||||
|
||||
@@ -98,8 +98,14 @@ fn the_pill_bar_pads_for_traffic_lights_when_it_leads_the_window() {
|
||||
bounds(&mut visual, "test-dock-pane-0-tabs-tab-overview").expect("tab missing");
|
||||
let padded_inset = padded_tab.left() - padded_bar.left();
|
||||
|
||||
// The bare bar keeps the standard leading padding; the padded bar clears
|
||||
// the traffic lights.
|
||||
assert!(
|
||||
padded_inset - bare_inset >= px(TRAFFIC_LIGHT_PAD) - px(1.),
|
||||
bare_inset < px(TRAFFIC_LIGHT_PAD),
|
||||
"the bare bar must not reserve the traffic-light pad (bare {bare_inset:?})"
|
||||
);
|
||||
assert!(
|
||||
padded_inset >= px(TRAFFIC_LIGHT_PAD) - px(1.),
|
||||
"the pad must clear the traffic lights (bare {bare_inset:?}, padded {padded_inset:?})"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user