@@ -577,10 +577,29 @@ pub(crate) mod test {
PositionChanged,
Activated,
Closed,
+ ZoomIn,
+ ZoomOut,
+ Focus,
}
pub struct TestPanel {
pub position: DockPosition,
+ pub zoomed: bool,
+ pub active: bool,
+ pub has_focus: bool,
+ pub size: f32,
+ }
+
+ impl TestPanel {
+ pub fn new(position: DockPosition) -> Self {
+ Self {
+ position,
+ zoomed: false,
+ active: false,
+ has_focus: false,
+ size: 300.,
+ }
+ }
}
impl Entity for TestPanel {
@@ -595,6 +614,14 @@ pub(crate) mod test {
fn render(&mut self, _: &mut ViewContext<'_, '_, Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
+
+ fn focus_in(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {
+ self.has_focus = true;
+ }
+
+ fn focus_out(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {
+ self.has_focus = false;
+ }
}
impl Panel for TestPanel {
@@ -612,26 +639,23 @@ pub(crate) mod test {
}
fn is_zoomed(&self, _: &WindowContext) -> bool {
- unimplemented!()
+ self.zoomed
}
- fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext<Self>) {
- unimplemented!()
+ fn set_zoomed(&mut self, zoomed: bool, _cx: &mut ViewContext<Self>) {
+ self.zoomed = zoomed;
}
- fn set_active(&mut self, _active: bool, _cx: &mut ViewContext<Self>) {
- unimplemented!()
+ fn set_active(&mut self, active: bool, _cx: &mut ViewContext<Self>) {
+ self.active = active;
}
fn size(&self, _: &WindowContext) -> f32 {
- match self.position.axis() {
- Axis::Horizontal => 300.,
- Axis::Vertical => 200.,
- }
+ self.size
}
- fn set_size(&mut self, _: f32, _: &mut ViewContext<Self>) {
- unimplemented!()
+ fn set_size(&mut self, size: f32, _: &mut ViewContext<Self>) {
+ self.size = size;
}
fn icon_path(&self) -> &'static str {
@@ -646,12 +670,12 @@ pub(crate) mod test {
matches!(event, TestPanelEvent::PositionChanged)
}
- fn should_zoom_in_on_event(_: &Self::Event) -> bool {
- false
+ fn should_zoom_in_on_event(event: &Self::Event) -> bool {
+ matches!(event, TestPanelEvent::ZoomIn)
}
- fn should_zoom_out_on_event(_: &Self::Event) -> bool {
- false
+ fn should_zoom_out_on_event(event: &Self::Event) -> bool {
+ matches!(event, TestPanelEvent::ZoomOut)
}
fn should_activate_on_event(event: &Self::Event) -> bool {
@@ -663,11 +687,11 @@ pub(crate) mod test {
}
fn has_focus(&self, _cx: &WindowContext) -> bool {
- unimplemented!()
+ self.has_focus
}
- fn is_focus_event(_: &Self::Event) -> bool {
- unimplemented!()
+ fn is_focus_event(event: &Self::Event) -> bool {
+ matches!(event, TestPanelEvent::Focus)
}
}
}
@@ -3931,16 +3931,12 @@ mod tests {
let (panel_1, panel_2) = workspace.update(cx, |workspace, cx| {
// Add panel_1 on the left, panel_2 on the right.
- let panel_1 = cx.add_view(|_| TestPanel {
- position: DockPosition::Left,
- });
+ let panel_1 = cx.add_view(|_| TestPanel::new(DockPosition::Left));
workspace.add_panel(panel_1.clone(), cx);
workspace
.left_dock()
.update(cx, |left_dock, cx| left_dock.set_open(true, cx));
- let panel_2 = cx.add_view(|_| TestPanel {
- position: DockPosition::Right,
- });
+ let panel_2 = cx.add_view(|_| TestPanel::new(DockPosition::Right));
workspace.add_panel(panel_2.clone(), cx);
workspace
.right_dock()
@@ -4060,6 +4056,30 @@ mod tests {
);
});
+ // Emitting a ZoomIn event shows the panel as zoomed.
+ panel_1.update(cx, |_, cx| cx.emit(TestPanelEvent::ZoomIn));
+ workspace.read_with(cx, |workspace, cx| {
+ assert_eq!(workspace.zoomed(cx), Some(panel_1.clone().into_any()));
+ });
+
+ // If focus is transferred elsewhere in the workspace, the panel is no longer zoomed.
+ workspace.update(cx, |_, cx| cx.focus_self());
+ workspace.read_with(cx, |workspace, cx| {
+ assert_eq!(workspace.zoomed(cx), None);
+ });
+
+ // When focus is transferred back to the panel, it is zoomed again.
+ panel_1.update(cx, |_, cx| cx.focus_self());
+ workspace.read_with(cx, |workspace, cx| {
+ assert_eq!(workspace.zoomed(cx), Some(panel_1.clone().into_any()));
+ });
+
+ // Emitting a ZoomOut event unzooms the panel.
+ panel_1.update(cx, |_, cx| cx.emit(TestPanelEvent::ZoomOut));
+ workspace.read_with(cx, |workspace, cx| {
+ assert_eq!(workspace.zoomed(cx), None);
+ });
+
// Emit closed event on panel 1, which is active
panel_1.update(cx, |_, cx| cx.emit(TestPanelEvent::Closed));