Faster grid gadget

slava 2006-10-22 22:46:02 +00:00
parent 5faea12c89
commit b71697db41
20 changed files with 67 additions and 59 deletions

View File

@ -11,14 +11,17 @@
- there was a performance hit, investigate
- float boxing and overflow checks need a gc check too
- [ [ dup call ] dup call ] infer hangs
- grid slows down with 2000 lines
- growable data heap
- more compact relocation info
- update module system docs
- flip may fail with >64kb string
- documentation:
- document columns
- update module system docs
+ ui:
- grid displays quickly now, but constructing large amounts of gadgets
is slow: eg, 10000 [ dup number>string ] map describe
- completion is not ideal: eg, C+e "buttons"
- some way of intercepting all gestures
- slider needs to be modelized

View File

@ -1,14 +1,13 @@
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-frames
USING: arrays gadgets gadgets-grids generic kernel math
namespaces sequences words ;
IN: gadgets
USING: arrays generic kernel math namespaces sequences words ;
! A frame arranges gadgets in a 3x3 grid, where the center
! gadgets gets left-over space.
TUPLE: frame ;
: <frame-grid> 3 [ drop 3 f <array> ] map ;
: <frame-grid> 9 [ drop <gadget> ] map 3 group ;
: @center 1 1 ;
: @left 0 1 ;

View File

@ -1,7 +1,7 @@
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-grids
USING: gadgets kernel math namespaces opengl sequences ;
IN: gadgets
USING: kernel math namespaces opengl sequences ;
! You can set a grid's gadget-boundary to this.
TUPLE: grid-lines color ;

View File

@ -1,7 +1,7 @@
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-grids
USING: arrays gadgets kernel math namespaces sequences words ;
IN: gadgets
USING: arrays kernel math namespaces sequences words ;
TUPLE: grid children gap ;
@ -17,17 +17,14 @@ C: grid ( children -- grid )
: grid-child ( grid i j -- gadget ) rot grid-children nth nth ;
: grid-add ( gadget grid i j -- )
>r >r over [ over add-gadget ] when* r> r>
>r >r 2dup add-gadget r> r>
3dup grid-child unparent rot grid-children nth set-nth ;
: grid-remove ( grid i j -- )
>r >r >r f r> r> r> grid-add ;
: ?pref-dim ( gadget/f -- dim )
[ pref-dim ] [ { 0 0 } ] if* ;
>r >r >r <gadget> r> r> r> grid-add ;
: pref-dim-grid ( -- dims )
grid get grid-children [ [ ?pref-dim ] map ] map ;
grid get grid-children [ [ pref-dim ] map ] map ;
: compute-grid ( -- horiz vert )
pref-dim-grid
@ -47,9 +44,9 @@ M: grid pref-dim*
] with-grid ;
: do-grid ( dims quot -- )
swap grid get grid-children [
[ dup [ pick call ] [ 2drop ] if ] 2each
] 2each drop ; inline
swap grid get grid-children
[ [ pick call ] 2each ] 2each
drop ; inline
: pair-up ( horiz vert -- dims )
[ swap [ swap (pair-up) ] map-with ] map-with ;
@ -75,3 +72,12 @@ M: grid layout*
#! The setter has stack effect ( new gadget -- ),
#! the loc is @center, @top, etc.
swap [ [ grid-add ] build-spec ] with-gadget ; inline
M: grid children-on ( rect gadget -- seq )
dup gadget-children empty? [
2drop f
] [
{ 0 1 } swap grid-children
[ 0 <column> fast-children-on ] keep
<slice> concat
] if ;

View File

@ -1,7 +1,7 @@
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets
USING: arrays errors freetype gadgets-frames generic hashtables
USING: arrays errors freetype gadgets generic hashtables
kernel math models namespaces opengl sequences ;
: menu-loc ( world menu -- loc )

View File

@ -2,9 +2,8 @@
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-outliner
USING: arrays gadgets gadgets-borders gadgets-buttons
gadgets-frames gadgets-grids gadgets-labels gadgets-panes
gadgets-theme generic io kernel math opengl sequences styles
namespaces ;
gadgets-labels gadgets-panes gadgets-theme generic io kernel
math opengl sequences styles namespaces ;
! Vertical line.
TUPLE: guide color ;
@ -45,11 +44,12 @@ DEFER: set-outliner-expanded?
>r not <expand-button> r> @top-left grid-add ;
: setup-center ( expanded? outliner -- )
[ swap [ outliner-quot make-pane ] [ drop f ] if ] keep
@center grid-add ;
[
swap [ outliner-quot make-pane ] [ drop <gadget> ] if
] keep @center grid-add ;
: setup-guide ( expanded? outliner -- )
>r [ <guide-gadget> ] [ f ] if r> @left grid-add ;
>r [ <guide-gadget> ] [ <gadget> ] if r> @left grid-add ;
: set-outliner-expanded? ( expanded? outliner -- )
#! Call the expander quotation if expanding.

View File

@ -5,7 +5,7 @@ DEFER: call-listener
IN: gadgets-presentations
USING: arrays definitions gadgets gadgets-borders
gadgets-buttons gadgets-grids gadgets-labels gadgets-outliner
gadgets-buttons gadgets-labels gadgets-outliner
gadgets-panes gadgets-paragraphs gadgets-theme
generic hashtables tools io kernel prettyprint sequences strings
styles words help math models namespaces ;

View File

