factor/core/ui/gadgets/labels.factor

35 lines
935 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 strings ;
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
: label-string ( label -- string )
label-text dup string? [ "\n" join ] unless ; inline
: set-label-string ( string label -- )
CHAR: \n pick memq? [
2006-11-29 15:18:33 -05:00
>r string-lines r> set-label-text
] [
set-label-text
] if ; inline
C: label ( string -- label )
2005-10-27 16:17:50 -04:00
dup delegate>gadget
[ set-label-string ] keep
2005-10-27 16:17:50 -04:00
dup label-theme ;
2005-02-02 19:50:13 -05:00
2006-10-12 18:09:30 -04:00
M: label pref-dim*
2006-12-11 19:59:22 -05:00
dup label-font open-font swap label-text text-dim ;
2005-10-14 04:05:02 -04:00
2006-10-12 18:09:30 -04:00
M: label draw-gadget*
2005-10-27 16:17:50 -04:00
dup label-color gl-color
dup label-font swap label-text origin get draw-text ;
2005-02-01 22:48:04 -05:00
: <label-control> ( model -- gadget )
"" <label> [ set-label-string ] <control> ;