Text width in VID (Was: Re: Compressing image data (bugs?))
[1/4] from: henrik::webz::dk at: 6-Dec-2003 7:51
Carl Read wrote:
> Also, if you're dealing with an image created by REBOL, you could use
> save/png to create a compressed binary of the image. ie...
That's very clever. Keep the ideas coming! ;-)
I'm also toying with size adaptable buttons, which size themselves to
the text, so it doesn't wrap, and allow for resizing the main window
with the buttons without screwing up the text and for resizing the
column in a listview and make sure, text is never obscured.
I can't use automatic calculations for the button size, because I need
to be able to resize the button from the minimum size of the text width
and up.
I've come up with making an image of a layout with the text string and
then determining its width from image/size/x and it works well. But it
seems a little cumbersome, but is (not yet) performance critical for my
application.
Still, are there easier ways?
--
Regards,
Henrik Mikael Kristensen
[2/4] from: atruter:labyrinth:au at: 6-Dec-2003 20:44
> Still, are there easier ways?
I don't know about easier, but I use code like the following:
get-text-size: function [fontsize [integer!]][t][
layout [t: text font-size fontsize "MMMMMMMM"]
size-text t
]
to determine the size of a base "element" and then stylize/master all my
widgets (in addition to changing origin / space) like:
stylize/master [
btn: btn to-size 1 1 font-size to-integer fontsize * .75
choice: choice to-size 1 1 font-size fontsize
div: box red as-pair element/x element/y / 10
field: field to-size 1 1 font-size fontsize
...
]
whichs enables me to have a UI that dynamically responds to fontsize
changes whilst maintaining the same look. This solution works for me
(where I need to have things appear the same relative size across a wide
range of display size resolutions), but it is certainly not an ideal one.
Regards,
Ashley
[3/4] from: carl::cybercraft::co::nz at: 24-Dec-2003 22:50
Re: Text width in VID
On 06-Dec-03, Henrik Mikael Kristensen wrote:
> I'm also toying with size adaptable buttons, which size themselves
> to the text, so it doesn't wrap, and allow for resizing the main
> window with the buttons without screwing up the text and for
> resizing the column in a listview and make sure, text is never
> obscured.
In later versions of View, but (instead of button) produces a rounded
button sized to the text unless you over-ride it's size (I think).
> I can't use automatic calculations for the button size, because I
> need to be able to resize the button from the minimum size of the
<<quoted lines omitted: 4>>
> critical for my application.
> Still, are there easier ways?
Yes...
>> ? size-text
USAGE:
SIZE-TEXT face
DESCRIPTION:
Returns the size of the text in a face.
SIZE-TEXT is a native value.
ARGUMENTS:
face -- (Type: object)
So...
>> layout [t: text "hello"]
>> size-text t
== 25x12
And I've a vague feeling you can create faces directly without needing
layout, which would simplify things further, but I can't remember how
it was done - if it actually can be... :)
--
Carl Read
[4/4] from: antonr:iinet:au at: 8-Dec-2003 0:40
Re: Text width in VID (Was: Re: Compressing image data (bugs?))
There are two methods I discovered:
text-size: get in layout reduce [
'origin 0 'text "example string"
] 'size
text-size: size-text f: make-face/size/spec 'text 1000x100 [
text: "example string"
]
I found the second operates faster.
I just remembered they give different results for height
(87x19 and 87x15) but I only needed width at the time I
wrote it. I haven't figured out why yet.
Anton.
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted