panel: Always not show active tab style, when the dock is collapsed. (#335)

## Before

<img width="249" alt="image"
src="https://github.com/user-attachments/assets/2dfee593-1a07-4b75-913b-d2e17decb67a">

## After

<img width="271" alt="image"
src="https://github.com/user-attachments/assets/20752d04-1f25-498c-8e6e-4ff0f21401bf">
This commit is contained in:
Jason Lee 2024-10-14 10:06:20 +08:00 committed by GitHub
parent 5c8d0d7eb4
commit 5fd2ebf522
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 5 deletions

View file

@ -111,6 +111,12 @@ impl Dock {
) -> Self {
Self::subscribe_panel_events(dock_area.clone(), panel.clone(), cx);
if !open {
panel.update(cx, |panel, cx| {
panel.set_collapsed(true, cx);
});
}
Self {
placement,
dock_area,
@ -149,8 +155,7 @@ impl Dock {
}
pub fn toggle_open(&mut self, cx: &mut ViewContext<Self>) {
self.open = !self.open;
cx.notify();
self.set_open(!self.open, cx);
}
/// Returns the size of the Dock, the size is means the width or height of
@ -169,6 +174,11 @@ impl Dock {
/// Set the open state of the Dock.
pub fn set_open(&mut self, open: bool, cx: &mut ViewContext<Self>) {
self.open = open;
cx.defer(move |this, cx| {
this.panel.update(cx, |panel, cx| {
panel.set_collapsed(!open, cx);
});
});
cx.notify();
}

View file

@ -63,12 +63,14 @@ pub struct TabPanel {
stack_panel: Option<View<StackPanel>>,
pub(crate) panels: Vec<Arc<dyn PanelView>>,
pub(crate) active_ix: usize,
tab_bar_scroll_handle: ScrollHandle,
is_zoomed: bool,
/// If this is true, the Panel closeable will follow the active panel's closeable,
/// otherwise this TabPanel will not able to close
pub(crate) closeable: bool,
tab_bar_scroll_handle: ScrollHandle,
is_zoomed: bool,
is_collapsed: bool,
/// When drag move, will get the placement of the panel to be split
will_split_placement: Option<Placement>,
}
@ -139,6 +141,7 @@ impl TabPanel {
tab_bar_scroll_handle: ScrollHandle::new(),
will_split_placement: None,
is_zoomed: false,
is_collapsed: false,
closeable: true,
}
}
@ -261,6 +264,11 @@ impl TabPanel {
self.stack_panel.is_some()
}
pub(super) fn set_collapsed(&mut self, collapsed: bool, cx: &mut ViewContext<Self>) {
self.is_collapsed = collapsed;
cx.notify();
}
fn render_menu_button(&self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let closeable = self.closeable(cx);
let zoomable = self.zoomable(cx);
@ -542,7 +550,13 @@ impl TabPanel {
},
)
.children(self.panels.iter().enumerate().map(|(ix, panel)| {
let active = ix == self.active_ix;
let mut active = ix == self.active_ix;
// Always not show active tab style, if the panel is collapsed
if self.is_collapsed {
active = false;
}
Tab::new(("tab", ix), panel.title(cx))
.py_2()
.selected(active)