Red updating text in VID using reactive method -
red [needs: 'view] num: ["1^/"] k: num/1 view [ size 600x600 txt: text 30x50 k ar: area 300x400 "" focus on-change[ txt/size: ar/size len: length? split face/text newline either (len - face/data) > 0 [ append num append form (len + 1) newline face/data: len ][ remove tail num face/data: face/data - 1 ] txt/text: form num ] [ar/data: 0] ]
this red program contains "text face" , "area face". text face contains vertical list of serial numbers. when newline added in area face, serial number increase per number of lines. , when line removed in area face, serial number decrease well.
this using non-reactive method. there reactive approach it?
i believe we're looking react
function. reactive framework introduced in this blog post , there similar example of converting example using on-change
reactive version.
anyhow, reading lot lately red, , looking first exercise; to-list
implementation improved probably, view declaration more compact now:
red [needs: 'view] to-list: function [text][ ; converts text area string list of numbers separated newlines txt: copy text append txt "dummy" ; handle empty lines len: length? split txt newline x: copy "" repeat len [ append x mold append x newline] ] view [ size 600x600 text 30x600 react [ face/text: to-list text-area/text ] text-area: area 300x400 "" ]
Comments
Post a Comment