Matlab GUI dynamic discrete status tracker

3 views (last 30 days)
Gerti Tuzi
Gerti Tuzi on 26 Oct 2016
Edited: Gerti Tuzi on 27 Oct 2016
In a figure, I want to dynamically display a sequence of equally spaced boxes (contained within a panel) and to dynamically highlight a particular one. A sort of status tracker (my apologies, I don't know the technical term for this). Obviously the sizing and spacing should be relative to the containing panel. This GUI tracker would be embedded within a containing parent figure. Btw, they don't have to be squares. Radio buttons or just plain old push buttons would work fine. Is this possible ? If so, would it also be possible to obtain a click index on any of these boxes ?
  1 Comment
Gerti Tuzi
Gerti Tuzi on 26 Oct 2016
Edited: Gerti Tuzi on 27 Oct 2016
Ok, what I have so far, having access to a panel handle, I create a list of 'frame' style uicontrol objects. This list is added to the 'handles' argument.
Inspiration came from: Forget your GUIDE
pnl = handles.trackerPanel;
pnlPose = get(pnl, 'Position');
pnlX = pnlPose(1);
pnlY = pnlPose(2);
pnlW = pnlPose(3);
pnlH = pnlPose(4);
panelSidePad = 0.01*pnlW;
% Continuous box space
boxcontW = (pnlW - 2*panelSidePad)/N;
% Visible box: total box space - padding
boxW = boxcontW*0.9;
% Same thing on height
panelTopPad = pnlH*0.01;
boxH = pnlH - 2*panelTopPad;
% Indeces along the X-dimension
boxXIdc = pnlX+panelSidePad:boxcontW:pnlX+panelSidePad + boxcontW*(N-1);
boxYIdc = pnlY + panelSidePad;
trackerObjects = [];
for ii = 1:length(boxXIdc)
objpos = [boxXIdc(ii), boxYIdc, boxW, boxH];
tObj = uicontrol('Parent', pnl,'Style','frame',...
'String','', 'Tag', sprintf('t_%d', ii), ...
'BackgroundColor', 'red',...
'Units','normalized','Position',objpos);
% Register callback function. Use the same function to catch all click
% events.
set(tObj, 'Callback', @tracker_Callback);
trackerObjects = [trackerObjects; tObj];
% For a dramatic loading effect.
drawnow();
end
if(length(boxXIdc) ~= N)
warning('Not all trackers were displayed');
end
handles.trackerObjects = trackerObjects;
But the problem is that frames/text etc. objects do not respond to click events. I have to add buttons for that. Buttons on the other side have thick edges and when there are too many objects, the color disappears. So, does anyone know if 1) add working callbacks to frames/text or 2) make buttons appear without the "popping" edges and make them look flat and boxy. I don't see any such properties in the property inspector for any of the button objects.
EDIT: To obtain clicks on the frame, instead of using 'Callback', use 'ButtonDownFcn' as the click-callback function property, as in the following:
set(tObj, 'ButtonDownFcn', @tracker_Callback);
The callback now will be invoked on mouse clicks.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 26 Oct 2016
You could use a uibuttongroup to manage a series of uicontrol('style', 'radio') .
A trick there is that for radio buttons and push buttons, you can modify the CData property to change what the button shows. You can also change the color of the object.
  1 Comment
Gerti Tuzi
Gerti Tuzi on 26 Oct 2016
Hi Walter - I tried the radio button but the appearance suffers when the buttons are very close together. Please see my addition to my comment above to see my approach.

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!