Am Sun, 18 Sep 2016 10:25:59 -0700 schrieb John Benediktsson <mrj...@gmail.com>:
> 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 ``<scroller>`` > 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 <solid> ] [ f ] if >>boundary relayout-1 ; : <node-gadget> ( n model -- gadget ) swap [ number>string <label> 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>> <shelf> dup gadgets set nodes get [ pick <node-gadget> ] map add-gadgets nip <scroller> chart-cell grid-add [ set-control-value ] keep ; : add-node-gadget ( dialog n -- ) swap 2dup model>> <node-gadget> 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 : <dialog> ( -- gadget ) 1 2 dialog new-frame chart-cell >>filled-cell "Press ← or → to navigate. Press INSERT to add a number." <label> { 5 9 } <border> { 0 0 } grid-add 0 [ <model> >>model ] keep draw ; nodes off 5 [ add-node drop ] times [ <dialog> "dialog" open-window ] with-ui ------------------------------------------------------------------------------ _______________________________________________ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk