Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy/wtDeployVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.2
2.4.3
3 changes: 3 additions & 0 deletions deploy/wtPackageRelease.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
% Perform the packaging
matlab.addons.toolbox.packageToolbox(opts);

% Add the installer to the project
proj.addFile(outputFile)


%% Open the release folder

Expand Down
Binary file added release/Widgets Toolbox 2.4.3.mltbx
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="Widgets Toolbox 2.4.3.mltbx" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="moveOnScreen.m" type="File"/>
75 changes: 2 additions & 73 deletions widgets/+wt/+apps/BaseApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -386,79 +386,8 @@ function moveOnScreen(app)
% Show output if Debug is on
app.displayDebugText();

if strcmp(app.Figure.Units,'pixels')

% Get the corners of each screen
g = groot;
screenPos = g.MonitorPositions;
screenCornerA = screenPos(:,1:2);
screenCornerB = screenPos(:,1:2) + screenPos(:,3:4) - 1;

% Buffer for title bar
titleBarHeight = 30;

% Get the corners of the figure (bottom left and top right)
figPos = app.Figure.OuterPosition;
figCornerA = figPos(1:2);
figCornerB = figPos(1:2) + figPos(:,3:4) - 1;

% Are the corners on any screen?
aIsOnScreen = all( figCornerA >= screenCornerA & ...
figCornerA <= screenCornerB, 2 );
bIsOnScreen = all( figCornerB >= screenCornerA & ...
figCornerB <= screenCornerB, 2);

% Are corners on a screen?

% Are both corners fully on any screen?
if any(aIsOnScreen) && any(bIsOnScreen)
% Yes - do nothing

elseif any(bIsOnScreen)
% No - only upper right corner is on a screen

% Calculate the adjustment needed, and make it
figAdjust = max(figCornerA, screenCornerA(bIsOnScreen,:)) ...
- figCornerA;
figPos(1:2) = figPos(1:2) + figAdjust;

% Ensure the upper right corner still fits
figPos(3:4) = min(figPos(3:4), ...
screenCornerB(bIsOnScreen,:) - figPos(1:2) - [0 titleBarHeight] + 1);

% Move the figure
app.Figure.Position = figPos;

elseif any(aIsOnScreen)
% No - only lower left corner is on a screen

% Calculate the adjustment needed, and make it
figAdjust = min(figCornerB, screenCornerB(aIsOnScreen,:)) ...
- figCornerB;
figPos(1:2) = max( screenCornerA(aIsOnScreen,:),...
figPos(1:2) + figAdjust );

% Ensure the upper right corner still fits
figPos(3:4) = min(figPos(3:4), ...
screenCornerB(aIsOnScreen,:) - figPos(1:2) - [0 titleBarHeight] + 1);

% Move the figure
app.Figure.Position = figPos;

else
% No - Not on any screen

% This is slower, but uncommon anyway
movegui(app.Figure,'onscreen');

end %if any( all(aIsOnScreen,2) & all(bIsOnScreen,2) )

else

% This is slower, but uncommon anyway
movegui(app.Figure,'onscreen');

end %if strcmp(app.Figure.Units,'pixels')
% Move it on screen
wt.utility.moveOnScreen(app.Figure);

end %function

Expand Down
87 changes: 87 additions & 0 deletions widgets/+wt/+utility/moveOnScreen.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
function moveOnScreen(fig)
% Ensure the figure is placed on screen

% Copyright 2025 The MathWorks, Inc.

% Define arguments
arguments
fig (1,1) matlab.ui.Figure
end

% Figure must be in pixel units
if ~strcmp(fig.Units,'pixels')
oldUnits = fig.Units;
cleanupObj = onCleanup(@()set(fig,"Units",oldUnits));
fig.Units = 'pixels';
end

% Get screen positions
g = groot;
screenPos = g.MonitorPositions;

% Buffer for title bar
titleBarHeight = 30;

% Get the corners of the figure (bottom left and top right)
figPos = fig.OuterPosition;
figCornerA = figPos(1:2);
figCornerB = figPos(1:2) + figPos(:,3:4) - 1;

% Calculate the figure's area shown on each screen
overlapAreas = zeros(size(screenPos, 1), 1);
for i = 1:size(screenPos, 1)
thisScreen = screenPos(i, :);
overlapWidth = max(0, min(figPos(1) + figPos(3), thisScreen(1) + thisScreen(3)) - max(figPos(1), thisScreen(1)));
overlapHeight = max(0, min(figPos(2) + figPos(4), thisScreen(2) + thisScreen(4)) - max(figPos(2), thisScreen(2)));
overlapAreas(i) = overlapWidth * overlapHeight;
end

% Determine the screen with the largest overlap
[~, screenIdx] = max(overlapAreas);

% Get the corners of the screen
screenCornerA = screenPos(screenIdx, 1:2);
screenCornerB = screenCornerA + screenPos(screenIdx, 3:4) - 1;

% Are the corners on the screen?
aIsOnScreen = all( figCornerA >= screenCornerA & ...
figCornerA <= screenCornerB, 2 );
bIsOnScreen = all( figCornerB >= screenCornerA & ...
figCornerB <= screenCornerB, 2);


% Are both corners fully on one screen?
if aIsOnScreen && bIsOnScreen
% Yes - do nothing

elseif bIsOnScreen
% Upper right corner is on a screen
% Adjust so the entire figure is on that screen

% Calculate the adjustment needed, and make it
figAdjust = max(figCornerA, screenCornerA) - figCornerA;
figPos(1:2) = figPos(1:2) + figAdjust;

% Ensure the upper right corner still fits
requestedSize = screenCornerB - figPos(1:2) - [0 titleBarHeight] + 1;
figPos(3:4) = min(figPos(3:4), requestedSize);

% Move the figure
fig.Position = figPos;

else
% Lower left corner is on a screen
% Adjust so the entire figure is on that screen

% Calculate the adjustment needed, and make it
figAdjust = min(figCornerB, screenCornerB) - figCornerB;
figPos(1:2) = max(screenCornerA, figPos(1:2) + figAdjust);

% Ensure the upper right corner still fits
requestedSize = screenCornerB - figPos(1:2) - [0 titleBarHeight] + 1;
figPos(3:4) = min(figPos(3:4), requestedSize);

% Move the figure
fig.Position = figPos;

end %if