forge
Explore
Log in

Don't you dare go Hollow

Grid view panels resize by dragging (streams | side, members / chat, with limits)

Browse files at this commit

8fd10d5b09b376facfc931bb605a602144bb7206Ahmet Kaan GümüşParent: 56c130b
  • feat
    • grid view panels resize by dragging (streams | side, members / chat, with limits)
    • drag the member list onto the chat to swap them
Show full message
✨ feat: grid view panels resize by dragging (streams | side, members / chat, with limits); drag the member list onto the chat to swap them
crates/client/src/gui/chat.rsmodified+107 -59
@@ -57,6 +57,7 @@ use gpui_kit::{
57 component::{57 component::{
58 Icon, IndexPath, WindowExt,58 Icon, IndexPath, WindowExt,
59 input::{InputEvent, InputState, Textarea, TextareaState},59 input::{InputEvent, InputState, Textarea, TextareaState},
60+ resizable::{h_resizable, resizable_panel, v_resizable},
60 searchable_list::SearchableVec,61 searchable_list::SearchableVec,
61 select::SelectState,62 select::SelectState,
62 slider::{SliderEvent, SliderState},63 slider::{SliderEvent, SliderState},
@@ -281,6 +282,7 @@ pub struct Chat {
281 pub(super) camera_task: Option<Task<()>>,282 pub(super) camera_task: Option<Task<()>>,
282 pub(super) stage: Stage,283 pub(super) stage: Stage,
283 pub(super) grid_size: (f32, f32),284 pub(super) grid_size: (f32, f32),
285+ pub(super) chat_on_top: bool,
284 pub(super) typing: HashMap<Id, HashMap<Id, Instant>>,286 pub(super) typing: HashMap<Id, HashMap<Id, Instant>>,
285 pub(super) typing_sent: HashMap<Id, Instant>,287 pub(super) typing_sent: HashMap<Id, Instant>,
286 }288 }
@@ -578,6 +580,7 @@ impl Chat {
578 camera_task: None,580 camera_task: None,
579 stage: Stage::Strip,581 stage: Stage::Strip,
580 grid_size: (1280., 720.),582 grid_size: (1280., 720.),
583+ chat_on_top: false,
581 composer: Composer::Compose { reply: None },584 composer: Composer::Compose { reply: None },
582 }585 }
583 }586 }
@@ -1418,71 +1421,17 @@ impl Yumush {
1418 let viewer = self.inline_viewer(entity, themed);1421 let viewer = self.inline_viewer(entity, themed);
1419 let grid = viewer1422 let grid = viewer
1420 .is_none()1423 .is_none()
1421- .then(|| self.stage_grid(entity, themed, cx))1424+ .then(|| {
1425+ self.stage_grid(entity, themed, cx)
1426+ .map(IntoElement::into_any_element)
1427+ })
1422 .flatten();1428 .flatten();
1423- let side_chat = grid.is_some();
1424 panel1429 panel
1425 .child(self.header(entity, themed))1430 .child(self.header(entity, themed))
1426 .children(self.stage_strip(entity, themed))1431 .children(self.stage_strip(entity, themed))
1427 .children(self.unread_bar(entity, themed))1432 .children(self.unread_bar(entity, themed))
1428 .children(self.poll_banner(entity, themed))1433 .children(self.poll_banner(entity, themed))
1429- .child(1434+ .child(self.chat_body(entity, themed, viewer, grid, cx))
1430- div()
1431- .flex_1()
1432- .min_h_0()
1433- .flex()
1434- .child(div().flex_1().min_w_0().flex().flex_col().map(
1435- |panel| {
1436- match (viewer, grid) {
1437- (Some(viewer), _) => panel.child(viewer),
1438- (None, Some(grid)) => panel.child(grid),
1439- (None, None) => panel
1440- .child(self.message_area(entity, themed))
1441- .child(self.composer(entity, themed, cx)),
1442- }
1443- },
1444- ))
1445- .children(members_column(entity, self, themed).map(
1446- |members| {
1447- div()
1448- .w(px(if side_chat {
1449- size::MARGIN_CHAT
1450- } else {
1451- size::MARGIN
1452- }))
1453- .flex_none()
1454- .h_full()
1455- .flex()
1456- .flex_col()
1457- .border_l_1()
1458- .border_color(palette.border)
1459- .child(if side_chat {
1460- members
1461- .flex_none()
1462- .max_h(gpui_kit::relative(0.4))
1463- } else {
1464- members.flex_1().min_h_0()
1465- })
1466- .when(side_chat, |column| {
1467- column.child(
1468- div()
1469- .flex_1()
1470- .min_h_0()
1471- .flex()
1472- .flex_col()
1473- .border_t_1()
1474- .border_color(palette.border)
1475- .child(
1476- self.message_area(entity, themed),
1477- )
1478- .child(
1479- self.composer(entity, themed, cx),
1480- ),
1481- )
1482- })
1483- },
1484- )),
1485- )
1486 }1435 }
1487 None => panel.child(empty_state(palette)),1436 None => panel.child(empty_state(palette)),
1488 },1437 },
@@ -1491,6 +1440,97 @@ impl Yumush {
1491 .children(self.dock(entity, palette, cx))1440 .children(self.dock(entity, palette, cx))
1492 }1441 }
1493 1442
1443+ fn chat_body(
1444+ &self,
1445+ entity: &Entity<Self>,
1446+ palette: Palette,
1447+ viewer: Option<Div>,
1448+ grid: Option<AnyElement>,
1449+ cx: &App,
1450+ ) -> AnyElement {
1451+ let chat = || {
1452+ div()
1453+ .size_full()
1454+ .flex()
1455+ .flex_col()
1456+ .child(self.message_area(entity, palette))
1457+ .child(self.composer(entity, palette, cx))
1458+ };
1459+ let members = members_column(entity, self, palette);
1460+ match (viewer, grid, members) {
1461+ (None, Some(grid), Some(members)) => h_resizable("stage_split")
1462+ .child(
1463+ resizable_panel()
1464+ .size_range(px(size::PAGE)..gpui_kit::Pixels::MAX)
1465+ .child(div().size_full().flex().flex_col().child(grid)),
1466+ )
1467+ .child(
1468+ resizable_panel()
1469+ .size(px(size::MARGIN_CHAT))
1470+ .size_range(px(size::MARGIN)..px(size::MARGIN * 2.))
1471+ .fixed()
1472+ .child({
1473+ let members = resizable_panel()
1474+ .size(px(size::THUMB * 2.))
1475+ .size_range(px(size::ROW * 2.)..gpui_kit::Pixels::MAX)
1476+ .fixed()
1477+ .child(
1478+ members
1479+ .size_full()
1480+ .on_drag(SideSwap, |_, _, _, cx| cx.new(|_| SideSwap)),
1481+ );
1482+ let swap = entity.clone();
1483+ let hover = palette.tokens.hov();
1484+ let chat = resizable_panel()
1485+ .size_range(px(size::THUMB * 2.)..gpui_kit::Pixels::MAX)
1486+ .child(
1487+ chat()
1488+ .drag_over::<SideSwap>(move |style, _, _, _| {
1489+ style.bg(hover)
1490+ })
1491+ .on_drop(move |_: &SideSwap, _, cx| {
1492+ swap.update(cx, |yumush, cx| {
1493+ yumush.chat.chat_on_top = !yumush.chat.chat_on_top;
1494+ cx.notify();
1495+ })
1496+ }),
1497+ );
1498+ if self.chat.chat_on_top {
1499+ v_resizable("side_split_chat_top")
1500+ .child(chat)
1501+ .child(members)
1502+ } else {
1503+ v_resizable("side_split").child(members).child(chat)
1504+ }
1505+ }),
1506+ )
1507+ .into_any_element(),
1508+ (viewer, grid, members) => div()
1509+ .flex_1()
1510+ .min_h_0()
1511+ .flex()
1512+ .child(div().flex_1().min_w_0().flex().flex_col().map(|panel| {
1513+ match (viewer, grid) {
1514+ (Some(viewer), _) => panel.child(viewer),
1515+ (None, Some(grid)) => panel.child(grid),
1516+ (None, None) => panel.child(chat()),
1517+ }
1518+ }))
1519+ .children(members.map(|members| {
1520+ div()
1521+ .w(px(size::MARGIN))
1522+ .flex_none()
1523+ .h_full()
1524+ .flex()
1525+ .flex_col()
1526+ .border_l_1()
1527+ .border_color(palette.border)
1528+ .child(members.flex_1().min_h_0())
1529+ }))
1530+ .into_any_element(),
1531+ }
1532+ }
1533+
1494 fn stats_sheet(&self, palette: Palette) -> Option<impl IntoElement> {1534 fn stats_sheet(&self, palette: Palette) -> Option<impl IntoElement> {
1495 let at = self1535 let at = self
1496 .chat1536 .chat
@@ -3743,3 +3783,11 @@ fn stage_button(
3743 })3783 })
3744 .child(super::parts::small_icon(icon))3784 .child(super::parts::small_icon(icon))
3745 }3785 }
3786+
3787+struct SideSwap;
3788+
3789+impl gpui_kit::Render for SideSwap {
3790+ fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
3791+ div()
3792+ }
3793+}