dock: Make the panel inner padding controllable (#613)

This commit is contained in:
Floyd Wang 2025-02-10 17:55:57 +08:00 committed by GitHub
parent cd9c88a0f7
commit 44e678b9bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View file

@ -119,6 +119,11 @@ pub trait Panel: EventEmitter<PanelEvent> + Render + Focusable {
fn dump(&self, cx: &App) -> PanelState {
PanelState::new(self)
}
/// Whether the panel has inner padding when the panel is in the tabs layout, default is `true`.
fn inner_padding(&self, cx: &App) -> bool {
true
}
}
/// The PanelView trait used to define the panel view.
@ -137,6 +142,7 @@ pub trait PanelView: 'static + Send + Sync {
fn view(&self) -> AnyView;
fn focus_handle(&self, cx: &App) -> FocusHandle;
fn dump(&self, cx: &App) -> PanelState;
fn inner_padding(&self, cx: &App) -> bool;
}
impl<T: Panel> PanelView for Entity<T> {
@ -195,6 +201,10 @@ impl<T: Panel> PanelView for Entity<T> {
fn dump(&self, cx: &App) -> PanelState {
self.read(cx).dump(cx)
}
fn inner_padding(&self, cx: &App) -> bool {
self.read(cx).inner_padding(cx)
}
}
impl From<&dyn PanelView> for AnyView {

View file

@ -131,6 +131,11 @@ impl Panel for TabPanel {
}
state
}
fn inner_padding(&self, cx: &App) -> bool {
self.active_panel(cx)
.map_or(true, |panel| panel.inner_padding(cx))
}
}
impl TabPanel {
@ -761,7 +766,7 @@ impl TabPanel {
return Empty {}.into_any_element();
};
let is_render_in_tabs = self.panels.len() > 1;
let is_render_in_tabs = self.panels.len() > 1 && self.inner_padding(cx);
v_flex()
.id("tab-content")