-
-
Save CitizenInsane/54f3c1eba2293d0e5264 to your computer and use it in GitHub Desktop.
Issue with the GUI Layout Toolbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% --- Main function | |
function [] = guilayoutbug() | |
%[ | |
fig = buildFigure(); | |
updatePreviews(fig); | |
%] | |
end | |
%% --- Interface building | |
function [fig] = buildFigure() | |
%[ | |
% Create/Clear figure | |
fig = figure(666); clf(fig); | |
data = guidata(fig); | |
% Create main layout (i.e. A toolbar and a preview area) | |
mainLayout = uiextras.Grid('Parent', fig); | |
toolbar = uiextras.Grid('Parent', mainLayout, 'Spacing', 5); | |
previews = uiextras.CardPanel('Parent', mainLayout); | |
set(mainLayout, 'RowSizes', [25 -1]); | |
% Feed the toolbar area with controls | |
data.handles.cbPreviewSelector = uicontrol('Parent', toolbar, 'Style', 'Popup', 'String', { 'Preview 1', 'Preview 2'}, 'callback', @(sender, args)onPreviewChanged(fig)); | |
data.handles.cbDo3DPlot = uicontrol('Parent', toolbar, 'Style', 'CheckBox', 'String', 'Do 3D plot in preview 1', 'callback', @(sender, args)onPreviewChanged(fig)); | |
uiextras.Empty('Parent', toolbar); | |
set(toolbar, 'ColumnSizes', [120 160 -1]); | |
% Feed first preview card (i.e. A single axis to plot things in 3D) | |
wrapper = uipanel('Parent', previews, 'BorderType', 'None'); | |
data.handles.axes3D = axes('Parent', wrapper); | |
% Feed second preview card (i.e. A single axis to plot things in 1D) | |
wrapper = uipanel('Parent', previews, 'BorderType', 'None'); | |
data.handles.axes1D = axes('Parent', wrapper); | |
% Save figure data | |
data.handles.cpPreviewCards = previews; | |
guidata(fig, data); | |
%] | |
end | |
%% --- Events handler | |
function [] = onPreviewChanged(fig) | |
%[ | |
updatePreviews(fig); | |
%] | |
end | |
%% --- Updates | |
function [] = updatePreviews(fig) | |
%[ | |
% Get back data | |
data = guidata(fig); | |
% Update previews | |
idx = get(data.handles.cbPreviewSelector, 'Value'); | |
do3DPlot = get(data.handles.cbDo3DPlot, 'Value'); | |
data.handles.cpPreviewCards.SelectedChild = idx; | |
switch(idx) | |
case 1, updatePreview1(fig, data.handles.axes3D, do3DPlot); | |
case 2, updatePreview2(fig, data.handles.axes1D); | |
end | |
%] | |
end | |
function [] = updatePreview1(fig, ax, do3DPlot) | |
%[ | |
set(0, 'CurrentFigure', fig); | |
set(fig, 'CurrentAxes', ax); | |
cla 'reset'; | |
if (do3DPlot) | |
surf(peaks); | |
else | |
plot(rand(1,12)); | |
end | |
shading flat; | |
xlabel('x'); | |
ylabel('y'); | |
title('3D'); | |
%] | |
end | |
function [] = updatePreview2(fig, ax) | |
%[ | |
set(0, 'CurrentFigure', fig); | |
set(fig, 'CurrentAxes', ax); | |
cla 'reset'; | |
plot(rand(1, 12)); | |
xlabel('n'); | |
ylabel('m'); | |
title('Cut'); | |
%] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://stackoverflow.com/q/25727765/684399 for details.