Hi,
I'm trying to get a nice and tidy GUI with a veriable number of uicontrol objects. To get a clean and clear layout I want to connect several objects with a simple line or path. Has anybody an idea how to implement this?
Thanks for your response, CN

 採用された回答

Sean de Wolski
Sean de Wolski 2012 年 6 月 5 日

4 投票

You could use an invisible axes in the background and draw line objects. For example:
fig = figure('units','pix');
pos = get(fig,'position');
ax = axes('units','pix','outerposition',[0 0 pos([3 4])],...
'position',[0 0 pos([3 4])],'parent',fig,'visible','off','xlim',...
[0 pos(3)],'ylim',[0 pos(4)]);
h(3) = uicontrol('units','pix','position',[300 10 100 100],'style','push');
h(2) = uicontrol('units','pix','position',[10 10 100 100],'style','push');
h(1) = uicontrol('units','pix','position',[300 300 100 100],'style','push');
pos = get(h,'position');
for ii = 1:length(h)-1
line('xdata',[pos{ii}(1)+pos{ii}(3)/2, pos{ii+1}(1)+pos{ii}(3)/2],...
'ydata',[pos{ii}(2)+pos{ii}(4)/2, pos{ii+1}(2)+pos{ii}(4)/2],'parent',ax)
end

7 件のコメント

Christoph
Christoph 2012 年 6 月 6 日
Hi Sean,
thank for your idea, it seems to be the only way of implementation. But now I have the next "small" problem. Due to the number of objects I want to display (the big goal is a navigation-tree as known from windows for a large number of elements without using uitree, because uitree it's undocumented), I have to use a parent panel which should be scrollable(?). And that's exactly the point where I'm lost. Maybe you have a clue?
Nevertheless thanks for your great and detailed answer,
CN
Sean de Wolski
Sean de Wolski 2012 年 6 月 7 日
Can you link to an image of what you expect?
Christoph
Christoph 2012 年 6 月 11 日
Hi Sean, due to the long weekend I wasn't able to post you an answer, sorry for that.
before I started coding I searched for a solution to my problem and found one here: http://undocumentedmatlab.com/blog/uitree/
This might be a good layout. The problem is, as I figured out before, that I'm not allowed to use uitree-functions because of the undocumented status. That's why I'm trying building such tree "on my own".
Thanks for your help,
CN
Sean de Wolski
Sean de Wolski 2012 年 6 月 11 日
No worries, I don't look at computer screens at all over the weekend any way!
From my _*personal*_ point-of-view, why not just use a UITREE? If it ever becomes unavailable in a future release, then worry about the challenge you face now at that point. Until then, no reason to reinvent the wheel.
Christoph
Christoph 2012 年 6 月 11 日
well..this condition wasn't posed by me but my supervisor.
Christoph
Christoph 2012 年 6 月 15 日
Hi Sean,
just wan't to let you know that I found a solution. I figured out that for my purposes the uicontrol-objects aren't needed. I created a various number of text-objects in the axes-class which use the ButtonDownFcn-Property as Callback to show substructures or the cells of the structure. Connecting each object with a line was pretty easy in the axes class.
The idea of scrolling I implemented with the help of a slider, which sets the index of vector which contains all visible objects.
Last but not least I but uicontrol checkboxes on every node in figure coordinates to set or reset the concerned structure or cell.
Now I got one last question: Whats the drawback of an object with a ButtonDownFcn-Callback in axes-class compared with an uicontrol-object with a Callback. To me it seems they both do the same things, but maybe on a different way.
Nevertheless thanks for your great support and ideas,
CN
Sean de Wolski
Sean de Wolski 2012 年 6 月 15 日
There are a few things that are different I believe.
-The uicontrol callbacks will fire if you are zooming or panning, this is not true for a buttondownfcn which is disabled while in one of these interactive modes.
-The buttondownfcn fires when the button goes down, the callbacks fire when it comes up.
There are probably a few other things though I can't think of them right now.

サインインしてコメントする。

その他の回答 (3 件)

Image Analyst
Image Analyst 2012 年 6 月 5 日

1 投票

Did you try the line() function? I usually use it on axes, but it might work on your main figure also.

2 件のコメント

Walter Roberson
Walter Roberson 2012 年 6 月 5 日
line() can only be used in axes. The routines that can create graphical items that are not in axes seem to all be named starting with "ui": uicontrol(), uitab(), uitable(), uipanel()
Christoph
Christoph 2012 年 6 月 6 日
Thats totally right. Even patch doesn't work in different class then axes.

サインインしてコメントする。

Walter Roberson
Walter Roberson 2012 年 6 月 5 日

1 投票

You need to create an axes in order to draw the line.
My recollection is that uicontrol() objects take graphical precedence over axes (that is, if you have a uicontrol() that is positioned in an area where the axes happens to be, the control will show up on top.)

1 件のコメント

Sean de Wolski
Sean de Wolski 2012 年 6 月 5 日
@Walter, this is recollection is true!

サインインしてコメントする。

Adam Kaas
Adam Kaas 2012 年 6 月 5 日

0 投票

I'm guessing there is a more efficient way, but you could always get a picture of the path you want either online or make it using MSpaint or some other software and insert it as an axes. Are you using GUIDE?

1 件のコメント

Christoph
Christoph 2012 年 6 月 6 日
No, I'm not using guide. I don't want a static GUI. All I want to do is just a simple navigation tree to read and set several values of a struct with a large number of substructs just as know from windows explorer.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Update figure-Based Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by