chore: reduce component overhead (#3)

Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
2026-11-09 10:09:56 +00:00
parent 6815585528
commit 1c091db699
44 changed files with 1376 additions and 1241 deletions
+40 -22
View File
@@ -192,10 +192,8 @@ impl DockState {
}
/// Registers a panel descriptor, replacing any earlier one with its id.
pub fn register_panel(&mut self, panel: PanelDescriptor, cx: &mut Context<Self>) {
if self.panels.insert(panel.id.clone(), panel).is_none() {
cx.notify();
}
pub fn register_panel(&mut self, panel: PanelDescriptor) {
self.panels.insert(panel.id.clone(), panel);
}
/// Opens a panel into the active pane and activates its tab.
@@ -330,6 +328,17 @@ impl DockState {
};
if changed {
// The kept tab may have no right view, show the first remaining one.
self.right_view = self
.locate(id)
.and_then(|(pane_key, _)| self.pane(pane_key))
.and_then(|pane| {
pane.active.as_deref().and_then(|active| {
pane.tabs.iter().find(|tab| tab.panel.as_ref() == active)
})
})
.and_then(|tab| tab.right_view.clone())
.or_else(|| first_right_view(&self.root));
cx.notify();
}
}
@@ -354,10 +363,14 @@ impl DockState {
}
self.detach_pane(pane_key);
if self.active_pane == pane_key {
self.active_pane = self.first_pane_key().unwrap_or(0);
}
// The closed pane's views are gone; show the first remaining one.
self.right_view = first_right_view(&self.root);
cx.notify();
}
@@ -526,6 +539,19 @@ impl DockState {
}
}
fn pane(&self, key: u64) -> Option<&Pane> {
Self::pane_in(&self.root, key)
}
fn pane_in(node: &Node, key: u64) -> Option<&Pane> {
match node {
Node::Pane(pane) => (pane.key == key).then_some(pane),
Node::Split(split) => {
Self::pane_in(&split.a, key).or_else(|| Self::pane_in(&split.b, key))
}
}
}
fn pane_mut(&mut self, key: u64) -> Option<&mut Pane> {
Self::pane_mut_in(&mut self.root, key)
}
@@ -969,15 +995,10 @@ fn render_pane(
.map(|tab| tab.view.clone());
// The cache keeps an un-notified panel from re-rendering on dock frames.
let content_id = SharedString::from(format!("{dock_id}-content-{}", pane.key));
let content = div()
.id(SharedString::from(format!(
"{dock_id}-content-{}",
pane.key
)))
.debug_selector({
let id = SharedString::from(format!("{dock_id}-content-{}", pane.key));
move || id.to_string()
})
.id(content_id.clone())
.debug_selector(move || content_id.to_string())
.flex_1()
.min_h_0()
.overflow_hidden()
@@ -999,6 +1020,7 @@ fn render_pane(
let pane = pane.clone();
let titlebar = *titlebar;
let padding_x = metrics.dense_padding_x;
move |window, cx| {
let selected = pane
.active
@@ -1016,7 +1038,7 @@ fn render_pane(
move |_, _| {
tabs.iter()
.map(|tab| {
let mut entry = Tab::new(tab.title.clone());
let mut entry = Tab::new(tab.panel.clone(), tab.title.clone());
if let Some(role) = tab.icon {
entry = entry.icon(role);
}
@@ -1065,21 +1087,17 @@ fn render_pane(
}
});
let bar_id = SharedString::from(format!("{dock_id}-pane-{}-bar", pane.key));
h_flex()
.id(SharedString::from(format!(
"{dock_id}-pane-{}-bar",
pane.key
)))
.debug_selector({
let id = SharedString::from(format!("{dock_id}-pane-{}-bar", pane.key));
move || id.to_string()
})
.id(bar_id.clone())
.debug_selector(move || bar_id.to_string())
.flex_none()
.w_full()
.h(titlebar.height)
.items_center()
.pl(if titlebar.traffic_light_pad {
px(TRAFFIC_LIGHT_PAD)
TRAFFIC_LIGHT_PAD
} else {
padding_x
})