Re: [Factor-talk] How to scroll to a new gadget ?
Am Sun, 18 Sep 2016 10:25:59 -0700 schrieb John Benediktsson: > Your code didn't run for me as is, you have to set ``nodes`` to a > value first. > > Also, I don't understand why ``draw`` is making a new > instead of just adding the new node to the existing scroller? > > > In the code below "nodes" is initialized in the second to last line. The new variable "gadgets" is initialized by "draw" and used by "add-node-gadget" to add the new node gadget only. But scrolling still only works when navigating with ← or → . --- USING: accessors colors.constants kernel math math.parser models namespaces sequences ui ui.gadgets ui.gadgets.borders ui.gadgets.frames ui.gadgets.grids ui.gadgets.labels ui.gadgets.packs ui.gadgets.scrollers ui.gestures ui.pens.solid ; IN: test-script SYMBOLS: nodes gadgets ; : add-node ( -- n ) nodes get dup length [ suffix nodes set ] keep ; TUPLE: node-gadget < border number ; M: node-gadget model-changed swap value>> over number>> = [ dup scroll>gadget COLOR: black ] [ f ] if >>boundary relayout-1 ; : ( n model -- gadget ) swap [ number>string node-gadget new-border ] keep >>number { 22 22 } >>size dup rot add-connection ; TUPLE: dialog < frame ; CONSTANT: chart-cell { 0 1 } : draw ( dialog n -- dialog' ) swap dup model>> dup gadgets set nodes get [ pick ] map add-gadgets nip chart-cell grid-add [ set-control-value ] keep ; : add-node-gadget ( dialog n -- ) swap 2dup model>> gadgets get swap add-gadget drop set-control-value ; : go ( dialog offset -- ) over control-value + nodes get length rem swap set-control-value ; dialog H{ { T{ key-down { sym "INSERT" } } [ add-node add-node-gadget ] } { T{ key-down { sym "LEFT" } } [ -1 go ] } { T{ key-down { sym "RIGHT" } } [ 1 go ] } } set-gestures : ( -- gadget ) 1 2 dialog new-frame chart-cell >>filled-cell "Press ← or → to navigate. Press INSERT to add a number." { 5 9 } { 0 0 } grid-add 0 [ >>model ] keep draw ; nodes off 5 [ add-node drop ] times [ "dialog" open-window ] with-ui -- ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] How to scroll to a new gadget ?
Until now I supposed variables to be initialized to "f". Now I know that I was wrong. So the last line of my code now has "nodes off" prepended. For a simple node sequence I agree. But in my application I want to show a changing directed graph build from SQL records. Therefore I consider it more robust to alter the SQL records and then rebuild the complete gadget tree (recursively). Am Sun, 18 Sep 2016 10:25:59 -0700 schrieb John Benediktsson: > Your code didn't run for me as is, you have to set ``nodes`` to a > value first. > > Also, I don't understand why ``draw`` is making a new > instead of just adding the new node to the existing scroller? > > > > On Sun, Sep 18, 2016 at 5:33 AM, Georg Simon > wrote: > > > The code below is a useless program. > > It's only purpose is to show my question. > > > > By pressing INSERT I add new nodes until the scroller appears. > > > > By using ← or → I can see the scroller work. > > > > Pressing INSERT triggers the content of the filled-cell of > > "dialog < frame" to be overwritten by "draw". > > "draw" triggers "node-gadget => model-changed" which calls > > "scroll>gadget". > > But scrolling doesn't work after INSERT. > > > > I guess that rendering happens after "scroll>gadget". > > > > How can I make scrolling work in this case ? > > - > > USING: > > accessors colors.constants kernel > > math math.parser models namespaces sequences > > ui ui.gadgets ui.gadgets.borders ui.gadgets.frames > > ui.gadgets.grids ui.gadgets.labels ui.gadgets.packs > > ui.gadgets.scrollers > > ui.gestures ui.pens.solid > > ; > > IN: test-script > > > > SYMBOL: nodes > > > > : add-node ( -- n ) > > nodes get dup length [ suffix nodes set ] keep > > ; > > TUPLE: node-gadget < border > > number > > ; > > M: node-gadget model-changed > > swap value>> over number>> = > > [ dup scroll>gadget COLOR: black ] [ f ] if > > >>boundary relayout-1 > > ; > > : ( n model -- gadget ) > > swap [ number>string node-gadget new-border ] keep > > >>number { 22 22 } >>size dup rot add-connection > > ; > > TUPLE: dialog < frame > > ; > > CONSTANT: chart-cell { 0 1 } > > > > : draw ( dialog n -- dialog' ) > > swap dup model>> > > nodes get [ pick ] map add-gadgets nip > > chart-cell grid-add [ set-control-value ] keep > > ; > > : go ( dialog offset -- ) > > over control-value + nodes get length rem > > swap set-control-value > > ; > > dialog > > H{ > > { T{ key-down { sym "INSERT" } } [ add-node draw drop ] } > > { T{ key-down { sym "LEFT" } } [ -1 go ] } > > { T{ key-down { sym "RIGHT" } } [ 1 go ] } > > } > > set-gestures > > > > : ( -- gadget ) > > 1 2 dialog new-frame chart-cell >>filled-cell > > "Press ← or → to navigate. Press INSERT to add a number." > > { 5 9 } { 0 0 } grid-add > > 0 [ >>model ] keep draw > > ; > > 5 [ add-node drop ] times [ "dialog" open-window ] with-ui > > > > > > -- > > ___ > > Factor-talk mailing list > > Factor-talk@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/factor-talk > > -- ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] How to scroll to a new gadget ?
The code below is a useless program. It's only purpose is to show my question. By pressing INSERT I add new nodes until the scroller appears. By using ← or → I can see the scroller work. Pressing INSERT triggers the content of the filled-cell of "dialog < frame" to be overwritten by "draw". "draw" triggers "node-gadget => model-changed" which calls "scroll>gadget". But scrolling doesn't work after INSERT. I guess that rendering happens after "scroll>gadget". How can I make scrolling work in this case ? - USING: accessors colors.constants kernel math math.parser models namespaces sequences ui ui.gadgets ui.gadgets.borders ui.gadgets.frames ui.gadgets.grids ui.gadgets.labels ui.gadgets.packs ui.gadgets.scrollers ui.gestures ui.pens.solid ; IN: test-script SYMBOL: nodes : add-node ( -- n ) nodes get dup length [ suffix nodes set ] keep ; TUPLE: node-gadget < border number ; M: node-gadget model-changed swap value>> over number>> = [ dup scroll>gadget COLOR: black ] [ f ] if >>boundary relayout-1 ; : ( n model -- gadget ) swap [ number>string node-gadget new-border ] keep >>number { 22 22 } >>size dup rot add-connection ; TUPLE: dialog < frame ; CONSTANT: chart-cell { 0 1 } : draw ( dialog n -- dialog' ) swap dup model>> nodes get [ pick ] map add-gadgets nip chart-cell grid-add [ set-control-value ] keep ; : go ( dialog offset -- ) over control-value + nodes get length rem swap set-control-value ; dialog H{ { T{ key-down { sym "INSERT" } } [ add-node draw drop ] } { T{ key-down { sym "LEFT" } } [ -1 go ] } { T{ key-down { sym "RIGHT" } } [ 1 go ] } } set-gestures : ( -- gadget ) 1 2 dialog new-frame chart-cell >>filled-cell "Press ← or → to navigate. Press INSERT to add a number." { 5 9 } { 0 0 } grid-add 0 [ >>model ] keep draw ; 5 [ add-node drop ] times [ "dialog" open-window ] with-ui -- ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk