! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays alien alien.c-types alien.syntax kernel
-destructors accessors fry words hashtables
+destructors accessors fry words hashtables strings
sequences memoize assocs math math.functions locals init
namespaces combinators fonts colors core-foundation
core-foundation.strings core-foundation.attributed-strings
FUNCTION: CGRect CTLineGetImageBounds ( CTLineRef line, CGContextRef context ) ;
+ERROR: not-a-string object ;
+
: <CTLine> ( string open-font color -- line )
[
- [ dup selection? [ string>> ] when ] 2dip
+ [
+ dup selection? [ string>> ] when
+ dup string? [ not-a-string ] unless
+ ] 2dip
[
kCTForegroundColorAttributeName set
kCTFontAttributeName set
USING: accessors arrays hashtables io kernel math math.functions
namespaces make opengl sequences strings splitting ui.gadgets
ui.gadgets.tracks ui.gadgets.packs fonts ui.render ui.text
-colors colors.constants models ;
+colors colors.constants models combinators ;
IN: ui.gadgets.labels
! A label gadget draws a string.
M: label string>> ( label -- string )
text>> dup string? [ "\n" join ] unless ; inline
+<PRIVATE
+
+PREDICATE: string-array < array [ string? ] all? ;
+
+PRIVATE>
+
+: ?string-lines ( string -- string/array )
+ CHAR: \n over memq? [ string-lines ] when ;
+
+ERROR: not-a-string object ;
+
M: label (>>string) ( string label -- )
- [ CHAR: \n over memq? [ string-lines ] when ] dip (>>text) ; inline
+ [
+ {
+ { [ dup string-array? ] [ ] }
+ { [ dup string? ] [ ?string-lines ] }
+ [ not-a-string ]
+ } cond
+ ] dip (>>text) ; inline
: label-theme ( gadget -- gadget )
sans-serif-font >>font ; inline
M: string text-dim string-dim ;
-M: sequence text-dim
+M: array text-dim
[ { 0 0 } ] 2dip [ string-dim combine-text-dim ] with each ;
: text-width ( font text -- w ) text-dim first ;
M: selection draw-text draw-string ;
-M: sequence draw-text
+M: array draw-text
[
[
2dup { 0 0 } draw-string