forked from 1b-agent/opencadstudio-upstream
feat(viewport): hide ViewCube then render bar as the viewport narrows
When the viewport got too narrow the top-left render-mode bar and the top-right ViewCube overlapped. Hide them adaptively, measuring the render bar's real width rather than guessing: - Wrap the render bar in DensitySwap, which measures its natural width every frame and swaps it for an empty spacer once it no longer fits the tile. Add report_width0 so it publishes that measured width to render_bar_w. - Compute viewcube_visible from that measured width: the cube shows only while bar_w + gap + cube region fits. This one flag drives the ViewCube nav/UCS widgets, the hover hit-test, and — threaded through build_viewports / build_viewport_for_pane / viewport_data_for — the GPU cube itself, which previously ignored the pane flag (show_viewcube was inst.active only), so the cube stayed while its surrounding widgets vanished. Result: the ViewCube gives way first, then the render bar once it too has no room — no overlap, sized to the bar's real width (which varies with the render-mode label, split buttons and tile count). Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
07eb9dcb9a
commit
7cba5c8679
5 files changed
+128
-27
No files matched your search
@@ -846,6 +846,7 @@ impl Scene {
|
||||
bounds: Rectangle,
|
||||
model_render_mode: acadrust::entities::ViewportRenderMode,
|
||||
_hover_region: Option<usize>,
|
||||
show_viewcube: bool,
|
||||
) -> Primitive {
|
||||
// Hover comes from the scene cell driven by the app-level
|
||||
// `CursorMoved` handler — the cube overlay sits above the shader
|
||||
@@ -864,7 +865,7 @@ impl Scene {
|
||||
let bg_color = [0.0, 0.0, 0.0, 0.0];
|
||||
let viewports: Vec<ViewportData> = instances
|
||||
.iter()
|
||||
.filter_map(|inst| self.viewport_data_for(inst, canvas, hover_region))
|
||||
.filter_map(|inst| self.viewport_data_for(inst, canvas, hover_region, show_viewcube))
|
||||
.collect();
|
||||
// Empty viewports → blit nothing; the container background (model bg
|
||||
// or the paper desk colour) stays visible.
|
||||
@@ -886,6 +887,7 @@ impl Scene {
|
||||
bounds: Rectangle,
|
||||
tile_idx: usize,
|
||||
model_render_mode: acadrust::entities::ViewportRenderMode,
|
||||
show_viewcube: bool,
|
||||
) -> Primitive {
|
||||
let hover_region = self.viewcube_hover.get();
|
||||
let canvas = (bounds.width.max(1.0), bounds.height.max(1.0));
|
||||
@@ -926,7 +928,7 @@ impl Scene {
|
||||
paper_sheet: false,
|
||||
};
|
||||
let viewports = self
|
||||
.viewport_data_for(&inst, canvas, hover_region)
|
||||
.viewport_data_for(&inst, canvas, hover_region, show_viewcube)
|
||||
.into_iter()
|
||||
.collect();
|
||||
Primitive {
|
||||
@@ -945,6 +947,7 @@ impl Scene {
|
||||
inst: &ViewportInstance,
|
||||
canvas: (f32, f32),
|
||||
hover_region: Option<usize>,
|
||||
show_viewcube: bool,
|
||||
) -> Option<ViewportData> {
|
||||
let flags = render_mode_flags(inst.render_mode);
|
||||
let view_wireframe = !flags.face3d_fill;
|
||||
@@ -1159,7 +1162,10 @@ impl Scene {
|
||||
compass_rotation: inst.camera.view_rotation_mat(),
|
||||
// Only the active viewport gets the hovered-region highlight.
|
||||
hover_region: if inst.active { hover_region } else { None },
|
||||
show_viewcube: inst.active,
|
||||
// The cube shows only on the active viewport, and only while the
|
||||
// caller (the widget) says there is room for it beside the render
|
||||
// bar — so it hides adaptively when the viewport gets narrow.
|
||||
show_viewcube: inst.active && show_viewcube,
|
||||
fill_mode: self.document.header.fill_mode,
|
||||
view_wireframe,
|
||||
mesh_fill: flags.mesh_fill,
|
||||
|
||||
@@ -69,12 +69,18 @@ impl<'a, Msg: std::fmt::Debug + Clone> shader::Program<Msg> for ViewportPane<'a>
|
||||
bounds: Rectangle,
|
||||
) -> Self::Primitive {
|
||||
match self.pane {
|
||||
Some(idx) => self
|
||||
.scene
|
||||
.build_viewport_for_pane(bounds, idx, self.render_mode),
|
||||
None => self
|
||||
.scene
|
||||
.build_viewports(bounds, self.render_mode, state.hover_region),
|
||||
Some(idx) => self.scene.build_viewport_for_pane(
|
||||
bounds,
|
||||
idx,
|
||||
self.render_mode,
|
||||
self.show_viewcube,
|
||||
),
|
||||
None => self.scene.build_viewports(
|
||||
bounds,
|
||||
self.render_mode,
|
||||
state.hover_region,
|
||||
self.show_viewcube,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user