factor/library/ui/gadgets.factor

69 lines
1.7 KiB
Factor
Raw Normal View History

2005-01-31 14:02:09 -05:00
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
2005-06-23 22:35:41 -04:00
USING: generic hashtables kernel lists math matrices namespaces
2005-07-17 02:49:07 -04:00
sequences styles vectors ;
2005-01-31 14:02:09 -05:00
2005-02-02 19:50:13 -05:00
! A gadget is a shape, a paint, a mapping of gestures to
! actions, and a reference to the gadget's parent. A gadget
! delegates to its shape.
2005-07-17 00:21:10 -04:00
TUPLE: gadget
paint gestures visible? relayout? root?
parent children ;
2005-01-31 14:02:09 -05:00
2005-07-16 22:16:18 -04:00
: gadget-child gadget-children first ;
2005-07-13 21:03:34 -04:00
C: gadget ( -- gadget )
2005-07-17 00:21:10 -04:00
{ 0 0 0 } dup <rectangle> over set-delegate
t over set-gadget-visible? ;
2005-01-31 14:02:09 -05:00
2005-07-08 01:32:29 -04:00
DEFER: add-invalid
: invalidate ( gadget -- )
t swap set-gadget-relayout? ;
: relayout ( gadget -- )
2005-05-05 22:30:58 -04:00
#! Relayout and redraw a gadget and its parent before the
#! next iteration of the event loop.
2005-04-30 17:17:10 -04:00
dup gadget-relayout? [
drop
] [
2005-07-08 01:32:29 -04:00
dup invalidate
dup gadget-root?
[ add-invalid ]
2005-07-08 01:32:29 -04:00
[ gadget-parent [ relayout ] when* ] ifte
2005-04-30 17:17:10 -04:00
] ifte ;
: (relayout-down)
dup invalidate gadget-children [ (relayout-down) ] each ;
2005-07-08 01:32:29 -04:00
: relayout-down ( gadget -- )
2005-05-05 22:30:58 -04:00
#! Relayout a gadget and its children.
dup add-invalid (relayout-down) ;
2005-04-30 17:17:10 -04:00
: set-gadget-dim ( dim gadget -- )
2dup shape-dim =
2005-07-08 01:32:29 -04:00
[ 2drop ] [ [ set-shape-dim ] keep relayout-down ] ifte ;
2005-06-28 23:50:23 -04:00
GENERIC: pref-dim ( gadget -- dim )
2005-06-28 23:50:23 -04:00
M: gadget pref-dim shape-dim ;
2005-03-07 23:15:00 -05:00
2005-03-07 22:11:36 -05:00
GENERIC: layout* ( gadget -- )
2005-03-07 23:15:00 -05:00
2005-06-28 23:50:23 -04:00
: prefer ( gadget -- ) dup pref-dim swap set-gadget-dim ;
2005-03-07 23:15:00 -05:00
M: gadget layout* drop ;
2005-02-19 21:49:37 -05:00
2005-03-07 22:11:36 -05:00
GENERIC: user-input* ( ch gadget -- ? )
2005-06-23 22:35:41 -04:00
2005-03-07 22:11:36 -05:00
M: gadget user-input* 2drop t ;
GENERIC: focusable-child* ( gadget -- gadget/t )
M: gadget focusable-child* drop t ;
: focusable-child ( gadget -- gadget )
dup focusable-child*
dup t = [ drop ] [ nip focusable-child ] ifte ;