Fix drawer position (#174)

This commit is contained in:
Jason Lee 2024-08-23 22:01:52 +08:00 committed by GitHub
parent 72b8290945
commit 5533a8b72c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 92 additions and 97 deletions

View file

@ -204,14 +204,17 @@ impl TabPanel {
let panel = self.panels.get(0).unwrap(); let panel = self.panels.get(0).unwrap();
return h_flex() return h_flex()
.id("tab")
.justify_between() .justify_between()
.items_center() .items_center()
.line_height(rems(1.0))
.pr_3()
.child(
div()
.id("tab")
.py_2() .py_2()
.px_3() .px_3()
.line_height(rems(1.0)) .min_w_16()
.child(panel.title(cx)) .child(panel.title(cx))
.child(self.render_menu_button(cx))
.on_drag( .on_drag(
DragPanel { DragPanel {
panel: panel.clone(), panel: panel.clone(),
@ -221,7 +224,9 @@ impl TabPanel {
cx.stop_propagation(); cx.stop_propagation();
cx.new_view(|_| drag.clone()) cx.new_view(|_| drag.clone())
}, },
),
) )
.child(self.render_menu_button(cx))
.into_any_element(); .into_any_element();
} }

View file

@ -150,7 +150,7 @@ impl RenderOnce for Drawer {
.shadow_xl() .shadow_xl()
.map(|this| { .map(|this| {
// Set the size of the drawer. // Set the size of the drawer.
if placement.is_vertical() { if placement.is_horizontal() {
this.h_full().w(self.size) this.h_full().w(self.size)
} else { } else {
this.w_full().h(self.size) this.w_full().h(self.size)

View file

@ -1,10 +1,9 @@
use std::rc::Rc; use std::rc::Rc;
use gpui::{ use gpui::{
canvas, deferred, div, prelude::FluentBuilder, px, AnyElement, AnyView, Axis, Bounds, canvas, div, prelude::FluentBuilder, px, AnyElement, AnyView, Axis, Bounds, DragMoveEvent,
DragMoveEvent, EntityId, InteractiveElement as _, IntoElement, MouseButton, ParentElement, EntityId, InteractiveElement as _, IntoElement, MouseButton, ParentElement, Pixels, Render,
Pixels, Render, StatefulInteractiveElement, Styled, View, ViewContext, VisualContext as _, StatefulInteractiveElement, Styled, View, ViewContext, VisualContext as _, WindowContext,
WindowContext,
}; };
use crate::{h_flex, theme::ActiveTheme, v_flex, AxisExt}; use crate::{h_flex, theme::ActiveTheme, v_flex, AxisExt};
@ -125,9 +124,8 @@ impl ResizablePanelGroup {
fn render_resize_handle(&self, ix: usize, cx: &mut ViewContext<Self>) -> impl IntoElement { fn render_resize_handle(&self, ix: usize, cx: &mut ViewContext<Self>) -> impl IntoElement {
let axis = self.axis; let axis = self.axis;
let neg_offset = -HANDLE_PADDING; let neg_offset = -HANDLE_PADDING + px(1.);
deferred(
div() div()
.id(("resizable-handle", ix)) .id(("resizable-handle", ix))
.occlude() .occlude()
@ -138,7 +136,7 @@ impl ResizablePanelGroup {
.top_0() .top_0()
.right(neg_offset) .right(neg_offset)
.h_full() .h_full()
.w(px(0.)) .w(px(1.))
.px(HANDLE_PADDING) .px(HANDLE_PADDING)
}) })
.when(self.axis.is_vertical(), |this| { .when(self.axis.is_vertical(), |this| {
@ -146,7 +144,7 @@ impl ResizablePanelGroup {
.bottom(neg_offset) .bottom(neg_offset)
.left_0() .left_0()
.w_full() .w_full()
.h(px(0.)) .h(px(1.))
.py(HANDLE_PADDING) .py(HANDLE_PADDING)
}) })
.child( .child(
@ -159,8 +157,8 @@ impl ResizablePanelGroup {
this.w_full().h(self.handle_size) this.w_full().h(self.handle_size)
}), }),
) )
.on_drag_move(cx.listener(move |view, e: &DragMoveEvent<DragPanel>, cx| { .on_drag_move(cx.listener(
match e.drag(cx) { move |view, e: &DragMoveEvent<DragPanel>, cx| match e.drag(cx) {
DragPanel((entity_id, ix, axis)) => { DragPanel((entity_id, ix, axis)) => {
if cx.entity_id() != *entity_id { if cx.entity_id() != *entity_id {
return; return;
@ -176,22 +174,16 @@ impl ResizablePanelGroup {
view.sync_real_panel_sizes(cx); view.sync_real_panel_sizes(cx);
match axis { match axis {
Axis::Horizontal => view.resize_panels( Axis::Horizontal => {
ix, view.resize_panels(ix, e.event.position.x - panel.bounds.left(), cx)
e.event.position.x - panel.bounds.left(), }
cx,
),
Axis::Vertical => { Axis::Vertical => {
view.resize_panels( view.resize_panels(ix, e.event.position.y - panel.bounds.top(), cx);
ix,
e.event.position.y - panel.bounds.top(),
cx,
);
} }
} }
} }
} },
})) ))
.on_mouse_up_out( .on_mouse_up_out(
MouseButton::Left, MouseButton::Left,
cx.listener(|view, _, _| { cx.listener(|view, _, _| {
@ -205,9 +197,7 @@ impl ResizablePanelGroup {
.on_drag(DragPanel((cx.entity_id(), ix, axis)), |drag_panel, cx| { .on_drag(DragPanel((cx.entity_id(), ix, axis)), |drag_panel, cx| {
cx.stop_propagation(); cx.stop_propagation();
cx.new_view(|_| drag_panel.clone()) cx.new_view(|_| drag_panel.clone())
}), })
)
.with_priority(0)
} }
fn sync_real_panel_sizes(&mut self, cx: &WindowContext) { fn sync_real_panel_sizes(&mut self, cx: &WindowContext) {