text render size ?

  • Follow


I am trying to size some uicontrol()'s as small as will fit everything
including the String. (This is related to computed positioning of
multiple controls instead of hard-coding their relative positions.)

I have found that when rendering a uicontrol, that on my system,
'Font','fixedwidth' (what the documentation says to use) is
rendering proportionally instead. According to get(), the fixed
width font name is 'Courier New'. Using the ui font editor, I
found that my system has a font named 'fixed'; using that resulted
in proportional rendering as well.

The test was fairly simple: put up '|||||||' and '7777777' directly
underneath and see that the 7's go much further right.
More subtly, if I play with the box render size until it encloses
the seven bars, and then try to render the seven sevens in the
same space, matlab will detect the sevens as being too long, and
will put up a few 7's followed by an ellipsis.

Is there a way to query how the width and height that would be needed
to render a given string? Or is there a way to specify Position
as "start from this given lower-left corner and go only
as far up and right as you need" with a query of the Position
thereafter returning the actual size used?

My best approximation so far is that a uicontrol of checkbox
style requires a width (in Units characters) of at least
3 + 43/32 * length(String) in order to avoid the possibility of
String being truncated. But allowing that width looks pretty bad
if the characters happen to be relatively thin in proportionate
spacing -- e.g., 'sam hill' ends up with a big blank space
at the end compared to '88888888'.
-- 
  There are some ideas so wrong that only a very intelligent person
  could believe in them.                              -- George Orwell
0
Reply roberson2 (8067) 3/22/2007 5:29:47 AM

Install the string, then check the "Extent" property of the
uicontrol, then resize the control.
You're right that the checkbox requires some additional size for the
"check" thingy. You might just have to use a rule of thumb for that.
Tim
0
Reply conover1 (10) 3/22/2007 2:14:38 PM


In article <ef51318.0@webcrossing.raydaftYaTP>,
Tim Conover <conover@ces.clemson.edu> wrote:
>Install the string, then check the "Extent" property of the
>uicontrol, then resize the control.
>You're right that the checkbox requires some additional size for the
>"check" thingy. You might just have to use a rule of thumb for that.

Thanks, Extent turned out to be what I needed. I found that
I had earlier used 'FontName' 'fixedwidth' instead of 'FontName'
'FixedWidth', but switching to FixedWidth still resulted in
proportional rendering on my system.


It turns out that Extent applied to a uicontrol('Style','checkbox')
returns the Extent of the String, ignorning the space needed
for the checkbox. The Position one sets for the uicontrol()
needs to include an allocation for the checkbox; I found that
2.45 character widths was sufficient (I rounded to 2.5).

I found that for uicontrol('Style','text') that if the width
of the Position was not enough to accomedate all of the text,
that the text would be wrapped onto additional lines, to
the degree possible considering the height of the Position.
But even when displayed wrapped, the Extent returned as if
the text was all on one line.

For uicontrol('Style','checkbox'), the text does not wrap:
it is truncated and an ellipsis added instead (and only part
of an ellipsis if the space is too tight.) But Extent still
indicates the text size that would have been needed in this case.

I found that a uipanel() around a series of uicontrol()s
needs an extra width of 0.45 (I rounded to 0.5) and an
extra height of 0.4, in order to render the enscribed border
for the panel. [These are in 'Units' 'characters']


For those who (like me) are struggling with positioning UI elements:
My finished buttonlist procedure (non-exclusive check buttons)
ended up working about like this:

  User supplies a parent, and a position (in parent units) that has a
  panel size guess, and a cellstring array of button labels.  Code
  creates an invisible uipanel initially sized by the guess. Code
  creates all the buttons, all in the same relative position, guessing
  at the width. Code gets the the Extent for all the buttons, and finds
  the maximum height from from them, and finds the panel width by
  summing the Extent widths plus the checkbox width times the number of
  buttons plus the panel width border, and finds the panel height as
  the maximum height plus the panel height border. Code resizes the
  uipanel according to this computed information. Code loops over
  button handle list and repositions each button to the right of the
  previous one with the width equal to the Extent width previously
  extracted plus the checkbox size, and the height equal to the maximum
  height found.  Finally, the code makes the uipanel visible, thus
  rendering panel and buttons all at the same time, all correctly sized
  and placed, and returns the uipanel handle and the array of button
  handles.
-- 
   Okay, buzzwords only. Two syllables, tops.  -- Laurie Anderson
0
Reply roberson2 (8067) 3/22/2007 5:39:05 PM

In article <etuevp$f5j$1@canopus.cc.umanitoba.ca>,
Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> wrote:
>It turns out that Extent applied to a uicontrol('Style','checkbox')
>returns the Extent of the String, ignorning the space needed
>for the checkbox.

Further notes based upon R2006b experimentation:

Extent applied to a uicontrol with 'Style' of 'popupmenu' or
'listbox' returns the Extent that would be needed for the first
string choice, no matter what the current Value is.


'listbox' needs a width margin of 19 pixels to accomedate the
(present by default) right scroll-bar; e.g., a text width of 241
needs a control width of 260 or else a horizontal scroll bar will
be inserted (if the control isn't so small that it decides to
omit the bar.)

