wip
This commit is contained in:
parent
6c60853842
commit
ba50b35de6
9 changed files with 634 additions and 525 deletions
|
@ -69,6 +69,7 @@ actions!(
|
|||
SplitUp,
|
||||
SplitRight,
|
||||
SplitDown,
|
||||
ToggleZoom,
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -91,6 +92,7 @@ const MAX_NAVIGATION_HISTORY_LEN: usize = 1024;
|
|||
pub type BackgroundActions = fn() -> &'static [(&'static str, &'static dyn Action)];
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.add_action(Pane::toggle_zoom);
|
||||
cx.add_action(|pane: &mut Pane, action: &ActivateItem, cx| {
|
||||
pane.activate_item(action.0, true, true, cx);
|
||||
});
|
||||
|
@ -132,12 +134,15 @@ pub enum Event {
|
|||
Split(SplitDirection),
|
||||
ChangeItemTitle,
|
||||
Focus,
|
||||
ZoomIn,
|
||||
ZoomOut,
|
||||
}
|
||||
|
||||
pub struct Pane {
|
||||
items: Vec<Box<dyn ItemHandle>>,
|
||||
activation_history: Vec<usize>,
|
||||
is_active: bool,
|
||||
zoomed: bool,
|
||||
active_item_index: usize,
|
||||
last_focused_view_by_item: HashMap<usize, AnyWeakViewHandle>,
|
||||
autoscroll: bool,
|
||||
|
@ -236,6 +241,7 @@ impl Pane {
|
|||
items: Vec::new(),
|
||||
activation_history: Vec::new(),
|
||||
is_active: true,
|
||||
zoomed: false,
|
||||
active_item_index: 0,
|
||||
last_focused_view_by_item: Default::default(),
|
||||
autoscroll: false,
|
||||
|
@ -655,6 +661,14 @@ impl Pane {
|
|||
self.items.iter().position(|i| i.id() == item.id())
|
||||
}
|
||||
|
||||
pub fn toggle_zoom(&mut self, _: &ToggleZoom, cx: &mut ViewContext<Self>) {
|
||||
if self.zoomed {
|
||||
cx.emit(Event::ZoomOut);
|
||||
} else {
|
||||
cx.emit(Event::ZoomIn);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn activate_item(
|
||||
&mut self,
|
||||
index: usize,
|
||||
|
@ -1546,6 +1560,15 @@ impl Pane {
|
|||
.with_background_color(background)
|
||||
.into_any()
|
||||
}
|
||||
|
||||
pub fn set_zoomed(&mut self, zoomed: bool, cx: &mut ViewContext<Self>) {
|
||||
self.zoomed = zoomed;
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn is_zoomed(&self) -> bool {
|
||||
self.zoomed
|
||||
}
|
||||
}
|
||||
|
||||
impl Entity for Pane {
|
||||
|
|
|
@ -142,6 +142,12 @@ impl Member {
|
|||
|
||||
match self {
|
||||
Member::Pane(pane) => {
|
||||
let pane_element = if pane.read(cx).is_zoomed() {
|
||||
Empty::new().into_any()
|
||||
} else {
|
||||
ChildView::new(pane, cx).into_any()
|
||||
};
|
||||
|
||||
let leader = follower_states
|
||||
.iter()
|
||||
.find_map(|(leader_id, follower_states)| {
|
||||
|
@ -258,7 +264,7 @@ impl Member {
|
|||
};
|
||||
|
||||
Stack::new()
|
||||
.with_child(ChildView::new(pane, cx).contained().with_border(border))
|
||||
.with_child(pane_element.contained().with_border(border))
|
||||
.with_children(leader_status_box)
|
||||
.into_any()
|
||||
}
|
||||
|
|
|
@ -441,6 +441,7 @@ pub struct Workspace {
|
|||
weak_self: WeakViewHandle<Self>,
|
||||
remote_entity_subscription: Option<client::Subscription>,
|
||||
modal: Option<AnyViewHandle>,
|
||||
zoomed: Option<AnyViewHandle>,
|
||||
center: PaneGroup,
|
||||
left_dock: ViewHandle<Dock>,
|
||||
bottom_dock: ViewHandle<Dock>,
|
||||
|
@ -627,8 +628,9 @@ impl Workspace {
|
|||
];
|
||||
|
||||
let mut this = Workspace {
|
||||
modal: None,
|
||||
weak_self: weak_handle.clone(),
|
||||
modal: None,
|
||||
zoomed: None,
|
||||
center: PaneGroup::new(center_pane.clone()),
|
||||
panes: vec![center_pane.clone()],
|
||||
panes_by_item: Default::default(),
|
||||
|
@ -1303,6 +1305,16 @@ impl Workspace {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn zoom_in(&mut self, view: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||
self.zoomed = Some(view);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn zoom_out(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.zoomed.take();
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn items<'a>(
|
||||
&'a self,
|
||||
cx: &'a AppContext,
|
||||
|
@ -1685,6 +1697,16 @@ impl Workspace {
|
|||
pane::Event::Focus => {
|
||||
self.handle_pane_focused(pane.clone(), cx);
|
||||
}
|
||||
pane::Event::ZoomIn => {
|
||||
pane.update(cx, |pane, cx| pane.set_zoomed(true, cx));
|
||||
self.zoom_in(pane.into_any(), cx);
|
||||
}
|
||||
pane::Event::ZoomOut => {
|
||||
if self.zoomed.as_ref().map_or(false, |zoomed| *zoomed == pane) {
|
||||
pane.update(cx, |pane, cx| pane.set_zoomed(false, cx));
|
||||
self.zoom_out(cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.serialize_workspace(cx);
|
||||
|
@ -2735,6 +2757,21 @@ impl View for Workspace {
|
|||
})
|
||||
.with_child(Overlay::new(
|
||||
Stack::new()
|
||||
.with_children(self.zoomed.as_ref().map(|zoomed| {
|
||||
enum ZoomBackground {}
|
||||
|
||||
ChildView::new(zoomed, cx)
|
||||
.contained()
|
||||
.with_style(theme.workspace.zoomed_foreground)
|
||||
.aligned()
|
||||
.contained()
|
||||
.with_style(theme.workspace.zoomed_background)
|
||||
.mouse::<ZoomBackground>(0)
|
||||
.capture_all()
|
||||
.on_down(MouseButton::Left, |_, this: &mut Self, cx| {
|
||||
this.zoom_out(cx);
|
||||
})
|
||||
}))
|
||||
.with_children(self.modal.as_ref().map(|modal| {
|
||||
ChildView::new(modal, cx)
|
||||
.contained()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue