How to extend horizontally this inputdlg window?

Dear all,
I have this code for inputdlg window:
prompt = {'Nastavení výšky modelu:','Nastavení jemnosti sítě modelu:','Nastavení počtu elektrod:','Nastavení vzdálenosti mezi elektrodami:','Nastavení poloměru elektrod:','Nastavení tvaru elektrod:','Nastavení jemnosti sítě elektrod:','Nastavení normy - doplnit:'};
dlg_title = 'Nastavení parametrů modelu';
num_lines = 1;
defaultans = {'1','0.8','16','1','0.05','0','0.4','256'};
answer = inputdlg(prompt, dlg_title,num_lines, defaultans);
I would like to extend horizontally this window, because there isn´t display title of window. Can you advise me?

 Respuesta aceptada

Star Strider
Star Strider el 11 de Mzo. de 2017
All you need to do is to define ‘num_lines’ to be a matrix. Here, I defined them as all being 75 characters wide:
prompt = {'Nastavení výšky modelu:','Nastavení jemnosti sítě modelu:','Nastavení počtu elektrod:','Nastavení vzdálenosti mezi elektrodami:','Nastavení poloměru elektrod:','Nastavení tvaru elektrod:','Nastavení jemnosti sítě elektrod:','Nastavení normy - doplnit:'};
dlg_title = 'Nastavení parametrů modelu';
defaultans = {'1','0.8','16','1','0.05','0','0.4','256'};
num_lines = [ones(size(defaultans')) ones(size(defaultans'))*75];
answer = inputdlg(prompt, dlg_title,num_lines, defaultans);

5 comentarios

dpb
dpb el 11 de Mzo. de 2017
Editada: dpb el 11 de Mzo. de 2017
"All you need to do..."
"All", indeed! :( It's still arbitrary to discover how wide is "wide enough" since simply counting characters doesn't tell how long the two text strings of longest prompt vis a vis the dialog title are relative to each other in display length since they're not same font size. Seems like there is some ability to determine some of that I've seen in the past but can't think just what/where it is at the moment. (Ah, I recall...the 'extent' property of the text object; write the string in question and query the extent; comparison of different strings lengths/font sizes can be done then to find the number of characters to be at least the length of the other string in a different font/fontsize. It's still pretty klunky, but at least is theoretically possible.)
I think still it's another of those little nits that TMW should've gotten working better initially...it's just such a pain to have to work thru these little nigglies that aren't all that important in big scheme of things but are endlessly annoying...
$0.02, imo, ymmv, etc., etc., etc., ...
It’s definitely not well-documented. In most of the documentation, when I added the matrix directly to the argument list, since much of the documentation implies that being the correct syntax, I got a ‘Too many input arguments.’ error. It took me a while to figure it out.
Using:
num_lines = repmat([1 75], size(defaultans,2), 1);
would likely be more efficient. It produces the same result.
dpb
dpb el 11 de Mzo. de 2017
The repmat "trick" is what I commented on in my (revised) Answer on building the numel array; I agree that's the better syntax. If I get a few minutes I may play with the length issue a little and see if can ascertain if there is a way to derive a more pleasing generic solution than the so-far "use arbitrary width greater max prompt string length" rule that is hard to code w/o the Crystal Ball Toolbox (soon(?) to be released).
Star Strider
Star Strider el 11 de Mzo. de 2017
I suppose you could somehow recover the title font size, estimate the length (in millimetres or pixels or whatever) necessary to show the entire title, then translate that to the necessary length requirement for ‘num_lines’ as the number of characters in the input window length, and then set that.
It seems to me to be easier to simply update the documentation to include that option as a more obvious solution rather than ‘camouflaging’ it. We’re experienced with MATLAB, and if it takes us time to find it and experiment with it, those less experienced will quite likely never find it.
dpb
dpb el 11 de Mzo. de 2017
I agree at a minimum the doc ought to be improved; I don't do gui's but what few times have used the UIdialogs it has often seemed they've been so neutered from what the underlying OS parameters are that one almost always ends up with some issue if it's more than just the simplest of uses.

Iniciar sesión para comentar.

Más respuestas (2)

dpb
dpb el 11 de Mzo. de 2017
Editada: dpb el 11 de Mzo. de 2017
Don't see a way programmatically, TMW didn't expose the rest of the control properties thru the provided interface, unfortunately.
...[Previous use of longer prompt to fudge field width elided for brevity--dpb]...
Just point out one way to implement the TMW-suggestion linked to by IA and as fixed-width by SS above...
N=max(length(dlg_title),max(cellfun(@length,prompt)))+1; % get max length + offset
numel=repmat([1 N],length(prompt),1); % build numel array from inputs
Empirically the '+1' above was just enough; as observed in above comment this is an empirical adjustment, unfortunately.
What a kludge, though! :( This should be cited and an enhancement request submitted to TMW www.mathworks.com official support.
Image Analyst
Image Analyst el 11 de Mzo. de 2017

0 votos

1 comentario

dpb
dpb el 11 de Mzo. de 2017
Editada: dpb el 11 de Mzo. de 2017
Ah...shoulda' read the doc more carefully, the TMW-supplied answer at the above link uses the array form for the num_lines parameter where the first column is number of lines for each prompt while the second is the width of the column. So, add the characters of the difference between length of title and prompt plus some for the field width and the prompt boxes will be wide-enough.
Much cleaner than the above forcing a long-enough title for a prompt, but similar "trick" to force the sizing algorithm to work.
Be much better if TMW would do this internally, though; why wouldn't one if given the task to implement the UI? Or perhaps there was no internal test that uncovered the case of title display length > prompt length so it all seemed to work fine in internal test suite?

Iniciar sesión para comentar.

Preguntada:

el 11 de Mzo. de 2017

Comentada:

dpb
el 11 de Mzo. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by