Matlab GUI dynamic discrete status tracker

3 次查看(过去 30 天)
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 个评论
Gerti Tuzi
Gerti Tuzi 2016-10-26
编辑:Gerti Tuzi 2016-10-27
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.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2016-10-26
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 个评论
Gerti Tuzi
Gerti Tuzi 2016-10-26
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by