dock: Support hide dock toggle buttons (#726)
This commit is contained in:
parent
a89f971108
commit
0d1c40a56a
3 changed files with 35 additions and 1 deletions
|
|
@ -22,6 +22,7 @@ pub struct AddPanel(DockPlacement);
|
||||||
pub struct TogglePanelVisible(SharedString);
|
pub struct TogglePanelVisible(SharedString);
|
||||||
|
|
||||||
impl_internal_actions!(story, [AddPanel, TogglePanelVisible]);
|
impl_internal_actions!(story, [AddPanel, TogglePanelVisible]);
|
||||||
|
actions!(story, [ToggleDockToggleButton]);
|
||||||
|
|
||||||
const MAIN_DOCK_AREA: DockAreaTab = DockAreaTab {
|
const MAIN_DOCK_AREA: DockAreaTab = DockAreaTab {
|
||||||
id: "main-dock",
|
id: "main-dock",
|
||||||
|
|
@ -41,6 +42,7 @@ pub struct StoryWorkspace {
|
||||||
title_bar: Entity<AppTitleBar>,
|
title_bar: Entity<AppTitleBar>,
|
||||||
dock_area: Entity<DockArea>,
|
dock_area: Entity<DockArea>,
|
||||||
last_layout_state: Option<DockAreaState>,
|
last_layout_state: Option<DockAreaState>,
|
||||||
|
toggle_button_visible: bool,
|
||||||
_save_layout_task: Option<Task<()>>,
|
_save_layout_task: Option<Task<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,6 +124,11 @@ impl StoryWorkspace {
|
||||||
Box::new(AddPanel(DockPlacement::Bottom)),
|
Box::new(AddPanel(DockPlacement::Bottom)),
|
||||||
)
|
)
|
||||||
.separator()
|
.separator()
|
||||||
|
.menu(
|
||||||
|
"Show / Hide Dock Toggle Button",
|
||||||
|
Box::new(ToggleDockToggleButton),
|
||||||
|
)
|
||||||
|
.separator()
|
||||||
.menu_with_check(
|
.menu_with_check(
|
||||||
"Sidebar",
|
"Sidebar",
|
||||||
!invisible_panels
|
!invisible_panels
|
||||||
|
|
@ -133,7 +140,7 @@ impl StoryWorkspace {
|
||||||
"Modal",
|
"Modal",
|
||||||
!invisible_panels
|
!invisible_panels
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.contains(&SharedString::from("SidebModalar")),
|
.contains(&SharedString::from("Modal")),
|
||||||
Box::new(TogglePanelVisible(SharedString::from("Modal"))),
|
Box::new(TogglePanelVisible(SharedString::from("Modal"))),
|
||||||
)
|
)
|
||||||
.menu_with_check(
|
.menu_with_check(
|
||||||
|
|
@ -161,6 +168,7 @@ impl StoryWorkspace {
|
||||||
dock_area,
|
dock_area,
|
||||||
title_bar,
|
title_bar,
|
||||||
last_layout_state: None,
|
last_layout_state: None,
|
||||||
|
toggle_button_visible: true,
|
||||||
_save_layout_task: None,
|
_save_layout_task: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -468,6 +476,19 @@ impl StoryWorkspace {
|
||||||
});
|
});
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn on_action_toggle_dock_toggle_button(
|
||||||
|
&mut self,
|
||||||
|
_: &ToggleDockToggleButton,
|
||||||
|
_: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
self.toggle_button_visible = !self.toggle_button_visible;
|
||||||
|
|
||||||
|
self.dock_area.update(cx, |dock_area, _| {
|
||||||
|
dock_area.show_toggle_button(self.toggle_button_visible);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_new(
|
pub fn open_new(
|
||||||
|
|
@ -494,6 +515,7 @@ impl Render for StoryWorkspace {
|
||||||
.id("story-workspace")
|
.id("story-workspace")
|
||||||
.on_action(cx.listener(Self::on_action_add_panel))
|
.on_action(cx.listener(Self::on_action_add_panel))
|
||||||
.on_action(cx.listener(Self::on_action_toggle_panel_visible))
|
.on_action(cx.listener(Self::on_action_toggle_panel_visible))
|
||||||
|
.on_action(cx.listener(Self::on_action_toggle_dock_toggle_button))
|
||||||
.relative()
|
.relative()
|
||||||
.size_full()
|
.size_full()
|
||||||
.flex()
|
.flex()
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,8 @@ pub struct DockArea {
|
||||||
/// The entity_id of the [`TabPanel`](TabPanel) where each toggle button should be displayed,
|
/// The entity_id of the [`TabPanel`](TabPanel) where each toggle button should be displayed,
|
||||||
toggle_button_panels: Edges<Option<EntityId>>,
|
toggle_button_panels: Edges<Option<EntityId>>,
|
||||||
|
|
||||||
|
/// Whether to show the toggle button.
|
||||||
|
toggle_button_visible: bool,
|
||||||
/// The left dock of the dock_area.
|
/// The left dock of the dock_area.
|
||||||
left_dock: Option<Entity<Dock>>,
|
left_dock: Option<Entity<Dock>>,
|
||||||
/// The bottom dock of the dock_area.
|
/// The bottom dock of the dock_area.
|
||||||
|
|
@ -456,6 +458,7 @@ impl DockArea {
|
||||||
items: dock_item,
|
items: dock_item,
|
||||||
zoom_view: None,
|
zoom_view: None,
|
||||||
toggle_button_panels: Edges::default(),
|
toggle_button_panels: Edges::default(),
|
||||||
|
toggle_button_visible: true,
|
||||||
left_dock: None,
|
left_dock: None,
|
||||||
right_dock: None,
|
right_dock: None,
|
||||||
bottom_dock: None,
|
bottom_dock: None,
|
||||||
|
|
@ -680,6 +683,7 @@ impl DockArea {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Toggle the dock at the given placement.
|
||||||
pub fn toggle_dock(
|
pub fn toggle_dock(
|
||||||
&self,
|
&self,
|
||||||
placement: DockPlacement,
|
placement: DockPlacement,
|
||||||
|
|
@ -700,6 +704,11 @@ impl DockArea {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Show or hide the toggle button.
|
||||||
|
pub fn show_toggle_button(&mut self, visible: bool) {
|
||||||
|
self.toggle_button_visible = visible;
|
||||||
|
}
|
||||||
|
|
||||||
/// Add a panel item to the dock area at the given placement.
|
/// Add a panel item to the dock area at the given placement.
|
||||||
pub fn add_panel(
|
pub fn add_panel(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
||||||
|
|
@ -492,6 +492,9 @@ impl TabPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
let dock_area = self.dock_area.upgrade()?.read(cx);
|
let dock_area = self.dock_area.upgrade()?.read(cx);
|
||||||
|
if !dock_area.toggle_button_visible {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
if !dock_area.is_dock_collapsible(placement, cx) {
|
if !dock_area.is_dock_collapsible(placement, cx) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue