List & text-list - font object
[1/6] from: philb:upnaway at: 3-Dec-2003 13:27
Hi all,
I have a problem with list & text-list vid objects.
If I set up a list with a particular font style all subsequent text-list seem to use
the same font object ... see example the code below.
I dont want to specify a particular font style in my text-list .... (as in the real application
there are many possible text-list's)
Changing
text 100
to
text font [] 1000
seems to fix the problem in this particular example but in my real world application,
which has multiple columns in the list, is doesnt seem to fix the problem.
Any ideas? ... or perhaps an explanation of how to force a seperate font object for the
list object?
Cheers Phil
8< ---------------------------
rebol []
data1: ["Hello" "world" "here" "are" "some" "lines" "in" "a" "list"]
data2: ["This" "is" "a" "normal" "text" "list"]
lv-lay: layout [
my-list: list with [picked: false]
[
text 100
]
supply [
if count > length? data1 [face/show?: false exit]
face/show?: true
; print [count index]
;print [count pick data1 count]
face/text: pick data1 count
face/font/style: 'bold
]
button "Show Text List" [
view/new layout [text-list data data2]
]
]
view lv-lay
quit
[2/6] from: nitsch-lists::netcologne::de at: 3-Dec-2003 11:36
Am Mittwoch, 3. Dezember 2003 06:27 schrieb [philb--upnaway--com]:
> Hi all,
> I have a problem with list & text-list vid objects.
<<quoted lines omitted: 11>>
> Any ideas? ... or perhaps an explanation of how to force a seperate font
> object for the list object?
Reason:
/font and /para are stored in sub-objects. and this objects are shared with
the base-style. So changing the sub-object affect every face using that font.
Not only next text-lists, but everything using 'text.
Solution:
You have to clone the font-object for each face where you change it.
You can trigger that with layout[text font[] para[]].
This syntax is because the [] contains an object-spec.
So you can say [text font[style: 'bold]] and have a unique bold font in your
face.
view layout[
across
text "Hello" font[style: 'bold]
text "World" font[style: 'italic]
]
Experiments:
Writing [font[]] everywhere is annoying.
So i tried using styles. (change in your text-list)
;style tx text 100 font[] ;all 'tx share the same font
style tx text 100 with[append init [font: make font[]]]
; ^ each tx own font
across a: tx b: tx
I checked for cloning with [ probe same? a/font b/font ]
With the first version: style tx text 100 font[]
the style 'tx gets its own font. then all 'tx share this font. that saves
some font-objects.
Second version: style tx text 100 with[append init [font: make font[]]]
this makes sure each face gets its own font.
the [append init[]] is the rebol way of a constructor.
layout does it after it has filled the face from the arguments.
So font and size etc are already calculated.
Hint: when cloning objects, sub-objects stay shared, series (blocks, strings),
functions are copied.
So the 'init -block is unique for each face, and we can simply append.
Your example changed:
rebol []
data1: ["Hello" "world" "here" "are" "some" "lines" "in" "a" "list"]
data2: ["This" "is" "a" "normal" "text" "list"]
lv-lay: layout [
my-list: list 400x200 with [picked: false]
[
;style tx text 100 font[] ;all 'tx share the same font
style tx text 100 with[append init [font: make font[]]]
; ^ each tx own font
across a: tx b: tx
]
supply [
if count > length? data1 [face/show?: false exit]
face/show?: true
; print [count index]
;print [count index pick data1 count]
face/text: pick data1 count
face/font/style: 'bold
]
button "Show Text List" [
view/new layout [text-list data data2]
probe same? a/font b/font
]
]
view lv-lay
quit
> Cheers Phil
>
> 8< ---------------------------
>
HTH
-Volker
[3/6] from: philb:upnaway at: 3-Dec-2003 19:51
Thanks Volker ....
That's explained the cloning of the objects .... and why adding font [] worked.
Unfortunately there must be a bug in my email program .... adding the font [] to all
the fields in my list didnt work .... I'll do more debugging.
Cheers Phil
[4/6] from: petr:krenzelok:trz:cz at: 3-Dec-2003 12:53
Hi,
nice explanation Volker - I just wonder how many even non developers
will be struggling subobject sharing on various places in Rebol :-) I
have not met any single beginer with VID who would not run into such
kind of problems. As some ppl suggested 'clone is not usefull at all, we
need at least better docs on that one ;-)
-pekr-
[5/6] from: philb:upnaway at: 3-Dec-2003 23:51
Hi Anton,
Got it sorted now .... the help available on this list is amazing.
Thanks again Volker ....
The bug it was a little strange and I should really investigate further.
I tried to cut the problem down to a much smaller program, just list & text-list.
I put a font [] on all the text items in the list.
Of course, the bug dissapeared.
Doing the same in my much larger program, the bug was still there :-( grrrr
Following Volkers suggestion, I made a style with a
with[append init [font: make font[]]]
as soon as I put this in my much larger program, and the bug went away.
As I said I should investigate further, as putting a font [] on each field should have
sorted the problem, .... but time is against me of course :-(
FYI the much larger program is an email client.
If the email is unread then the line in the list representing that email appears bold,
otherwise it should have no 'style (if you see what I mean ;-) ). The problem was that
all subsequent text-list appeared bold if the first item in a folder was unread.
Cheers Phil
[6/6] from: antonr:iinet:au at: 4-Dec-2003 1:22
Try restart rebol between tests.
The font was maybe "permanently" changed by the last test.
Show us your list layout (showing the fields).
Anton.
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted