From 2b5735820f70b20dcd7171dd63fc1d607e838e35 Mon Sep 17 00:00:00 2001 From: giuliaghirardini <giulia.ghirardini@skywarder.eu> Date: Sat, 8 Mar 2025 19:19:00 +0100 Subject: [PATCH] [fixes][utilities] Added new buttons, applied some suggestions and added tooltip --- functions/utilities/exportFigureGUI.m | 80 +++++++++++++++++++++------ 1 file changed, 64 insertions(+), 16 deletions(-) diff --git a/functions/utilities/exportFigureGUI.m b/functions/utilities/exportFigureGUI.m index e675458..08609b8 100644 --- a/functions/utilities/exportFigureGUI.m +++ b/functions/utilities/exportFigureGUI.m @@ -20,7 +20,7 @@ screenWidth = screenSize(3); screenHeight = screenSize(4); % Define an offset from the top of the screen -topOffset = figY; +topOffset = figY; leftOffset = figX; % Calculate the position for the new figures @@ -40,19 +40,21 @@ titleLabel.Position = [0, fig.Position(4)-50, fig.Position(3), 30]; %% Input fields % Figure Name uilabel(fig, 'Text', 'Figure Name:', 'Position', [50 550 100 30]); -figNameField = uitextarea(fig, 'Position', [150 550 200 30]); +figNameField = uieditfield(fig, 'text', 'Position', [150 550 200 30], ... + 'ValueChangedFcn', @(src, event) emptyNameField(src,event)); % WHratio Input uilabel(fig, 'Text', 'Width/Height Ratio:', 'Position', [50 170 150 30]); -WHratioField = uieditfield(fig, 'numeric', 'Value', 0, 'Position', [180 170 50 30]); +WHratioField = uieditfield(fig, 'numeric', 'Value', 0, 'Position', [160 170 50 30]); % Forced Markers Input -uilabel(fig, 'Text', 'Forced Markers:', 'Position', [270 170 150 30]); -forcedMarkersField = uieditfield(fig, 'numeric', 'Value', 0, 'Position', [390 170 50 30]); +uilabel(fig, 'Text', 'Forced Markers:', 'Position', [250 170 150 30]); +forcedMarkersField = uieditfield(fig, 'numeric', 'Value', 0, 'Position', [350 170 50 30]); % Percentage of Text Width -uilabel(fig, 'Text', 'Percentage of Text Width:', 'Position', [500 170 200 30]); -percTextField = uieditfield(fig, 'numeric', 'Value', 0.75, 'Position', [670 170 50 30]); +uilabel(fig, 'Text', 'Percentage of Text Width:', 'Position', [450 170 200 30]); +percTextField = uieditfield(fig, 'numeric', 'Value', 0.75, 'Position', [600 170 50 30], ... + 'ValueChangedFcn', @(src, event) limitsCheck(src, event)); %% Checkboxes %%% Create a panel to group flags @@ -136,6 +138,7 @@ end updateButton = uibutton(fig, 'Text', 'Update Figures', ... 'Position', [370, 500, 120, 30], ... 'BackgroundColor', '#9fc9eb', ... + 'Tooltip', 'Update list of available figures', ... 'ButtonPushedFcn', @(src, event) updateDropdown()); % Submit Button @@ -146,12 +149,57 @@ exportButton = uibutton(fig, 'Text', 'Export Figure', ... % preview image to export button previewButton = uibutton(fig, 'Text', 'Update preview', ... - 'Position', [500, 500, 120, 30], ... - 'BackgroundColor', '#9fc9eb', ... + 'Position', [640, 500, 120, 30], ... + 'BackgroundColor', '#fdf3ae', ... + 'Tooltip', 'Click to see a preview of your plot', ... 'ButtonPushedFcn', @(src, event) previewFigureCallback()); +% return to default button +defaultButton = uibutton(fig, 'Text', 'Reset', ... + 'Position', [710, 170, 50, 30], ... + 'BackgroundColor', [.7 .7 .7], ... + 'Tooltip', 'Return to default values', ... + 'ButtonPushedFcn', @(src, event) resetToDefault()); + +% automatically generate a name +autoNameButton = uibutton(fig, 'Text', 'Auto name', ... + 'Position', [370, 550, 120, 30], ... + 'BackgroundColor', [.7 .7 .7], ... + 'Tooltip', 'Generate a automatic name', ... + 'ButtonPushedFcn', @(src, event) autoNameGenerator()); + %% Functions % Function to update dropdown menu with new figures + function autoNameGenerator() + figNameField.Value = "[]plot"; + end + + function emptyNameField(src) + if isempty(src.Value) + src.Tooltip = 'Insert a valid name'; + src.BackgroundColor = [1, 0.8, 0.8]; % Light red + else + src.Tooltip = ''; + src.BackgroundColor = [1, 1, 1]; % White + end + end + + function limitsCheck(src, event) + if event.Value > 1 + src.Tooltip = 'Only values less than 1 are accepted'; + src.BackgroundColor = [1, 0.8, 0.8]; % Light red + else + src.Tooltip = ''; + src.BackgroundColor = [1, 1, 1]; % White + end + end + + function resetToDefault() + forcedMarkersField.Value = 0; + WHratioField.Value = 0; + percTextField.Value = 0.75; + end + function updateDropdown() figHandles = findFigures(fig); figNames = getFigureNames(figHandles); @@ -166,15 +214,15 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ... % Function to update preview function updatePreview() - checkboxes = findall(flagsPanel.Children, 'Type', 'uicheckbox'); + checkboxes = findall(flagsPanel.Children, 'Type', 'uicheckbox'); set(checkboxes, 'Enable', 'on'); figHandles = findFigures(fig); - + % Get selected figure from dropdown selectedIdx = figSelectionDropDown.Value; selectedFig = []; - + for i = 1:length(figHandles) figSeries = figHandles(i); @@ -198,12 +246,12 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ... end end % Move from background to foreground current figure - uistack(selectedFig,'top') + uistack(selectedFig,'top') updateDropdown(); if isempty(selectedFig) && isscalar(figHandles), selectedFig = figHandles(1); end if isempty(selectedFig) || ~isvalid(selectedFig), return; end - + % Retrieve axes from selected figure obj = findall(selectedFig, 'Type', 'figure'); @@ -229,7 +277,7 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ... newAx = copyobj(obj.Children(1).Children(i).Children, newFig); set(newAx, 'Position', get(gca, 'Position')); - hold(newAx, 'on'); + hold(newAx, 'on'); end delete(obj); else @@ -378,7 +426,7 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ... 'WHratio', WHratio, ... 'overwriteFigure', overwriteFigure); - checkboxes = findall(flagsPanel.Children, 'Type', 'uicheckbox'); + checkboxes = findall(flagsPanel.Children, 'Type', 'uicheckbox'); set(checkboxes, 'Enable', 'off'); end end -- GitLab