forked from icza/gowut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
style.go
816 lines (635 loc) · 22.3 KB
/
style.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
// Copyright (C) 2013 Andras Belicza. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Defines the style builder and style attribute constants.
package gwu
import (
"strconv"
)
// Style attribute constants.
const (
StBackground = "background" // Background (color)
StBorder = "border" // Border
StBorderLeft = "border-left" // Left border
StBorderRight = "border-right" // Right border
StBorderTop = "border-top" // Top border
StBorderBottom = "border-bottom" // Bottom border
StColor = "color" // (Foreground) color
StCursor = "cursor" // Cursor
StDisplay = "display" // Display
StFontSize = "font-size" // Font size
StFontStyle = "font-style" // Font style
StFontWeight = "font-weight" // Font weight
StHeight = "height" // Height
StMargin = "margin" // Margin
StMarginLeft = "margin-left" // Left margin
StMarginRight = "margin-right" // Right margin
StMarginTop = "margin-top" // Top margin
StMarginBottom = "margin-bottom" // Bottom margin
StPadding = "padding" // Padding
StPaddingLeft = "padding-left" // Left padding
StPaddingRight = "padding-right" // Right padding
StPaddingTop = "padding-top" // Top padding
StPaddingBottom = "padding-bottom" // Bottom padding
StWhiteSpace = "white-space" // White-space
StWidth = "width" // Width
)
// The 17 standard color constants.
const (
ClrAqua = "Aqua" // Aqua (#00FFFF)
ClrBlack = "Black" // Black (#000000)
ClrBlue = "Blue" // Blue (#0000FF)
ClrFuchsia = "Fuchsia" // Fuchsia (#FF00FF)
ClrGray = "Gray" // Gray (#808080)
ClrGrey = "Grey" // Grey (#808080)
ClrGreen = "Green" // Green (#008000)
ClrLime = "Lime" // Lime (#00FF00)
ClrMaroon = "Maroon" // Maroon (#800000)
ClrNavy = "Navy" // Navy (#000080)
ClrOlive = "Olive" // Olive (#808000)
ClrPurple = "Purple" // Purple (#800080)
ClrRed = "Red" // Red (#FF0000)
ClrSilver = "Silver" // Silver (#C0C0C0)
ClrTeal = "Teal" // Teal (#008080)
ClrWhite = "White" // White (#FFFFFF)
ClrYellow = "Yellow" // Yellow (#FFFF00)
)
// Border style constants.
const (
BrdStyleSolid = "solid" // Solid
BrdStyleDashed = "dashed" // Dashed
BrdStyleDotted = "dotted" // Dotted
BrdStyleDouble = "double" // Double
BrdStyleGroove = "groove" // 3D grooved border
BrdStyleRidge = "ridge" // 3D ridged border
BrdStyleInset = "inset" // 3D inset border
BrdStyleOutset = "outset" // 3D outset border
)
// Font weight constants.
const (
FontWeightNormal = "normal" // Normal
FontWeightBold = "bold" // Bold
FontWeightBolder = "bolder" // Bolder
FontWeightLighter = "lighter" // Lighter
)
// Font style constants.
const (
FontStyleNormal = "normal" // Normal
FontStyleItalic = "italic" // Italic
)
// Mouse cursor constants.
const (
CursorAuto = "auto" // Default. Web browser sets the cursor.
CursorCrosshair = "crosshair" // Crosshair
CursorDefault = "default" // The default cursor.
CursorHelp = "help" // Help
CursorMove = "move" // Move
CursorPointer = "pointer" // Pointer
CursorProgress = "progress" // Progress
CursorText = "text" // Text
CursorWait = "wait" // Wait
CursorInherit = "inherit" // The cursor should be inherited from the parent element.
)
// Display mode constants.
const (
DisplayNone = "none" // The element will not be displayed.
DisplayBlock = "block" // The element is displayed as a block.
DisplayInline = "inline" // The element is displayed as an in-line element. This is the default.
DisplayInherit = "inherit" // The display property value will be inherited from the parent element.
)
// White space constants.
const (
WhiteSpaceNormal = "normal" // Sequences of white spaces are collapsed into a single whitespace. Text will wrap when necessary. This is the default.
WhiteSpaceNowrap = "nowrap" // Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line (the text is in one line).
WhiteSpacePre = "pre" // Whitespace is preserved. Text will only wrap on line breaks.
WhiteSpacePreLine = "pre-line" // Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary and on line breaks.
WhiteSpacePreWrap = "pre-wrap" // Whitespace is preserved. Text will wrap when necessary, and on line breaks.
WhiteSpaceInherit = "inherit" // Whitespace property will be inherited from the parent element.
)
// Style interface contains utility methods for manipulating
// the style of a component.
// You can think of it as the Style Builder.
// Set methods return the style reference so setting the values
// of multiple style attributes can be chained.
type Style interface {
// AddClass adds a style class name to the class name list.
AddClass(class string) Style
// SetClass sets a style class name, removing all previously
// added style class names.
// Tip: set an empty string class name to remove all class names.
SetClass(class string) Style
// RemoveClass removes a style class name.
// If the specified class is not found, this is a no-op.
RemoveClass(class string) Style
// Get returns the explicitly set value of the specified style attribute.
// Explicitly set style attributes will be concatenated and rendered
// as the "style" HTML attribute of the component.
Get(name string) string
// Set sets the value of the specified style attribute.
// Pass an empty string value to delete the specified style attribute.
Set(name, value string) Style
// Size returns the size.
Size() (width, height string)
// SetSize sets the width and height.
SetSize(width, height string) Style
// SetSizePx sets the width and height, in pixels.
SetSizePx(width, height int) Style
// SetFullSize sets full width (100%) and height (100%).
SetFullSize() Style
// Padding returns the padding.
// (The "padding" style attribute only.)
Padding() string
// SetPadding sets the padding.
// (The "padding" style attribute only.)
SetPadding(value string) Style
// SetPadding2 sets the padding specified by parts.
// (The "padding" style attribute only.)
SetPadding2(top, right, bottom, left string) Style
// SetPaddingPx sets the padding specified by parts, in pixels.
// (The "padding" style attribute only.)
SetPaddingPx(top, right, bottom, left int) Style
// PaddingLeft returns the left padding.
// (The "padding-left" style attribute only.)
PaddingLeft() string
// SetPaddingLeft sets the left padding.
// (The "padding-left" style attribute only.)
SetPaddingLeft(value string) Style
// SetPaddingLeftPx sets the left padding, in pixels.
// (The "padding-left" style attribute only.)
SetPaddingLeftPx(width int) Style
// PaddingRight returns the right padding.
// (The "padding-right" style attribute only.)
PaddingRight() string
// SetPaddingRight sets the right padding.
// (The "padding-right" style attribute only.)
SetPaddingRight(value string) Style
// SetPaddingRightPx sets the right padding, in pixels.
// (The "padding-right" style attribute only.)
SetPaddingRightPx(width int) Style
// PaddingTop returns the top padding.
// (The "padding-top" style attribute only.)
PaddingTop() string
// SetPaddingTop sets the top padding.
// (The "padding-top" style attribute only.)
SetPaddingTop(value string) Style
// SetPaddingTopPx sets the top padding, in pixels.
// (The "padding-top" style attribute only.)
SetPaddingTopPx(height int) Style
// PaddingBottom returns the bottom padding.
// (The "padding-bottom" style attribute only.)
PaddingBottom() string
// SetPaddingBottom sets the bottom padding.
// (The "padding-bottom" style attribute only.)
SetPaddingBottom(value string) Style
// SetPaddingBottomPx sets the bottom padding, in pixels.
// (The "padding-bottom" style attribute only.)
SetPaddingBottomPx(height int) Style
// Margin returns the margin.
// (The "margin" style attribute only.)
Margin() string
// SetMargin sets the margin.
// (The "margin" style attribute only.)
SetMargin(value string) Style
// SetMargin2 sets the margin specified by parts.
// (The "margin" style attribute only.)
SetMargin2(top, right, bottom, left string) Style
// SetMarginPx sets the margin specified by parts, in pixels.
// (The "margin" style attribute only.)
SetMarginPx(top, right, bottom, left int) Style
// MarginLeft returns the left margin.
// (The "margin-left" style attribute only.)
MarginLeft() string
// SetMarginLeft sets the left margin.
// (The "margin-left" style attribute only.)
SetMarginLeft(value string) Style
// SetMarginLeftPx sets the left margin, in pixels.
// (The "margin-left" style attribute only.)
SetMarginLeftPx(width int) Style
// MarginRight returns the right margin.
// (The "margin-right" style attribute only.)
MarginRight() string
// SetMarginRight sets the right margin.
// (The "margin-right" style attribute only.)
SetMarginRight(value string) Style
// SetMarginRightPx sets the right margin, in pixels.
// (The "margin-right" style attribute only.)
SetMarginRightPx(width int) Style
// MarginTop returns the top margin.
// (The "margin-top" style attribute only.)
MarginTop() string
// SetMarginTop sets the top margin.
// (The "margin-top" style attribute only.)
SetMarginTop(value string) Style
// SetMarginTopPx sets the top margin, in pixels.
// (The "margin-top" style attribute only.)
SetMarginTopPx(height int) Style
// MarginBottom returns the bottom margin.
// (The "margin-bottom" style attribute only.)
MarginBottom() string
// SetMarginBottom sets the bottom margin.
// (The "margin-bottom" style attribute only.)
SetMarginBottom(value string) Style
// SetMarginBottomPx sets the bottom margin, in pixels.
// (The "margin-bottom" style attribute only.)
SetMarginBottomPx(height int) Style
// Background returns the background (color).
Background() string
// SetBackground sets the background (color).
SetBackground(value string) Style
// Border returns the border.
Border() string
// SetBorder sets the border.
SetBorder(value string) Style
// SetBorder2 sets the border specified by parts.
// (The "border" style attribute only.)
SetBorder2(width int, style, color string) Style
// BorderLeft returns the left border.
BorderLeft() string
// SetBorderLeft sets the left border.
SetBorderLeft(value string) Style
// SetBorderLeft2 sets the left border specified by parts.
// (The "border-left" style attribute only.)
SetBorderLeft2(width int, style, color string) Style
// BorderRight returns the right border.
BorderRight() string
// SetBorderRight sets the right border.
SetBorderRight(value string) Style
// SetBorderRight2 sets the right border specified by parts.
// (The "border-right" style attribute only.)
SetBorderRight2(width int, style, color string) Style
// BorderTop returns the top border.
BorderTop() string
// SetBorderTop sets the top border.
SetBorderTop(value string) Style
// SetBorderTop2 sets the top border specified by parts.
// (The "border-top" style attribute only.)
SetBorderTop2(width int, style, color string) Style
// BorderBottom returns the bottom border.
BorderBottom() string
// SetBorderBottom sets the bottom border.
SetBorderBottom(value string) Style
// SetBorderBottom2 sets the bottom border specified by parts.
// (The "border-bottom" style attribute only.)
SetBorderBottom2(width int, style, color string) Style
// Color returns the (foreground) color.
Color() string
// SetColor sets the (foreground) color.
SetColor(value string) Style
// Cursor returns the (mouse) cursor.
Cursor() string
// SetCursor sets the (mouse) cursor.
SetCursor(value string) Style
// Display returns the display mode.
Display() string
// SetDisplay sets the display mode
SetDisplay(value string) Style
// FontSize returns the font size.
FontSize() string
// SetFontSize sets the font size.
SetFontSize(value string) Style
// FontStyle returns the font style.
FontStyle() string
// SetFontStyle sets the font style.
SetFontStyle(value string) Style
// FontWeight returns the font weight.
FontWeight() string
// SetFontWeight sets the font weight.
SetFontWeight(value string) Style
// Width returns the width.
Width() string
// SetWidth sets the width.
SetWidth(value string) Style
// SetWidthPx sets the width, in pixels.
SetWidthPx(width int) Style
// SetFullWidth sets full width (100%).
SetFullWidth() Style
// Height returns the height.
Height() string
// SetHeight sets the height.
SetHeight(value string) Style
// SetHeightPx sets the height.
SetHeightPx(height int) Style
// SetFullHeight sets full height (100%).
SetFullHeight() Style
// WhiteSpace returns the white space attribute value.
WhiteSpace() string
// SetWhiteSpace sets the white space attribute value.
SetWhiteSpace(value string) Style
// render renders all style information (style class names
// and style attributes).
render(w Writer)
// renderClasses renders the style class names.
renderClasses(w Writer)
// renderAttrs renders the style attributes.
renderAttrs(w Writer)
}
type styleImpl struct {
classes []string // Style classes.
attrs map[string]string // Explicitly set style attributes. Lazily initialized.
}
// newStyleImpl creates a new styleImpl.
func newStyleImpl() *styleImpl {
return &styleImpl{}
}
func (s *styleImpl) AddClass(class string) Style {
s.classes = append(s.classes, class)
return s
}
func (s *styleImpl) SetClass(class string) Style {
s.classes = s.classes[0:0]
if len(class) > 0 {
s.classes = append(s.classes, class)
}
return s
}
func (s *styleImpl) RemoveClass(class string) Style {
for i, cl := range s.classes {
if cl == class {
oldClasses := s.classes
s.classes = append(oldClasses[0:i], oldClasses[i+1:]...)
oldClasses[len(oldClasses)-1] = ""
break
}
}
return s
}
func (s *styleImpl) Get(name string) string {
return s.attrs[name]
}
func (s *styleImpl) Set(name, value string) Style {
if s.attrs == nil {
s.attrs = make(map[string]string)
}
if len(value) > 0 {
s.attrs[name] = value
} else {
delete(s.attrs, name)
}
return s
}
func (s *styleImpl) Size() (width, height string) {
return s.Get(StWidth), s.Get(StHeight)
}
func (s *styleImpl) SetSize(width, height string) Style {
s.Set(StWidth, width)
s.Set(StHeight, height)
return s
}
func (s *styleImpl) SetSizePx(width, height int) Style {
return s.SetSize(strconv.Itoa(width)+"px", strconv.Itoa(height)+"px")
}
func (s *styleImpl) SetFullSize() Style {
return s.SetSize("100%", "100%")
}
func (s *styleImpl) Padding() string {
return s.Get(StPadding)
}
func (s *styleImpl) SetPadding(value string) Style {
return s.Set(StPadding, value)
}
func (s *styleImpl) SetPadding2(top, right, bottom, left string) Style {
return s.SetPadding(top + " " + right + " " + bottom + " " + left)
}
func (s *styleImpl) SetPaddingPx(top, right, bottom, left int) Style {
return s.SetPadding(strconv.Itoa(top) + "px " + strconv.Itoa(right) + "px " + strconv.Itoa(bottom) + "px " + strconv.Itoa(left) + "px")
}
func (s *styleImpl) PaddingLeft() string {
return s.Get(StPaddingLeft)
}
func (s *styleImpl) SetPaddingLeft(value string) Style {
return s.Set(StPaddingLeft, value)
}
func (s *styleImpl) SetPaddingLeftPx(width int) Style {
return s.SetPaddingLeft(strconv.Itoa(width) + "px")
}
func (s *styleImpl) PaddingRight() string {
return s.Get(StPaddingRight)
}
func (s *styleImpl) SetPaddingRight(value string) Style {
return s.Set(StPaddingRight, value)
}
func (s *styleImpl) SetPaddingRightPx(width int) Style {
return s.SetPaddingRight(strconv.Itoa(width) + "px")
}
func (s *styleImpl) PaddingTop() string {
return s.Get(StPaddingTop)
}
func (s *styleImpl) SetPaddingTop(value string) Style {
return s.Set(StPaddingTop, value)
}
func (s *styleImpl) SetPaddingTopPx(height int) Style {
return s.SetPaddingTop(strconv.Itoa(height) + "px")
}
func (s *styleImpl) PaddingBottom() string {
return s.Get(StPaddingBottom)
}
func (s *styleImpl) SetPaddingBottom(value string) Style {
return s.Set(StPaddingBottom, value)
}
func (s *styleImpl) SetPaddingBottomPx(height int) Style {
return s.SetPaddingBottom(strconv.Itoa(height) + "px")
}
func (s *styleImpl) Margin() string {
return s.Get(StMargin)
}
func (s *styleImpl) SetMargin(value string) Style {
return s.Set(StMargin, value)
}
func (s *styleImpl) SetMargin2(top, right, bottom, left string) Style {
return s.SetMargin(top + " " + right + " " + bottom + " " + left)
}
func (s *styleImpl) SetMarginPx(top, right, bottom, left int) Style {
return s.SetMargin(strconv.Itoa(top) + "px " + strconv.Itoa(right) + "px " + strconv.Itoa(bottom) + "px " + strconv.Itoa(left) + "px ")
}
func (s *styleImpl) MarginLeft() string {
return s.Get(StMarginLeft)
}
func (s *styleImpl) SetMarginLeft(value string) Style {
return s.Set(StMarginLeft, value)
}
func (s *styleImpl) SetMarginLeftPx(width int) Style {
return s.SetMarginLeft(strconv.Itoa(width) + "px")
}
func (s *styleImpl) MarginRight() string {
return s.Get(StMarginRight)
}
func (s *styleImpl) SetMarginRight(value string) Style {
return s.Set(StMarginRight, value)
}
func (s *styleImpl) SetMarginRightPx(width int) Style {
return s.SetMarginRight(strconv.Itoa(width) + "px")
}
func (s *styleImpl) MarginTop() string {
return s.Get(StMarginTop)
}
func (s *styleImpl) SetMarginTop(value string) Style {
return s.Set(StMarginTop, value)
}
func (s *styleImpl) SetMarginTopPx(height int) Style {
return s.SetMarginTop(strconv.Itoa(height) + "px")
}
func (s *styleImpl) MarginBottom() string {
return s.Get(StMarginBottom)
}
func (s *styleImpl) SetMarginBottom(value string) Style {
return s.Set(StMarginBottom, value)
}
func (s *styleImpl) SetMarginBottomPx(height int) Style {
return s.SetMarginBottom(strconv.Itoa(height) + "px")
}
func (s *styleImpl) Background() string {
return s.Get(StBackground)
}
func (s *styleImpl) SetBackground(value string) Style {
return s.Set(StBackground, value)
}
func (s *styleImpl) Border() string {
return s.Get(StBorder)
}
func (s *styleImpl) SetBorder(value string) Style {
return s.Set(StBorder, value)
}
func (s *styleImpl) SetBorder2(width int, style, color string) Style {
return s.SetBorder(strconv.Itoa(width) + "px " + style + " " + color)
}
func (s *styleImpl) BorderLeft() string {
return s.Get(StBorderLeft)
}
func (s *styleImpl) SetBorderLeft(value string) Style {
return s.Set(StBorderLeft, value)
}
func (s *styleImpl) SetBorderLeft2(width int, style, color string) Style {
return s.SetBorderLeft(strconv.Itoa(width) + "px " + style + " " + color)
}
func (s *styleImpl) BorderRight() string {
return s.Get(StBorderRight)
}
func (s *styleImpl) SetBorderRight(value string) Style {
return s.Set(StBorderRight, value)
}
func (s *styleImpl) SetBorderRight2(width int, style, color string) Style {
return s.SetBorderRight(strconv.Itoa(width) + "px " + style + " " + color)
}
func (s *styleImpl) BorderTop() string {
return s.Get(StBorderTop)
}
func (s *styleImpl) SetBorderTop(value string) Style {
return s.Set(StBorderTop, value)
}
func (s *styleImpl) SetBorderTop2(width int, style, color string) Style {
return s.SetBorderTop(strconv.Itoa(width) + "px " + style + " " + color)
}
func (s *styleImpl) BorderBottom() string {
return s.Get(StBorderBottom)
}
func (s *styleImpl) SetBorderBottom(value string) Style {
return s.Set(StBorderBottom, value)
}
func (s *styleImpl) SetBorderBottom2(width int, style, color string) Style {
return s.SetBorderBottom(strconv.Itoa(width) + "px " + style + " " + color)
}
func (s *styleImpl) Color() string {
return s.Get(StColor)
}
func (s *styleImpl) SetColor(value string) Style {
return s.Set(StColor, value)
}
func (s *styleImpl) Cursor() string {
return s.Get(StCursor)
}
func (s *styleImpl) SetCursor(value string) Style {
return s.Set(StCursor, value)
}
func (s *styleImpl) Display() string {
return s.Get(StDisplay)
}
func (s *styleImpl) SetDisplay(value string) Style {
return s.Set(StDisplay, value)
}
func (s *styleImpl) FontSize() string {
return s.Get(StFontSize)
}
func (s *styleImpl) SetFontSize(value string) Style {
return s.Set(StFontSize, value)
}
func (s *styleImpl) FontStyle() string {
return s.Get(StFontStyle)
}
func (s *styleImpl) SetFontStyle(value string) Style {
return s.Set(StFontStyle, value)
}
func (s *styleImpl) FontWeight() string {
return s.Get(StFontWeight)
}
func (s *styleImpl) SetFontWeight(value string) Style {
return s.Set(StFontWeight, value)
}
func (s *styleImpl) Height() string {
return s.Get(StHeight)
}
func (s *styleImpl) SetHeight(value string) Style {
return s.Set(StHeight, value)
}
func (s *styleImpl) SetHeightPx(height int) Style {
return s.SetHeight(strconv.Itoa(height) + "px")
}
func (s *styleImpl) SetFullHeight() Style {
return s.SetHeight("100%")
}
func (s *styleImpl) Width() string {
return s.Get(StWidth)
}
func (s *styleImpl) SetWidth(value string) Style {
return s.Set(StWidth, value)
}
func (s *styleImpl) SetWidthPx(width int) Style {
return s.SetWidth(strconv.Itoa(width) + "px")
}
func (s *styleImpl) SetFullWidth() Style {
return s.SetWidth("100%")
}
func (s *styleImpl) WhiteSpace() string {
return s.Get(StWhiteSpace)
}
func (s *styleImpl) SetWhiteSpace(value string) Style {
return s.Set(StWhiteSpace, value)
}
func (s *styleImpl) render(w Writer) {
s.renderClasses(w)
if s.attrs != nil {
w.Write(strStyle)
s.renderAttrs(w)
w.Write(strQuote)
}
}
func (s *styleImpl) renderClasses(w Writer) {
if len(s.classes) > 0 {
w.Write(strClass)
for i, class := range s.classes {
if i > 0 {
w.Write(strSpace)
}
w.Writes(class)
}
w.Write(strQuote)
}
}
func (s *styleImpl) renderAttrs(w Writer) {
for name, value := range s.attrs {
w.Writes(name)
w.Write(strColon)
w.Writes(value)
w.Write(strSemicol)
}
}