'popupmenu' needs a width margin of 16 pixels to accomedate the
pop-up indicator; e.g., a text width of 241 needs a control width
of 257 or else the String will be shown with an ellipsis.

'checkbox' needs a width margin of 15 pixels to accomedate the
checkbox; e.g., a text width of 241 needs a control width of 256
or else the String will be shown with an ellipsis.


uicontrol 'Style's of 'frame' and 'slider' will ignore all String content.

uicontrol 'Style's 'pushbutton', 'togglebutton', 'radiobutton',
'checkbox', will ignore any String content beyond the first string.

A uicontrol 'Style' of 'edit' will complain if the String is not
a single string (e.g., is a cell).

A uicontrol 'Style's of 'Text' will accept a String with multiple cell
entries, and will attempt to wrap each of them to fit within the
visible area.

uicontrol 'Style's of 'listbox' and 'popupmenu' will use each
String entry as a distinct selection choice.


textwrap() does not take into account the variety of control. It will,
for example, not take into account the controls that do not accept
multiple lines in coming up with its recommendations for the
text size. Thus, if one starts with a single line string and
a control that only accepts single line strings, and one follows
textwrap()'s size recommendations and sets the String according
to the value returned by textwrap, large portions of the string
may have disappeared (ignored by the control.) In my opinion,
this qualifies as a bug.

textwrap() has an off-by-one error (at least in R2006b). If the
container width is exactly the size needed to hold a string,
then textwrap() will wrap it onto multiple lines. For example,
textwrap might tell you that a text width of 241 is needed for
a string; if you then size the control at a width of 241 and
ask textwrap again then it will provide a wrapped version of the
string, but if you sized the control at 242 or higher then textwrap()
would tell you that the recommended width was 241. Therefore if one
accepts textwrap()'s recommendations and iterates through resizing
and asking again, the string will become more and more wrapped.


All in all, I would assess textwrap() of being of almost no
utility except for uicontrols of type Text, and I'm not even
certain of the utility there considering the automatic wrapping
that is done anyhow.
-- 
   "No one has the right to destroy another person's belief by
   demanding empirical evidence."              -- Ann Landers
0
Reply roberson2 (8067) 4/2/2007 10:21:23 PM

In article <eurvl3$ecb$1@canopus.cc.umanitoba.ca>,
Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> wrote:

>Further notes based upon R2006b experimentation:

>Extent applied to a uicontrol with 'Style' of 'popupmenu' or
>'listbox' returns the Extent that would be needed for the first
>string choice, no matter what the current Value is.

Amendment to that and related points:

If the 'Max' setting of the control is greater than 1, then
Extent is the full extent for the strings, not just the Extent
for the first string choice. This happens even for controls
where it doesn't make any sense to be able to return multiple
values -- including 'popupmenu' and 'slider'.

>'listbox' needs a width margin of 19 pixels to accomedate the
>'popupmenu' needs a width margin of 16 pixels to accomedate the
>'checkbox' needs a width margin of 15 pixels to accomedate the

'radiobutton' needs a margin of 15 pixels.

'edit' needs a margin of 19 pixels in the multiline case,
to accomedate the scroll bar. There is no scrollbar for the single
line case.

Correction to previous posting: 'edit' will *not* complain if there
is more than one string element if Max is greater than 1.
I missed the multiline edit case before.

-- 
  "law -- it's a commodity"
                         -- Andrew Ryan (The Globe and Mail, 2005/11/26)
0
Reply roberson2 (8067) 4/3/2007 9:58:21 PM

In article <euuilt$5eh$1@canopus.cc.umanitoba.ca>,
Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> wrote:

>'edit' needs a margin of 19 pixels in the multiline case,
>to accomedate the scroll bar.

Correction: the needed margin is 21 pixels. (Though I'm sure it
tested out as 19 earlier today...)
-- 
  All is vanity.                                       -- Ecclesiastes
0
Reply roberson2 (8067) 4/3/2007 10:04:23 PM

In article <eurvl3$ecb$1@canopus.cc.umanitoba.ca>,
Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> wrote:

>Further notes based upon R2006b experimentation:

The documentation for uicontrol('Style','frame') indicates that,
"Only other uicontrols can appear within frames.". However,
uicontrol objects cannot be constructed with a Parent which is
another uicontrol, so you cannot make anything a child of
a frame.

Based upon experimentation, it -appears- that what the documentation
is getting at is that any object (such as a plot) which is not of type
uicontrol will be overlayed by the frame; this occurs no matter
which order the other object and the frame were created in. uicontrol
objects, though, will be drawn on top of a uicontrol 'frame'
if the object is defined after the frame.

Another way of saying this would be that a uicontrol frame
(apparently) clips everything except uicontrol objects.
-- 
  "It is important to remember that when it comes to law, computers
  never make copies, only human beings make copies.  Computers are given
  commands, not permission. Only people can be given permission."
                                               -- Brad Templeton
0
Reply roberson2 (8067) 4/4/2007 6:00:52 PM

6 Replies
56 Views

(page loaded in 0.271 seconds)

Similiar Articles:













7/21/2012 5:16:30 PM


Reply: