Fix drawer position (#174)
This commit is contained in:
parent
72b8290945
commit
5533a8b72c
3 changed files with 92 additions and 97 deletions
|
|
@ -204,24 +204,29 @@ 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()
|
||||||
.py_2()
|
|
||||||
.px_3()
|
|
||||||
.line_height(rems(1.0))
|
.line_height(rems(1.0))
|
||||||
.child(panel.title(cx))
|
.pr_3()
|
||||||
.child(self.render_menu_button(cx))
|
.child(
|
||||||
.on_drag(
|
div()
|
||||||
DragPanel {
|
.id("tab")
|
||||||
panel: panel.clone(),
|
.py_2()
|
||||||
tab_panel: view,
|
.px_3()
|
||||||
},
|
.min_w_16()
|
||||||
|drag, cx| {
|
.child(panel.title(cx))
|
||||||
cx.stop_propagation();
|
.on_drag(
|
||||||
cx.new_view(|_| drag.clone())
|
DragPanel {
|
||||||
},
|
panel: panel.clone(),
|
||||||
|
tab_panel: view,
|
||||||
|
},
|
||||||
|
|drag, cx| {
|
||||||
|
cx.stop_propagation();
|
||||||
|
cx.new_view(|_| drag.clone())
|
||||||
|
},
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
.child(self.render_menu_button(cx))
|
||||||
.into_any_element();
|
.into_any_element();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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,89 +124,80 @@ 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()
|
.absolute()
|
||||||
.absolute()
|
.flex_shrink_0()
|
||||||
.flex_shrink_0()
|
.when(self.axis.is_horizontal(), |this| {
|
||||||
.when(self.axis.is_horizontal(), |this| {
|
this.cursor_col_resize()
|
||||||
this.cursor_col_resize()
|
.top_0()
|
||||||
.top_0()
|
.right(neg_offset)
|
||||||
.right(neg_offset)
|
.h_full()
|
||||||
.h_full()
|
.w(px(1.))
|
||||||
.w(px(0.))
|
.px(HANDLE_PADDING)
|
||||||
.px(HANDLE_PADDING)
|
})
|
||||||
})
|
.when(self.axis.is_vertical(), |this| {
|
||||||
.when(self.axis.is_vertical(), |this| {
|
this.cursor_row_resize()
|
||||||
this.cursor_row_resize()
|
.bottom(neg_offset)
|
||||||
.bottom(neg_offset)
|
.left_0()
|
||||||
.left_0()
|
.w_full()
|
||||||
.w_full()
|
.h(px(1.))
|
||||||
.h(px(0.))
|
.py(HANDLE_PADDING)
|
||||||
.py(HANDLE_PADDING)
|
})
|
||||||
})
|
.child(
|
||||||
.child(
|
div()
|
||||||
div()
|
.bg(cx.theme().border)
|
||||||
.bg(cx.theme().border)
|
.when(self.axis.is_horizontal(), |this| {
|
||||||
.when(self.axis.is_horizontal(), |this| {
|
this.h_full().w(self.handle_size)
|
||||||
this.h_full().w(self.handle_size)
|
})
|
||||||
})
|
.when(self.axis.is_vertical(), |this| {
|
||||||
.when(self.axis.is_vertical(), |this| {
|
this.w_full().h(self.handle_size)
|
||||||
this.w_full().h(self.handle_size)
|
}),
|
||||||
}),
|
)
|
||||||
)
|
.on_drag_move(cx.listener(
|
||||||
.on_drag_move(cx.listener(move |view, e: &DragMoveEvent<DragPanel>, cx| {
|
move |view, e: &DragMoveEvent<DragPanel>, cx| match e.drag(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
let ix = *ix;
|
|
||||||
view.resizing_panel_ix = Some(ix);
|
|
||||||
let panel = view
|
|
||||||
.panels
|
|
||||||
.get(ix)
|
|
||||||
.expect("BUG: invalid panel index")
|
|
||||||
.read(cx);
|
|
||||||
|
|
||||||
view.sync_real_panel_sizes(cx);
|
|
||||||
match axis {
|
|
||||||
Axis::Horizontal => view.resize_panels(
|
|
||||||
ix,
|
|
||||||
e.event.position.x - panel.bounds.left(),
|
|
||||||
cx,
|
|
||||||
),
|
|
||||||
Axis::Vertical => {
|
|
||||||
view.resize_panels(
|
|
||||||
ix,
|
|
||||||
e.event.position.y - panel.bounds.top(),
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
.on_mouse_up_out(
|
|
||||||
MouseButton::Left,
|
|
||||||
cx.listener(|view, _, _| {
|
|
||||||
if view.resizing_panel_ix.is_none() {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
view.resizing_panel_ix = None;
|
let ix = *ix;
|
||||||
}),
|
view.resizing_panel_ix = Some(ix);
|
||||||
)
|
let panel = view
|
||||||
.on_drag(DragPanel((cx.entity_id(), ix, axis)), |drag_panel, cx| {
|
.panels
|
||||||
cx.stop_propagation();
|
.get(ix)
|
||||||
cx.new_view(|_| drag_panel.clone())
|
.expect("BUG: invalid panel index")
|
||||||
|
.read(cx);
|
||||||
|
|
||||||
|
view.sync_real_panel_sizes(cx);
|
||||||
|
match axis {
|
||||||
|
Axis::Horizontal => {
|
||||||
|
view.resize_panels(ix, e.event.position.x - panel.bounds.left(), cx)
|
||||||
|
}
|
||||||
|
Axis::Vertical => {
|
||||||
|
view.resize_panels(ix, e.event.position.y - panel.bounds.top(), cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.on_mouse_up_out(
|
||||||
|
MouseButton::Left,
|
||||||
|
cx.listener(|view, _, _| {
|
||||||
|
if view.resizing_panel_ix.is_none() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
view.resizing_panel_ix = None;
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.with_priority(0)
|
.on_drag(DragPanel((cx.entity_id(), ix, axis)), |drag_panel, cx| {
|
||||||
|
cx.stop_propagation();
|
||||||
|
cx.new_view(|_| drag_panel.clone())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sync_real_panel_sizes(&mut self, cx: &WindowContext) {
|
fn sync_real_panel_sizes(&mut self, cx: &WindowContext) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue