! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-books
-USING: gadgets gadgets-controls gadgets-panes gadgets-scrolling
+USING: gadgets gadgets-panes gadgets-scrolling
kernel sequences models ;
TUPLE: book ;
: hide-all ( book -- ) gadget-children [ hide-gadget ] each ;
: current-page ( book -- gadget )
- [ control-model model-value ] keep nth-gadget ;
+ [ control-value ] keep nth-gadget ;
M: book model-changed ( book -- )
dup hide-all
request-focus ;
C: book ( pages -- book )
- dup 0 <model> delegate>control
+ dup 0 <model> <gadget> delegate>control
[ add-gadgets ] keep
- dup dup set-control-self
dup model-changed ;
M: book pref-dim* gadget-children pref-dims max-dim ;
-! Copyright (C) 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
+! Copyright (C) 2005, 2006 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-buttons
-USING: gadgets gadgets-borders gadgets-controls gadgets-labels
+USING: gadgets gadgets-borders gadgets-labels
gadgets-theme generic io kernel math models namespaces sequences
strings styles threads words ;
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-IN: gadgets-controls
-USING: gadgets kernel models ;
+IN: gadgets
+USING: kernel models ;
TUPLE: control self model quot ;
[ set-gadget-delegate ] keep
[ set-control-model ] keep ;
+: control-value ( control -- value ) control-model model-value ;
+
M: control graft*
- dup control-self over control-model add-connection
+ control-self dup dup control-model add-connection
model-changed ;
M: control ungraft*
- dup control-self swap control-model remove-connection ;
+ control-self dup control-model remove-connection ;
M: control model-changed
- [ control-model model-value ] keep
- [ dup control-self swap control-quot call ] keep
- control-self relayout ;
+ control-self
+ [ control-value ] keep
+ [ dup control-quot call ] keep
+ relayout ;
-: delegate>control ( gadget model -- )
- <gadget> [ 2drop ] <control> swap set-gadget-delegate ;
+: delegate>control ( gadget model underlying -- )
+ [ 2drop ] <control> over set-gadget-delegate
+ dup set-control-self ;
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-labels
-USING: arrays freetype gadgets gadgets-controls gadgets-theme
+USING: arrays freetype gadgets gadgets-theme
generic hashtables io kernel math namespaces opengl sequences
styles ;
--- /dev/null
+! Copyright (C) 2006 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+IN: gadgets-lists
+USING: gadgets kernel sequences models opengl math ;
+
+TUPLE: list index quot color ;
+
+C: list ( model quot -- gadget )
+ [ set-list-quot ] keep
+ 0 over set-list-index
+ { 0.8 0.8 1.0 1.0 } over set-list-color
+ dup rot <pile> 1 over set-pack-fill delegate>control ;
+
+M: list model-changed
+ dup clear-gadget
+ dup control-value over list-quot map
+ swap add-gadgets ;
+
+M: list draw-gadget*
+ dup list-color gl-color
+ dup list-index swap gadget-children 2dup bounds-check? [
+ nth rect-bounds swap [ gl-fill-rect ] with-translation
+ ] [
+ 2drop
+ ] if ;
+
+M: list focusable-child* drop t ;
+
+: select-index ( n list -- )
+ dup control-value empty? [
+ 2drop
+ ] [
+ [ control-value length rem ] keep
+ [ set-list-index ] keep
+ relayout-1
+ ] if ;
+
+: select-prev ( list -- )
+ dup list-index 1- swap select-index ;
+
+: select-next ( list -- )
+ dup list-index 1+ swap select-index ;
+
+\ list H{
+ { T{ button-down } [ request-focus ] }
+ { T{ key-down f f "UP" } [ select-prev ] }
+ { T{ key-down f f "DOWN" } [ select-next ] }
+} set-gestures
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-panes
-USING: gadgets gadgets-buttons gadgets-controls gadgets-labels
+USING: gadgets gadgets-buttons gadgets-labels
gadgets-scrolling gadgets-theme generic hashtables io kernel
namespaces sequences ;
"gadgets/panes.factor"
"gadgets/books.factor"
"gadgets/outliner.factor"
+ "gadgets/lists.factor"
"text/document.factor"
"text/elements.factor"
"text/editor.factor"
! Copyright (C) 2006 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-text
-USING: gadgets gadgets-controls kernel models namespaces
-sequences ;
+USING: gadgets kernel models namespaces sequences ;
: editor-extend-selection ( editor -- )
dup request-focus
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-text
USING: arrays errors freetype gadgets gadgets-borders
-gadgets-buttons gadgets-controls gadgets-frames gadgets-labels
+gadgets-buttons gadgets-frames gadgets-labels
gadgets-scrolling gadgets-theme io kernel math models namespaces
opengl sequences strings styles ;
dup <loc> swap set-editor-mark ;
C: editor ( -- editor )
- dup <document> delegate>control
- dup dup set-control-self
+ dup <document> <gadget> delegate>control
dup init-editor-locs
dup editor-theme ;
: change-caret&mark ( editor quot -- )
over >r change-caret r> mark>caret ; inline
-: editor-lines ( editor -- seq )
- control-model model-value ;
-
-: editor-line ( n editor -- str ) editor-lines nth ;
+: editor-line ( n editor -- str ) control-value nth ;
: editor-font* ( editor -- font ) editor-font lookup-font ;
: visible-lines ( editor -- seq )
\ first-visible-line get
\ last-visible-line get
- rot editor-lines <slice> ;
+ rot control-value <slice> ;
: draw-lines ( -- )
GL_MODELVIEW [
[ draw-selection draw-lines draw-caret ] with-editor ;
: editor-height ( editor -- n )
- [ editor-lines length ] keep line>y ;
+ [ control-value length ] keep line>y ;
: editor-width ( editor -- n )
- 0 swap dup editor-font* swap editor-lines
+ 0 swap dup editor-font* swap control-value
[ string-width max ] each-with ;
M: editor pref-dim*
! Copyright (C) 2006 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-text
-USING: gadgets gadgets-controls generic kernel models sequences
-gadgets-theme ;
+USING: gadgets generic kernel models sequences gadgets-theme ;
TUPLE: field model ;
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-text
-USING: arrays definitions gadgets gadgets-controls gadgets-panes
+USING: arrays definitions gadgets gadgets-panes
generic hashtables help io kernel namespaces prettyprint styles
threads sequences vectors definitions parser words strings ;
DEFER: messages
IN: gadgets-workspace
-USING: gadgets gadgets-books gadgets-controls gadgets-workspace
+USING: gadgets gadgets-books gadgets-workspace
generic kernel models scratchpad sequences syntax
gadgets-messages ;
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-workspace
USING: help arrays compiler gadgets gadgets-books
-gadgets-browser gadgets-buttons gadgets-controls
+gadgets-browser gadgets-buttons
gadgets-dataflow gadgets-frames gadgets-grids gadgets-help
gadgets-listener gadgets-presentations gadgets-walker
gadgets-workspace generic kernel math modules scratchpad