diff --git a/src/app/view.rs b/src/app/view.rs index e7f7053bb..7b6b69876 100644 --- a/src/app/view.rs +++ b/src/app/view.rs @@ -166,6 +166,7 @@ impl H7CAD { tab.scene.current_layout.clone(), self.layout_rename_state.as_ref(), tab.scene.first_viewport_scale(), + tab.scene.viewport_count(), ) ] .width(Fill) diff --git a/src/scene/mod.rs b/src/scene/mod.rs index 9a40c5354..2b84d77bd 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -228,6 +228,24 @@ impl Scene { }) } + /// Count of user viewports (id > 1) in the current layout. + pub fn viewport_count(&self) -> usize { + if self.current_layout == "Model" { + return 0; + } + let layout_block = self.current_layout_block_handle(); + if layout_block.is_null() { + return 0; + } + self.document.entities().filter(|e| { + if let EntityType::Viewport(vp) = e { + vp.id > 1 && vp.common.owner_handle == layout_block + } else { + false + } + }).count() + } + /// Sorted list of layout names: "Model" first, then paper layouts by tab order. pub fn layout_names(&self) -> Vec { let mut names = vec!["Model".to_string()]; diff --git a/src/ui/statusbar.rs b/src/ui/statusbar.rs index a8246d6e0..adcb1d81c 100644 --- a/src/ui/statusbar.rs +++ b/src/ui/statusbar.rs @@ -33,6 +33,8 @@ impl StatusBar { rename_state: Option<&'a (String, String)>, // Scale of the first user viewport in the active paper layout. viewport_scale: Option, + // Number of user viewports in the current paper layout (0 = model space). + viewport_count: usize, ) -> Element<'a, Message> { let menu_btn = button(text("≡").size(14).color(ICON_COLOR)) .on_press(Message::Command("MENU".into())) @@ -60,7 +62,12 @@ impl StatusBar { "LAYOUT" }; let scale_label = format_scale(viewport_scale); - let right_status = row![ + let vp_label = if viewport_count > 0 { + format!("{} VP", viewport_count) + } else { + String::new() + }; + let mut right_status = row![ tip( toggle_pill("SNAP", snap_grid_on, Message::ToggleGridSnap), "Snap to Grid\nF9" @@ -82,6 +89,13 @@ impl StatusBar { status_pill(scale_label), ] .spacing(2); + if !vp_label.is_empty() { + right_status = right_status.push(tip( + status_pill(vp_label).into(), + "Viewport count in active layout", + )); + } + let right_status = right_status; let mut bar = Row::new().align_y(iced::Center).spacing(0); bar = bar.push(menu_btn);