factor/library/ui/gadgets/labels.factor

30 lines
786 B
Factor
Raw Normal View History

! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-labels
2006-10-03 18:17:21 -04:00
USING: arrays freetype gadgets gadgets-theme
generic hashtables io kernel math namespaces opengl sequences
styles ;
2005-02-01 22:48:04 -05:00
2005-03-01 22:11:08 -05:00
! A label gadget draws a string.
2005-10-27 16:17:50 -04:00
TUPLE: label text font color ;
2005-02-01 22:48:04 -05:00
C: label ( text -- label )
2005-10-27 16:17:50 -04:00
dup delegate>gadget
[ set-label-text ] keep
dup label-theme ;
2005-02-02 19:50:13 -05:00
2006-08-15 04:57:12 -04:00
: label-size ( gadget -- dim )
2006-06-23 02:25:08 -04:00
dup label-font lookup-font dup font-height >r
2006-06-23 00:06:53 -04:00
swap label-text string-width r> 2array ;
2005-10-14 04:05:02 -04:00
M: label pref-dim* label-size ;
2005-10-14 04:05:02 -04:00
: draw-label ( label -- )
2005-10-27 16:17:50 -04:00
dup label-color gl-color
2006-06-23 02:25:08 -04:00
dup label-font swap label-text draw-string ;
2005-02-01 22:48:04 -05:00
M: label draw-gadget* draw-label ;
: <label-control> ( model -- gadget )
"" <label> [ set-label-text ] <control> ;