! Copyright (C) 2005, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays colors.constants combinators fonts fry kernel make math.functions models namespaces sequences splitting strings ui.baseline-alignment ui.gadgets ui.gadgets.tracks ui.pens.solid ui.render ui.text ; IN: ui.gadgets.labels ! A label gadget draws a string. TUPLE: label < aligned-gadget text font ; SLOT: string M: label string>> ( label -- string ) text>> dup string? [ "\n" join ] unless ; inline : ?string-lines ( string -- string/array ) CHAR: \n over member-eq? [ string-lines ] when ; ERROR: not-a-string object ; M: label string<< ( string label -- ) [ { { [ dup string-array? ] [ ] } { [ dup string? ] [ ?string-lines ] } [ not-a-string ] } cond ] dip [ text<< ] [ relayout ] bi ; inline : label-theme ( gadget -- gadget ) sans-serif-font >>font ; inline : new-label ( string class -- label ) new swap >>string label-theme ; inline :