factor/library/ui/labels.factor

26 lines
740 B
Factor
Raw Normal View History

2005-02-01 22:48:04 -05:00
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
2005-02-16 21:54:36 -05:00
USING: generic kernel lists math namespaces sdl sdl-ttf ;
2005-02-01 22:48:04 -05:00
! A label draws a text label, centered on the gadget's bounding
! box.
TUPLE: label text delegate ;
2005-02-02 19:50:13 -05:00
C: label ( text -- )
2005-02-26 00:57:53 -05:00
<empty-gadget> over set-label-delegate
2005-02-02 19:50:13 -05:00
[ set-label-text ] keep ;
M: label layout* ( label -- )
2005-02-11 19:09:48 -05:00
[ label-text dup shape-w swap shape-h ] keep resize-gadget ;
2005-02-01 22:48:04 -05:00
2005-02-16 21:54:36 -05:00
: label-x ( label -- x )
dup shape-w swap label-text shape-w - 2 /i ;
: label-y ( label -- y )
shape-h font get lookup-font TTF_FontHeight - 2 /i ;
M: label draw-shape ( label -- )
2005-02-16 21:54:36 -05:00
dup label-x over label-y rect> over shape-pos +
2005-02-26 02:11:25 -05:00
[ label-text draw-shape ] with-trans ;