@ -1,8 +1,8 @@
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-scrolling
USING: arrays gadgets gadgets-frames gadgets-theme
gadgets-viewports generic kernel math namespaces sequences ;
USING: arrays gadgets gadgets-theme gadgets-viewports generic
kernel math namespaces sequences ;
! A scroller combines a viewport with two x and y sliders.
! The follows slot is a boolean, if true scroller will scroll

View File

@ -1,8 +1,8 @@
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-scrolling
USING: arrays gadgets gadgets-buttons gadgets-frames
gadgets-grids gadgets-theme generic kernel math namespaces
USING: arrays gadgets gadgets-buttons
gadgets-theme generic kernel math namespaces
sequences styles threads vectors ;
! An elevator has a thumb that may be moved up and down.

View File

@ -152,17 +152,19 @@ M: pack pref-dim*
M: pack layout*
dup gadget-children pref-dims pack-layout ;
: fast-children-on ( dim axis gadgets -- i )
: (fast-children-on) ( dim axis gadgets -- i )
swapd [ rect-loc v- over v. ] binsearch nip ;
M: pack children-on
dup gadget-orientation swap gadget-children [
: fast-children-on ( rect axis children -- from to )
3dup
>r >r dup rect-loc swap rect-dim v+ origin get v-
r> r> fast-children-on 1+
r> r> (fast-children-on) 1+
>r
>r >r rect-loc origin get v-
r> r> fast-children-on
r> r> (fast-children-on)
0 max
r>
] keep <slice> ;
r> ;
M: pack children-on ( rect gadget -- seq )
dup gadget-orientation swap gadget-children
[ fast-children-on ] keep <slice> ;

View File

@ -2,9 +2,8 @@
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-text
USING: arrays errors freetype gadgets gadgets-borders
gadgets-buttons gadgets-frames gadgets-labels
gadgets-scrolling gadgets-theme io kernel math models namespaces
opengl sequences strings styles ;
gadgets-buttons gadgets-labels gadgets-scrolling gadgets-theme
io kernel math models namespaces opengl sequences strings styles ;
TUPLE: editor
font color caret-color selection-color

View File

@ -3,8 +3,8 @@
USING: arrays sequences kernel gadgets-panes definitions
prettyprint gadgets-theme gadgets-borders gadgets
generic gadgets-scrolling math io words models styles
namespaces gadgets-tracks gadgets-presentations gadgets-grids
gadgets-workspace gadgets-frames help gadgets-buttons
namespaces gadgets-tracks gadgets-presentations
gadgets-workspace help gadgets-buttons
gadgets-search tools ;
IN: gadgets-browser

View File

@ -5,7 +5,7 @@ USING: namespaces arrays sequences io inference math kernel
generic prettyprint words gadgets opengl gadgets-panes
gadgets-labels gadgets-theme gadgets-presentations
gadgets-buttons gadgets-borders gadgets-scrolling
gadgets-frames gadgets-workspace optimizer models help ;
gadgets-workspace optimizer models help ;
GENERIC: node>gadget* ( height node -- gadget )

View File

@ -1,7 +1,7 @@
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-help
USING: gadgets gadgets-borders gadgets-buttons gadgets-frames
USING: gadgets gadgets-borders gadgets-buttons
gadgets-panes gadgets-search gadgets-scrolling help kernel
models namespaces sequences gadgets-tracks gadgets-workspace ;

View File

@ -1,7 +1,7 @@
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-listener
USING: compiler arrays gadgets gadgets-frames gadgets-labels
USING: compiler arrays gadgets gadgets-labels
gadgets-panes gadgets-scrolling gadgets-text gadgets-lists
gadgets-search gadgets-theme gadgets-tracks gadgets-workspace
generic hashtables tools io kernel listener math models

View File

@ -1,8 +1,8 @@
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-search
USING: arrays gadgets gadgets-frames gadgets-labels
gadgets-panes gadgets-scrolling gadgets-text gadgets-theme
USING: arrays gadgets gadgets-labels gadgets-panes
gadgets-scrolling gadgets-text gadgets-theme
generic help tools kernel models sequences words
gadgets-borders gadgets-lists namespaces parser hashtables io
completion styles ;

View File

@ -1,7 +1,7 @@
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-walker
USING: arrays errors gadgets gadgets-buttons gadgets-frames
USING: arrays errors gadgets gadgets-buttons
gadgets-listener gadgets-panes gadgets-scrolling gadgets-text
gadgets-tracks gadgets-workspace generic hashtables tools
interpreter io kernel kernel-internals listener math models

View File

@ -2,8 +2,7 @@
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-workspace
USING: help arrays compiler gadgets gadgets-books
gadgets-browser gadgets-buttons
gadgets-dataflow gadgets-frames gadgets-grids gadgets-help
gadgets-browser gadgets-buttons gadgets-dataflow gadgets-help
gadgets-listener gadgets-presentations gadgets-walker
gadgets-workspace generic kernel math modules scratchpad
sequences syntax words io namespaces hashtables

View File

@ -1,8 +1,8 @@
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets
USING: arrays errors gadgets gadgets-buttons gadgets-frames
gadgets-grids gadgets-labels gadgets-panes gadgets-presentations
USING: arrays errors gadgets gadgets-buttons
gadgets-labels gadgets-panes gadgets-presentations
gadgets-scrolling gadgets-theme gadgets-viewports generic
hashtables io kernel math models namespaces prettyprint queues
sequences test threads help sequences words ;

View File

@ -1,7 +1,7 @@
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets
USING: arrays errors freetype gadgets-frames generic hashtables
USING: arrays errors freetype generic hashtables
kernel math models namespaces opengl sequences ;
! The world gadget is the top level gadget that all (visible)