Skip to content

Commit 49d6cec

Browse files
shortcut for toggling visibility
1 parent 4a4581d commit 49d6cec

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/+gfx/+internal/Orbit3d.m

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
% Key t: Toggle transparency of selected obj
1313
% Key w: Toggle wireframe of selected patch
1414
% Key c: Toggle color of selected obj
15+
% Key v: Toggle visibility of selected obj
1516
% Key g: Toggle grid
1617
% Key b: Show object browser
1718
% Key h: Show help
@@ -36,7 +37,7 @@
3637
% "KeyPress", @(~,evnt)disp(evnt.Key), hFigure);
3738
%
3839
% AUTHOR
39-
% Copyright 2022-2025, Markus Leuthold, markus.leuthold@sonova.com
40+
% Copyright 2022-2026, Markus Leuthold, markus.leuthold@sonova.com
4041
%
4142
% LICENSE
4243
% BSD-3-Clause (https://opensource.org/licenses/BSD-3-Clause)
@@ -54,6 +55,7 @@
5455
self.keyboardShortcuts.Wireframe = 'w';
5556
self.keyboardShortcuts.Transparency = 't';
5657
self.keyboardShortcuts.Color = 'c';
58+
self.keyboardShortcuts.Visibility = 'v';
5759
self.keyboardShortcuts.Grid = 'g';
5860
self.keyboardShortcuts.Help = 'h';
5961
self.keyboardShortcuts.ObjectBrowser = 'b';
@@ -242,6 +244,9 @@ function keyPressCallback(self, hFig, keyData)
242244
case self.keyboardShortcuts.Color
243245
self.toggleColor(hFig)
244246

247+
case self.keyboardShortcuts.Visibility
248+
self.toggleVisibility(hFig.CurrentObject)
249+
245250
case self.keyboardShortcuts.Grid
246251
self.toggleGrid(hFig.CurrentAxes)
247252

@@ -308,6 +313,23 @@ function toggleColor(self, hFig)
308313
self.updateBrowser(hFig);
309314
end
310315

316+
function toggleVisibility(~, hObj)
317+
if ismember(hObj.Type, ["figure" "uigridlayout"])
318+
% This would close the window or remove GUI elements,
319+
% which is unwanted
320+
return
321+
end
322+
323+
% If there's a scenegraph built with hggroup, identify the
324+
% top-level hggroup to toggle the visibility of the entire tree
325+
hgTopLevel = ancestor(hObj, "hggroup", "toplevel");
326+
if ~isempty(hgTopLevel)
327+
hObj = hgTopLevel;
328+
end
329+
330+
hObj.Visible = ~hObj.Visible;
331+
end
332+
311333
function toggleGrid(~, hAxes)
312334
hAxes.Visible = ~hAxes.Visible;
313335
grid(hAxes, "on");
@@ -326,8 +348,9 @@ function toggleHelp(~, hFig)
326348
uilabel("Parent",hFig,"Text","w: wireframe", "Position", [10 90 200 20], "Tag","help");
327349
uilabel("Parent",hFig,"Text","c: next color", "Position", [10 110 200 20], "Tag","help");
328350
uilabel("Parent",hFig,"Text","t: transparency", "Position", [10 130 200 20], "Tag","help");
329-
uilabel("Parent",hFig,"Text","g: grid", "Position", [10 150 200 20], "Tag","help");
330-
uilabel("Parent",hFig,"Text","b: object browser", "Position", [10 170 200 20], "Tag","help");
351+
uilabel("Parent",hFig,"Text","v: visibility", "Position", [10 150 200 20], "Tag","help");
352+
uilabel("Parent",hFig,"Text","g: grid", "Position", [10 170 200 20], "Tag","help");
353+
uilabel("Parent",hFig,"Text","b: object browser", "Position", [10 190 200 20], "Tag","help");
331354
else
332355
delete(hHelp)
333356
end

src/+gfx/orbit3d.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ function orbit3d(hAxes)
1212
% Key t: Toggle transparency of selected obj
1313
% Key w: Toggle wireframe of selected patch
1414
% Key c: Toggle color of selected obj
15+
% Key v: Toggle visibility of selected obj
1516
% Key g: Toggle grid
17+
% Key b: Show object browser
1618
% Key h: Show help
1719
%
1820
% USER DEFINED KEYBOARD SHORTCUTS
@@ -43,7 +45,7 @@ function orbit3d(hAxes)
4345
% uiaxes()
4446
%
4547
% AUTHOR
46-
% Copyright 2022-2023, Markus Leuthold, markus.leuthold@sonova.com
48+
% Copyright 2022-2026, Markus Leuthold, markus.leuthold@sonova.com
4749
%
4850
% LICENSE
4951
% BSD-3-Clause (https://opensource.org/licenses/BSD-3-Clause)

0 commit comments

Comments
 (0)