USING: accessors assocs arrays kernel models monads sequences models.combinators ui.gadgets ui.gadgets.borders ui.gadgets.buttons ui.gadgets.buttons.private ui.gadgets.editors ui.gadgets.editors.private words images.loader ui.gadgets.scrollers ui.images vocabs.parser lexer models.range ui.gadgets.sliders ; QUALIFIED-WITH: ui.gadgets.sliders slider QUALIFIED-WITH: ui.gadgets.tables tbl EXCLUDE: ui.gadgets.editors => model-field ; IN: ui.gadgets.controls TUPLE: model-btn < button hook value ; : ( gadget -- button ) [ [ dup hook>> [ call( button -- ) ] [ drop ] if* ] [ [ [ value>> ] [ ] bi or ] keep set-control-value ] [ model>> f swap value<< ] tri ] model-btn new-button f >>model ; : ( text -- button ) border-button-theme ; TUPLE: table < tbl:table { quot initial: [ ] } { val-quot initial: [ ] } color-quot column-titles column-alignment actions ; M: table tbl:column-titles column-titles>> ; M: table tbl:column-alignment column-alignment>> ; M: table tbl:row-columns quot>> [ call( a -- b ) ] [ drop f ] if* ; M: table tbl:row-value val-quot>> [ call( a -- b ) ] [ drop f ] if* ; M: table tbl:row-color color-quot>> [ call( a -- b ) ] [ drop f ] if* ; : new-table ( model class -- table ) f swap tbl:new-table dup >>renderer f >>actions dup actions>> [ set-model ] curry >>action ; : ( model -- table ) table new-table ; : ( -- table ) V{ } clone
; : ( column-model -- table )
[ 1array ] >>quot ; : ( -- table ) V{ } clone ; : indexed ( table -- table ) f >>val-quot ; TUPLE: model-field < field model* ; : init-field ( model -- model' ) [ [ ] [ "" ] if* ] change-value ; : ( model -- gadget ) model-field new-field swap init-field >>model* ; M: model-field graft* [ [ model*>> value>> ] [ editor>> ] bi set-editor-string ] [ dup editor>> model>> add-connection ] [ dup model*>> add-connection ] tri ; M: model-field ungraft* [ dup editor>> model>> remove-connection ] [ dup model*>> remove-connection ] bi ; M: model-field model-changed 2dup model*>> = [ [ value>> ] [ editor>> ] bi* set-editor-string ] [ nip [ editor>> editor-string ] [ model*>> ] bi set-model ] if ; : (new-field) ( editor field -- gadget ) [ new-editor ] dip new-border dup gadget-child >>editor field-theme { 1 0 } >>align ; inline : ( -- field ) "" ; : ( model -- field ) "" switch-models ; : ( model -- gadget ) multiline-editor model-field (new-field) swap init-field >>model* ; : ( -- editor ) "" ; : ( model -- editor ) "" switch-models ; : ( -- field ) f dup [ set-control-value ] curry >>quot f >>model ; : ( init page min max step -- slider ) horizontal slider: ; : image-prep ( -- image ) scan current-vocab name>> "vocab:" "/icons/" surround ".tiff" surround dup cached-image drop ; SYNTAX: IMG-MODEL-BTN: image-prep [ ] curry append! ; SYNTAX: IMG-BTN: image-prep [ swap