Home   Archive   Permalink

Looking for an efficient way to handle text face offset

I attempt to indent lines on a line by line basis.
1) I changed para/indent which seems to affect all faces within a layout even buttons whereas when I update g/pane/pane/(text-face)/para/indent/x.
Should there not be a distinct indent porperty value for each face?
Perhaps there is a way to achieve that end?
2) I decided to overlap two text faces in order to mimic indent which works fine. Updating the offset at runtime leaves the screen grey from the old position to the new.
Is it possible to change offset/x property within a block layout? Or should I create a make face object but then how to integrate it within a block layout?
should something like
keep reduce [do [ set 'offset/x ((1 + indent-lvl) * 10)]]
num-size: 10
line-size: 200
grid: [across space 0]
ntext: [
1 "sample text"
2 "sample text 2"
text-face: 3
screen: [
     button "Offset"
     button "Indent"
     button "Prop. check"
        [ print ["g/pane/pane/(text-face)/para/indent/x " g/pane/pane/(text-face)/para/indent/x]
         print ["g/pane/pane/(text-face * 2)/para/indent/x " g/pane/pane/(text-face * 2)/para/indent/x]
         print ["g/pane/pane/(text-face)/offset/x " g/pane/pane/(text-face)/offset/x]
         print ["g/pane/pane/(text-face * 2)/offset/x " g/pane/pane/(text-face * 2)/offset/x]
     g: box 200x100 with [pane: layout/tight grid]
grid-make: func [
] [
     append grid collect [
        keep reduce ['text (mold indent-lvl) yellow red]
        keep reduce [(num-size)]
        ; keep reduce [do [ set 'offset/x ((1 + indent-lvl) * 10)]]
        keep [face-position: at]
        keep reduce ['text (line-size) blue blue]
        ; used as color background otherwise indented area colors grey
        keep [at face-position] ; overlaps preceeding text face
        keep reduce ['text (line-text) (line-size) white blue]
        keep [return]
update-indent: does [    
    do bind [
     offset/x: 20
     show self
    ] pick g/pane/pane text-face
update-offset: does [
    do bind [
     para/indent/x: 40
     show self
    ] pick g/pane/pane text-face
    show g/pane/pane/(text-face * 2)
foreach [indent-lvl line-text] ntext [grid-make indent-lvl line-text]
view layout screen

posted by:   VIDpuzzle       19-Feb-2019/13:08:09-8:00

1) Should note that for efficiency reasons, faces share PARA and FONT objects unless they are explicitly set for a given face. This might be as simple as:
     view layout [
         text 100 "Foo" para []
         text 100 "Bar"
         text 100 "Baz"
"Bar" and "Baz" here will still share the same PARA object where "Foo" will get a new one.
2) I'm not entirely clear what you're trying to do here--does this work?
     keep reduce ['text (line-text) (line-size) white blue]
     keep compose/deep [
         with [offset/x: (1 + indent-lvl * 10)]

posted by:   Chris       19-Feb-2019/14:49:32-8:00

Thanks to your tips.
The intent is to indent text within a text face based on the value on the left column.
keep [para [indent/x: 30]]
keep [para]
keep compose/deep [para [indent/x: ((1 + indent-lvl) * 10)]]
will create a distinct para for each line.
I could not get "with" to work        
keep compose/deep [
    with [para/offset/x: (1 + indent-lvl * 10)]
; with [para [offset/x: (1 + indent-lvl * 10)]]
I now can at last modify any VID object property from within the block that describes it, for those who might read this, like so:
text "mytext" para [offset/x: myoffset]
or even
text "mytext" para [offset: 10x20]

posted by:   VIDpuzzle       20-Feb-2019/8:00:31-8:00

> I now can at last modify any VID object property from within the block that describes it [...]
I'm not quite sure how this is so---an unqualified block on most elements becomes that face's action (with FACE and EFFECT parameters).
WITH does allow you to modify an element's face values before it is initialised (VID elements have an INIT value that is processed after the element setup).
For example:
     view layout [
         field 300 "Edit me and hit 'Enter'"
             probe face/text
             probe get in face 'action
         with [
             probe :init

posted by:   Chris       21-Feb-2019/18:09:54-8:00

Ach, right enough: as noted above, PARA [...] gives you access to a clone of the FACE/PARA object.

posted by:   Chris       21-Feb-2019/18:12:36-8:00

This topic is way above my understanding of REBOL, but it rang some little bell in my head and I went looking for that, and ran across this document which I am not seeing linked on the REBOL web site. So maybe you have not run across it either.

posted by:   Steven White       22-Feb-2019/9:49:23-8:00

> WITH does allow you to modify an element's face values before it is initialised
Thanks for the init tip. I was wondering if there were undocumented accessor functions, perhaps that is one.
Perhaps WITH does not work on PARA, because
is the copying mechanism.
"If you want to modify the para object, you should copy it first. See Para section."
from that URL,
you refered. "Para section" I am yet to be find.
Until I included PARA in the face declaration, I could only access the VID shared PARA.
I mulled over how would I make a copy of the para object, perhaps that is it?
It seems the para copy isn't yet done at the time WITH does its initializations.

posted by:   VIDpuzzle       25-Feb-2019/18:58:57-8:00

I did not write that document, I only found it. I have noticed that feature of VID documentation, namely, references to other documentation that seemed never to have been written. The documentation is incomplete, REBOL 2 is not being updated, REBOL 3 is being developed, RED is in beta; that is what we are up against it seems. I have resigned myself to the thought that REBOL might never be done in my lifetime. But it is done enough that I can use it at work and for fun personal projects.

posted by:   Steven White       25-Feb-2019/21:01:27-8:00

There is a specific order to the construction process (LAYOUT is just a Rebol function, after all), things that are established in WITH may be overwritten by INIT or indeed LAYOUT.
The PARA facet will create a clone of the base style's PARA object (which more than likely will be the shared VID PARA object). Try this example to illustrate that:
     view center-face layout [
         style I-USE-MY-OWN-PARA text 600 para []
         h1 600 "I use VID PARA"
         h2 600 "I use VID PARA"
         i-use-my-own-para "I use my own PARA"
         i-use-my-own-para "I use my own PARA"
         btn 295 "Toggle VID Indent" [
             face/para/indent/x: random 100
             show face/parent-face
         btn 295 "Toggle Custom Indent" [
             face/parent-face/pane/3/para/indent/x: random 100
             show face/parent-face

posted by:   Chris       26-Feb-2019/0:23:13-8:00

Using a style allows to share the same para across a group of faces. That could be handy.
Thanks for the idea.

posted by:   VIDpuzzle       27-Feb-2019/19:11:29-8:00

Using a style allows to share the same para across a group of faces. That could be handy.
Thanks for the idea.

posted by:   VIDpuzzle       27-Feb-2019/19:26:53-8:00

No problem--there are many efficiencies in the way that VIEW is implemented : )

posted by:   Chris       28-Feb-2019/17:28:52-8:00

One last implementation detail when using WITH.
para and font get instantiated by setting a property to a value by constrast to a word.
In this example using compose and compose/deep gives a different result:
different identation for each line when using
para [indent/x: 20]
text "Test2" 100 0.0.255 255.255.255 para [indent/x: 20]
same identation
[indent/x: (indent-lvl * pixel-by-tab)]
text "Test2" 100 0.0.255 255.255.255 para [indent/x: (indent-lvl * pixel-by-tab)]
     pixel-by-tab: 10
     indent-lvl: 1
     grid-font: "times"
     grid-font-size: 18
     grid: []
     line-font: [font [name: (grid-font) size: (grid-font-size)]]
     for line 1 2 1 [            
         append grid collect [        
             keep reduce ['text join "Test" line 100 blue white]
             ; keep compose/deep [para [indent/x: (indent-lvl * pixel-by-tab)]]
             keep compose [para [indent/x: (indent-lvl * pixel-by-tab)]]            
             keep compose line-font
             ; keep compose/deep line-font
         ++ indent-lvl
        probe grid
     view center-face layout [
         g: box with [pane: layout/tight grid]    
Same would go for font using
[font [name: (grid-font) size: (grid-font-size)]]

posted by:   VIDpuzzle       3-Mar-2019/20:28:34-8:00



Type the reverse of this captcha text: "e g n a r - f o - t u o"