github.com/gop9/olt@v0.0.0-20200202132135-d956aad50b08/framework/label/label.go (about) 1 package label 2 3 import ( 4 "image" 5 "image/color" 6 ) 7 8 type Label struct { 9 Kind LabelKind 10 Text string 11 Img *image.RGBA 12 Color color.RGBA 13 Symbol SymbolType 14 Align Align 15 } 16 17 type LabelKind int 18 19 const ( 20 ColorLabel LabelKind = iota 21 ImageLabel 22 ImageTextLabel 23 SymbolLabel 24 SymbolTextLabel 25 TextLabel 26 ) 27 28 // Text alignment. 29 // A two character string, the first character is horizontal alignment, the second character vertical alignment. 30 // For the first character: L (left), C (centered), R (right) 31 // For the second character: T (top), C (centered), B (bottom) 32 type Align string 33 34 type SymbolType int 35 36 const ( 37 SymbolNone SymbolType = iota 38 SymbolX 39 SymbolUnderscore 40 SymbolCircle 41 SymbolCircleFilled 42 SymbolRect 43 SymbolRectFilled 44 SymbolTriangleUp 45 SymbolTriangleDown 46 SymbolTriangleLeft 47 SymbolTriangleRight 48 SymbolPlus 49 SymbolMinus 50 ) 51 52 func T(text string) Label { 53 return Label{Kind: TextLabel, Text: text, Align: ""} 54 } 55 56 func TA(text string, align Align) Label { 57 return Label{Kind: TextLabel, Text: text, Align: align} 58 } 59 60 func C(color color.RGBA) Label { 61 return Label{Kind: ColorLabel, Color: color} 62 } 63 64 func I(img *image.RGBA) Label { 65 return Label{Kind: ImageLabel, Img: img} 66 } 67 68 func IT(img *image.RGBA, text string, align Align) Label { 69 return Label{Kind: ImageTextLabel, Img: img, Text: text, Align: align} 70 } 71 72 func S(s SymbolType) Label { 73 return Label{Kind: SymbolLabel, Symbol: s} 74 } 75 76 func ST(s SymbolType, text string, align Align) Label { 77 return Label{Kind: SymbolTextLabel, Symbol: s, Text: text, Align: align} 78 }