1use crate::DraggedDock;
2use crate::{status_bar::StatusItemView, Workspace};
3use gpui::{
4 div, px, Action, AnchorCorner, AnyView, AppContext, Axis, ClickEvent, Entity, EntityId,
5 EventEmitter, FocusHandle, FocusableView, IntoElement, MouseButton, ParentElement, Render,
6 SharedString, Styled, Subscription, View, ViewContext, VisualContext, WeakView, WindowContext,
7};
8use schemars::JsonSchema;
9use serde::{Deserialize, Serialize};
10use std::sync::Arc;
11use ui::{h_stack, ContextMenu, IconButton, Tooltip};
12use ui::{prelude::*, right_click_menu};
13
14const RESIZE_HANDLE_SIZE: Pixels = Pixels(6.);
15
16pub enum PanelEvent {
17 ChangePosition,
18 ZoomIn,
19 ZoomOut,
20 Activate,
21 Close,
22 Focus,
23}
24
25pub trait Panel: FocusableView + EventEmitter<PanelEvent> {
26 fn persistent_name() -> &'static str;
27 fn position(&self, cx: &WindowContext) -> DockPosition;
28 fn position_is_valid(&self, position: DockPosition) -> bool;
29 fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>);
30 fn size(&self, cx: &WindowContext) -> Pixels;
31 fn set_size(&mut self, size: Option<Pixels>, cx: &mut ViewContext<Self>);
32 // todo!("We should have a icon tooltip method, rather than using persistant_name")
33 fn icon(&self, cx: &WindowContext) -> Option<ui::Icon>;
34 fn toggle_action(&self) -> Box<dyn Action>;
35 fn icon_label(&self, _: &WindowContext) -> Option<String> {
36 None
37 }
38 fn is_zoomed(&self, _cx: &WindowContext) -> bool {
39 false
40 }
41 fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext<Self>) {}
42 fn set_active(&mut self, _active: bool, _cx: &mut ViewContext<Self>) {}
43}
44
45pub trait PanelHandle: Send + Sync {
46 fn panel_id(&self) -> EntityId;
47 fn persistent_name(&self) -> &'static str;
48 fn position(&self, cx: &WindowContext) -> DockPosition;
49 fn position_is_valid(&self, position: DockPosition, cx: &WindowContext) -> bool;
50 fn set_position(&self, position: DockPosition, cx: &mut WindowContext);
51 fn is_zoomed(&self, cx: &WindowContext) -> bool;
52 fn set_zoomed(&self, zoomed: bool, cx: &mut WindowContext);
53 fn set_active(&self, active: bool, cx: &mut WindowContext);
54 fn size(&self, cx: &WindowContext) -> Pixels;
55 fn set_size(&self, size: Option<Pixels>, cx: &mut WindowContext);
56 fn icon(&self, cx: &WindowContext) -> Option<ui::Icon>;
57 fn toggle_action(&self, cx: &WindowContext) -> Box<dyn Action>;
58 fn icon_label(&self, cx: &WindowContext) -> Option<String>;
59 fn focus_handle(&self, cx: &AppContext) -> FocusHandle;
60 fn to_any(&self) -> AnyView;
61}
62
63impl<T> PanelHandle for View<T>
64where
65 T: Panel,
66{
67 fn panel_id(&self) -> EntityId {
68 Entity::entity_id(self)
69 }
70
71 fn persistent_name(&self) -> &'static str {
72 T::persistent_name()
73 }
74
75 fn position(&self, cx: &WindowContext) -> DockPosition {
76 self.read(cx).position(cx)
77 }
78
79 fn position_is_valid(&self, position: DockPosition, cx: &WindowContext) -> bool {
80 self.read(cx).position_is_valid(position)
81 }
82
83 fn set_position(&self, position: DockPosition, cx: &mut WindowContext) {
84 self.update(cx, |this, cx| this.set_position(position, cx))
85 }
86
87 fn is_zoomed(&self, cx: &WindowContext) -> bool {
88 self.read(cx).is_zoomed(cx)
89 }
90
91 fn set_zoomed(&self, zoomed: bool, cx: &mut WindowContext) {
92 self.update(cx, |this, cx| this.set_zoomed(zoomed, cx))
93 }
94
95 fn set_active(&self, active: bool, cx: &mut WindowContext) {
96 self.update(cx, |this, cx| this.set_active(active, cx))
97 }
98
99 fn size(&self, cx: &WindowContext) -> Pixels {
100 self.read(cx).size(cx)
101 }
102
103 fn set_size(&self, size: Option<Pixels>, cx: &mut WindowContext) {
104 self.update(cx, |this, cx| this.set_size(size, cx))
105 }
106
107 fn icon(&self, cx: &WindowContext) -> Option<ui::Icon> {
108 self.read(cx).icon(cx)
109 }
110
111 fn toggle_action(&self, cx: &WindowContext) -> Box<dyn Action> {
112 self.read(cx).toggle_action()
113 }
114
115 fn icon_label(&self, cx: &WindowContext) -> Option<String> {
116 self.read(cx).icon_label(cx)
117 }
118
119 fn to_any(&self) -> AnyView {
120 self.clone().into()
121 }
122
123 fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
124 self.read(cx).focus_handle(cx).clone()
125 }
126}
127
128impl From<&dyn PanelHandle> for AnyView {
129 fn from(val: &dyn PanelHandle) -> Self {
130 val.to_any()
131 }
132}
133
134pub struct Dock {
135 position: DockPosition,
136 panel_entries: Vec<PanelEntry>,
137 is_open: bool,
138 active_panel_index: usize,
139 focus_handle: FocusHandle,
140 _focus_subscription: Subscription,
141}
142
143impl FocusableView for Dock {
144 fn focus_handle(&self, _: &AppContext) -> FocusHandle {
145 self.focus_handle.clone()
146 }
147}
148
149#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
150#[serde(rename_all = "lowercase")]
151pub enum DockPosition {
152 Left,
153 Bottom,
154 Right,
155}
156
157impl DockPosition {
158 fn to_label(&self) -> &'static str {
159 match self {
160 Self::Left => "left",
161 Self::Bottom => "bottom",
162 Self::Right => "right",
163 }
164 }
165
166 // todo!()
167 // fn to_resize_handle_side(self) -> HandleSide {
168 // match self {
169 // Self::Left => HandleSide::Right,
170 // Self::Bottom => HandleSide::Top,
171 // Self::Right => HandleSide::Left,
172 // }
173 // }
174
175 pub fn axis(&self) -> Axis {
176 match self {
177 Self::Left | Self::Right => Axis::Horizontal,
178 Self::Bottom => Axis::Vertical,
179 }
180 }
181}
182
183struct PanelEntry {
184 panel: Arc<dyn PanelHandle>,
185 // todo!()
186 // context_menu: View<ContextMenu>,
187 _subscriptions: [Subscription; 2],
188}
189
190pub struct PanelButtons {
191 dock: View<Dock>,
192}
193
194impl Dock {
195 pub fn new(position: DockPosition, cx: &mut ViewContext<Workspace>) -> View<Self> {
196 let focus_handle = cx.focus_handle();
197
198 let dock = cx.new_view(|cx: &mut ViewContext<Self>| {
199 let focus_subscription = cx.on_focus(&focus_handle, |dock, cx| {
200 if let Some(active_entry) = dock.panel_entries.get(dock.active_panel_index) {
201 active_entry.panel.focus_handle(cx).focus(cx)
202 }
203 });
204 Self {
205 position,
206 panel_entries: Default::default(),
207 active_panel_index: 0,
208 is_open: false,
209 focus_handle: focus_handle.clone(),
210 _focus_subscription: focus_subscription,
211 }
212 });
213
214 cx.observe(&dock, move |workspace, dock, cx| {
215 if dock.read(cx).is_open() {
216 if let Some(panel) = dock.read(cx).active_panel() {
217 if panel.is_zoomed(cx) {
218 workspace.zoomed = Some(panel.to_any().downgrade());
219 workspace.zoomed_position = Some(position);
220 return;
221 }
222 }
223 }
224 if workspace.zoomed_position == Some(position) {
225 workspace.zoomed = None;
226 workspace.zoomed_position = None;
227 }
228 })
229 .detach();
230
231 dock
232 }
233
234 pub fn position(&self) -> DockPosition {
235 self.position
236 }
237
238 pub fn is_open(&self) -> bool {
239 self.is_open
240 }
241
242 // todo!()
243 // pub fn has_focus(&self, cx: &WindowContext) -> bool {
244 // self.visible_panel()
245 // .map_or(false, |panel| panel.has_focus(cx))
246 // }
247
248 pub fn panel<T: Panel>(&self) -> Option<View<T>> {
249 self.panel_entries
250 .iter()
251 .find_map(|entry| entry.panel.to_any().clone().downcast().ok())
252 }
253
254 pub fn panel_index_for_type<T: Panel>(&self) -> Option<usize> {
255 self.panel_entries
256 .iter()
257 .position(|entry| entry.panel.to_any().downcast::<T>().is_ok())
258 }
259
260 pub fn panel_index_for_persistent_name(
261 &self,
262 ui_name: &str,
263 _cx: &AppContext,
264 ) -> Option<usize> {
265 self.panel_entries
266 .iter()
267 .position(|entry| entry.panel.persistent_name() == ui_name)
268 }
269
270 pub fn active_panel_index(&self) -> usize {
271 self.active_panel_index
272 }
273
274 pub(crate) fn set_open(&mut self, open: bool, cx: &mut ViewContext<Self>) {
275 if open != self.is_open {
276 self.is_open = open;
277 if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {
278 active_panel.panel.set_active(open, cx);
279 }
280
281 cx.notify();
282 }
283 }
284
285 pub fn set_panel_zoomed(&mut self, panel: &AnyView, zoomed: bool, cx: &mut ViewContext<Self>) {
286 for entry in &mut self.panel_entries {
287 if entry.panel.panel_id() == panel.entity_id() {
288 if zoomed != entry.panel.is_zoomed(cx) {
289 entry.panel.set_zoomed(zoomed, cx);
290 }
291 } else if entry.panel.is_zoomed(cx) {
292 entry.panel.set_zoomed(false, cx);
293 }
294 }
295
296 cx.notify();
297 }
298
299 pub fn zoom_out(&mut self, cx: &mut ViewContext<Self>) {
300 for entry in &mut self.panel_entries {
301 if entry.panel.is_zoomed(cx) {
302 entry.panel.set_zoomed(false, cx);
303 }
304 }
305 }
306
307 pub(crate) fn add_panel<T: Panel>(
308 &mut self,
309 panel: View<T>,
310 workspace: WeakView<Workspace>,
311 cx: &mut ViewContext<Self>,
312 ) {
313 let subscriptions = [
314 cx.observe(&panel, |_, _, cx| cx.notify()),
315 cx.subscribe(&panel, move |this, panel, event, cx| match event {
316 PanelEvent::ChangePosition => {
317 let new_position = panel.read(cx).position(cx);
318
319 let Ok(new_dock) = workspace.update(cx, |workspace, cx| {
320 if panel.is_zoomed(cx) {
321 workspace.zoomed_position = Some(new_position);
322 }
323 match new_position {
324 DockPosition::Left => &workspace.left_dock,
325 DockPosition::Bottom => &workspace.bottom_dock,
326 DockPosition::Right => &workspace.right_dock,
327 }
328 .clone()
329 }) else {
330 return;
331 };
332
333 let was_visible = this.is_open()
334 && this.visible_panel().map_or(false, |active_panel| {
335 active_panel.panel_id() == Entity::entity_id(&panel)
336 });
337
338 this.remove_panel(&panel, cx);
339
340 new_dock.update(cx, |new_dock, cx| {
341 new_dock.add_panel(panel.clone(), workspace.clone(), cx);
342 if was_visible {
343 new_dock.set_open(true, cx);
344 new_dock.activate_panel(new_dock.panels_len() - 1, cx);
345 }
346 });
347 }
348 PanelEvent::ZoomIn => {
349 this.set_panel_zoomed(&panel.to_any(), true, cx);
350 if !panel.focus_handle(cx).contains_focused(cx) {
351 cx.focus_view(&panel);
352 }
353 workspace
354 .update(cx, |workspace, cx| {
355 workspace.zoomed = Some(panel.downgrade().into());
356 workspace.zoomed_position = Some(panel.read(cx).position(cx));
357 })
358 .ok();
359 }
360 PanelEvent::ZoomOut => {
361 this.set_panel_zoomed(&panel.to_any(), false, cx);
362 workspace
363 .update(cx, |workspace, cx| {
364 if workspace.zoomed_position == Some(this.position) {
365 workspace.zoomed = None;
366 workspace.zoomed_position = None;
367 }
368 cx.notify();
369 })
370 .ok();
371 }
372 // todo!() we do not use this event in the production code (even in zed1), remove it
373 PanelEvent::Activate => {
374 if let Some(ix) = this
375 .panel_entries
376 .iter()
377 .position(|entry| entry.panel.panel_id() == Entity::entity_id(&panel))
378 {
379 this.set_open(true, cx);
380 this.activate_panel(ix, cx);
381 cx.focus_view(&panel);
382 }
383 }
384 PanelEvent::Close => {
385 if this
386 .visible_panel()
387 .map_or(false, |p| p.panel_id() == Entity::entity_id(&panel))
388 {
389 this.set_open(false, cx);
390 }
391 }
392 PanelEvent::Focus => {}
393 }),
394 ];
395
396 // todo!()
397 // let dock_view_id = cx.view_id();
398 self.panel_entries.push(PanelEntry {
399 panel: Arc::new(panel),
400 // todo!()
401 // context_menu: cx.add_view(|cx| {
402 // let mut menu = ContextMenu::new(dock_view_id, cx);
403 // menu.set_position_mode(OverlayPositionMode::Local);
404 // menu
405 // }),
406 _subscriptions: subscriptions,
407 });
408 cx.notify()
409 }
410
411 pub fn remove_panel<T: Panel>(&mut self, panel: &View<T>, cx: &mut ViewContext<Self>) {
412 if let Some(panel_ix) = self
413 .panel_entries
414 .iter()
415 .position(|entry| entry.panel.panel_id() == Entity::entity_id(panel))
416 {
417 if panel_ix == self.active_panel_index {
418 self.active_panel_index = 0;
419 self.set_open(false, cx);
420 } else if panel_ix < self.active_panel_index {
421 self.active_panel_index -= 1;
422 }
423 self.panel_entries.remove(panel_ix);
424 cx.notify();
425 }
426 }
427
428 pub fn panels_len(&self) -> usize {
429 self.panel_entries.len()
430 }
431
432 pub fn activate_panel(&mut self, panel_ix: usize, cx: &mut ViewContext<Self>) {
433 if panel_ix != self.active_panel_index {
434 if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {
435 active_panel.panel.set_active(false, cx);
436 }
437
438 self.active_panel_index = panel_ix;
439 if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {
440 active_panel.panel.set_active(true, cx);
441 }
442
443 cx.notify();
444 }
445 }
446
447 pub fn visible_panel(&self) -> Option<&Arc<dyn PanelHandle>> {
448 let entry = self.visible_entry()?;
449 Some(&entry.panel)
450 }
451
452 pub fn active_panel(&self) -> Option<&Arc<dyn PanelHandle>> {
453 Some(&self.panel_entries.get(self.active_panel_index)?.panel)
454 }
455
456 fn visible_entry(&self) -> Option<&PanelEntry> {
457 if self.is_open {
458 self.panel_entries.get(self.active_panel_index)
459 } else {
460 None
461 }
462 }
463
464 pub fn zoomed_panel(&self, cx: &WindowContext) -> Option<Arc<dyn PanelHandle>> {
465 let entry = self.visible_entry()?;
466 if entry.panel.is_zoomed(cx) {
467 Some(entry.panel.clone())
468 } else {
469 None
470 }
471 }
472
473 pub fn panel_size(&self, panel: &dyn PanelHandle, cx: &WindowContext) -> Option<Pixels> {
474 self.panel_entries
475 .iter()
476 .find(|entry| entry.panel.panel_id() == panel.panel_id())
477 .map(|entry| entry.panel.size(cx))
478 }
479
480 pub fn active_panel_size(&self, cx: &WindowContext) -> Option<Pixels> {
481 if self.is_open {
482 self.panel_entries
483 .get(self.active_panel_index)
484 .map(|entry| entry.panel.size(cx))
485 } else {
486 None
487 }
488 }
489
490 pub fn resize_active_panel(&mut self, size: Option<Pixels>, cx: &mut ViewContext<Self>) {
491 if let Some(entry) = self.panel_entries.get_mut(self.active_panel_index) {
492 let size = size.map(|size| size.max(RESIZE_HANDLE_SIZE));
493 entry.panel.set_size(size, cx);
494 cx.notify();
495 }
496 }
497
498 pub fn toggle_action(&self) -> Box<dyn Action> {
499 match self.position {
500 DockPosition::Left => crate::ToggleLeftDock.boxed_clone(),
501 DockPosition::Bottom => crate::ToggleBottomDock.boxed_clone(),
502 DockPosition::Right => crate::ToggleRightDock.boxed_clone(),
503 }
504 }
505}
506
507impl Render for Dock {
508 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
509 if let Some(entry) = self.visible_entry() {
510 let size = entry.panel.size(cx);
511
512 let position = self.position;
513 let mut handle = div()
514 .id("resize-handle")
515 .on_drag(DraggedDock(position), |dock, cx| {
516 cx.stop_propagation();
517 cx.new_view(|_| dock.clone())
518 })
519 .on_click(cx.listener(|v, e: &ClickEvent, cx| {
520 if e.down.button == MouseButton::Left && e.down.click_count == 2 {
521 v.resize_active_panel(None, cx);
522 cx.stop_propagation();
523 }
524 }))
525 .z_index(1)
526 .block_mouse();
527
528 match self.position() {
529 DockPosition::Left => {
530 handle = handle
531 .absolute()
532 .right(px(0.))
533 .top(px(0.))
534 .h_full()
535 .w(RESIZE_HANDLE_SIZE)
536 .cursor_col_resize();
537 }
538 DockPosition::Bottom => {
539 handle = handle
540 .absolute()
541 .top(px(0.))
542 .left(px(0.))
543 .w_full()
544 .h(RESIZE_HANDLE_SIZE)
545 .cursor_row_resize();
546 }
547 DockPosition::Right => {
548 handle = handle
549 .absolute()
550 .top(px(0.))
551 .left(px(0.))
552 .h_full()
553 .w(RESIZE_HANDLE_SIZE)
554 .cursor_col_resize();
555 }
556 }
557
558 div()
559 .flex()
560 .bg(cx.theme().colors().panel_background)
561 .border_color(cx.theme().colors().border)
562 .overflow_hidden()
563 .map(|this| match self.position().axis() {
564 Axis::Horizontal => this.w(size).h_full().flex_row(),
565 Axis::Vertical => this.h(size).w_full().flex_col(),
566 })
567 .map(|this| match self.position() {
568 DockPosition::Left => this.border_r(),
569 DockPosition::Right => this.border_l(),
570 DockPosition::Bottom => this.border_t(),
571 })
572 .child(
573 div()
574 .map(|this| match self.position().axis() {
575 Axis::Horizontal => this.min_w(size).h_full(),
576 Axis::Vertical => this.min_h(size).w_full(),
577 })
578 .child(entry.panel.to_any()),
579 )
580 .child(handle)
581 } else {
582 div()
583 }
584 }
585}
586
587impl PanelButtons {
588 pub fn new(dock: View<Dock>, cx: &mut ViewContext<Self>) -> Self {
589 cx.observe(&dock, |_, _, cx| cx.notify()).detach();
590 Self { dock }
591 }
592}
593
594impl Render for PanelButtons {
595 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
596 // todo!()
597 let dock = self.dock.read(cx);
598 let active_index = dock.active_panel_index;
599 let is_open = dock.is_open;
600 let dock_position = dock.position;
601
602 let (menu_anchor, menu_attach) = match dock.position {
603 DockPosition::Left => (AnchorCorner::BottomLeft, AnchorCorner::TopLeft),
604 DockPosition::Bottom | DockPosition::Right => {
605 (AnchorCorner::BottomRight, AnchorCorner::TopRight)
606 }
607 };
608
609 let buttons = dock
610 .panel_entries
611 .iter()
612 .enumerate()
613 .filter_map(|(i, entry)| {
614 let icon = entry.panel.icon(cx)?;
615 let name = entry.panel.persistent_name();
616 let panel = entry.panel.clone();
617
618 let is_active_button = i == active_index && is_open;
619
620 let (action, tooltip) = if is_active_button {
621 let action = dock.toggle_action();
622
623 let tooltip: SharedString =
624 format!("Close {} dock", dock.position.to_label()).into();
625
626 (action, tooltip)
627 } else {
628 let action = entry.panel.toggle_action(cx);
629
630 (action, name.into())
631 };
632
633 Some(
634 right_click_menu(name)
635 .menu(move |cx| {
636 const POSITIONS: [DockPosition; 3] = [
637 DockPosition::Left,
638 DockPosition::Right,
639 DockPosition::Bottom,
640 ];
641
642 ContextMenu::build(cx, |mut menu, cx| {
643 for position in POSITIONS {
644 if position != dock_position
645 && panel.position_is_valid(position, cx)
646 {
647 let panel = panel.clone();
648 menu = menu.entry(position.to_label(), None, move |cx| {
649 panel.set_position(position, cx);
650 })
651 }
652 }
653 menu
654 })
655 })
656 .anchor(menu_anchor)
657 .attach(menu_attach)
658 .trigger(
659 IconButton::new(name, icon)
660 .icon_size(IconSize::Small)
661 .selected(is_active_button)
662 .on_click({
663 let action = action.boxed_clone();
664 move |_, cx| cx.dispatch_action(action.boxed_clone())
665 })
666 .tooltip(move |cx| {
667 Tooltip::for_action(tooltip.clone(), &*action, cx)
668 }),
669 ),
670 )
671 });
672
673 h_stack().gap_0p5().children(buttons)
674 }
675}
676
677impl StatusItemView for PanelButtons {
678 fn set_active_pane_item(
679 &mut self,
680 _active_pane_item: Option<&dyn crate::ItemHandle>,
681 _cx: &mut ViewContext<Self>,
682 ) {
683 // Nothing to do, panel buttons don't depend on the active center item
684 }
685}
686
687#[cfg(any(test, feature = "test-support"))]
688pub mod test {
689 use super::*;
690 use gpui::{actions, div, ViewContext, WindowContext};
691
692 pub struct TestPanel {
693 pub position: DockPosition,
694 pub zoomed: bool,
695 pub active: bool,
696 pub focus_handle: FocusHandle,
697 pub size: Pixels,
698 }
699 actions!(test, [ToggleTestPanel]);
700
701 impl EventEmitter<PanelEvent> for TestPanel {}
702
703 impl TestPanel {
704 pub fn new(position: DockPosition, cx: &mut WindowContext) -> Self {
705 Self {
706 position,
707 zoomed: false,
708 active: false,
709 focus_handle: cx.focus_handle(),
710 size: px(300.),
711 }
712 }
713 }
714
715 impl Render for TestPanel {
716 fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl Element {
717 div()
718 }
719 }
720
721 impl Panel for TestPanel {
722 fn persistent_name() -> &'static str {
723 "TestPanel"
724 }
725
726 fn position(&self, _: &gpui::WindowContext) -> super::DockPosition {
727 self.position
728 }
729
730 fn position_is_valid(&self, _: super::DockPosition) -> bool {
731 true
732 }
733
734 fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>) {
735 self.position = position;
736 cx.emit(PanelEvent::ChangePosition);
737 }
738
739 fn size(&self, _: &WindowContext) -> Pixels {
740 self.size
741 }
742
743 fn set_size(&mut self, size: Option<Pixels>, _: &mut ViewContext<Self>) {
744 self.size = size.unwrap_or(px(300.));
745 }
746
747 fn icon(&self, _: &WindowContext) -> Option<ui::Icon> {
748 None
749 }
750
751 fn toggle_action(&self) -> Box<dyn Action> {
752 ToggleTestPanel.boxed_clone()
753 }
754
755 fn is_zoomed(&self, _: &WindowContext) -> bool {
756 self.zoomed
757 }
758
759 fn set_zoomed(&mut self, zoomed: bool, _cx: &mut ViewContext<Self>) {
760 self.zoomed = zoomed;
761 }
762
763 fn set_active(&mut self, active: bool, _cx: &mut ViewContext<Self>) {
764 self.active = active;
765 }
766 }
767
768 impl FocusableView for TestPanel {
769 fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {
770 self.focus_handle.clone()
771 }
772 }
773}