whirled_peas 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +315 -43
- data/Rakefile +8 -18
- data/lib/whirled_peas/graphics.rb +14 -0
- data/lib/whirled_peas/graphics/box_painter.rb +39 -46
- data/lib/whirled_peas/graphics/canvas.rb +22 -11
- data/lib/whirled_peas/graphics/container_coords.rb +6 -5
- data/lib/whirled_peas/graphics/container_dimensions.rb +26 -8
- data/lib/whirled_peas/graphics/container_painter.rb +42 -4
- data/lib/whirled_peas/graphics/grid_painter.rb +11 -10
- data/lib/whirled_peas/graphics/painter.rb +5 -1
- data/lib/whirled_peas/graphics/renderer.rb +6 -1
- data/lib/whirled_peas/graphics/text_painter.rb +2 -2
- data/lib/whirled_peas/settings/alignment.rb +24 -0
- data/lib/whirled_peas/settings/bg_color.rb +2 -0
- data/lib/whirled_peas/settings/border.rb +16 -16
- data/lib/whirled_peas/settings/color.rb +13 -14
- data/lib/whirled_peas/settings/container_settings.rb +126 -42
- data/lib/whirled_peas/settings/display_flow.rb +13 -11
- data/lib/whirled_peas/settings/element_settings.rb +3 -3
- data/lib/whirled_peas/settings/grid_settings.rb +5 -1
- data/lib/whirled_peas/settings/sizing.rb +19 -0
- data/lib/whirled_peas/settings/spacing.rb +34 -0
- data/lib/whirled_peas/settings/text_color.rb +2 -0
- data/lib/whirled_peas/settings/vert_alignment.rb +24 -0
- data/lib/whirled_peas/utils/title_font.rb +1 -1
- data/lib/whirled_peas/version.rb +1 -1
- data/screen_test/{rendered/elements → elements}/box.frame +1 -1
- data/screen_test/{rendered/elements → elements}/box.rb +0 -0
- data/screen_test/elements/grid.frame +1 -0
- data/screen_test/{rendered/elements → elements}/grid.rb +0 -0
- data/screen_test/elements/screen_overflow_x.frame +1 -0
- data/screen_test/{rendered/elements/screen_overflow.rb → elements/screen_overflow_x.rb} +0 -0
- data/screen_test/elements/screen_overflow_y.frame +1 -0
- data/screen_test/elements/screen_overflow_y.rb +9 -0
- data/screen_test/elements/text.frame +1 -0
- data/screen_test/{rendered/elements → elements}/text.rb +0 -0
- data/screen_test/elements/text_multiline.frame +1 -0
- data/screen_test/{rendered/elements → elements}/text_multiline.rb +0 -0
- data/screen_test/settings/align/box_around.frame +1 -0
- data/screen_test/settings/align/box_around.rb +16 -0
- data/screen_test/settings/align/box_between.frame +1 -0
- data/screen_test/settings/align/box_between.rb +16 -0
- data/screen_test/settings/align/box_center.frame +1 -0
- data/screen_test/{rendered/settings/align/grid.rb → settings/align/box_center.rb} +7 -6
- data/screen_test/settings/align/box_default.frame +1 -0
- data/screen_test/settings/align/box_default.rb +20 -0
- data/screen_test/settings/align/box_evenly.frame +1 -0
- data/screen_test/settings/align/box_evenly.rb +16 -0
- data/screen_test/settings/align/box_left.frame +1 -0
- data/screen_test/settings/align/box_left.rb +21 -0
- data/screen_test/settings/align/box_right.frame +1 -0
- data/screen_test/settings/align/box_right.rb +21 -0
- data/screen_test/settings/align/children_center.frame +1 -0
- data/screen_test/settings/align/children_center.rb +15 -0
- data/screen_test/settings/align/children_left.frame +1 -0
- data/screen_test/settings/align/children_left.rb +15 -0
- data/screen_test/settings/align/children_right.frame +1 -0
- data/screen_test/settings/align/children_right.rb +15 -0
- data/screen_test/settings/align/grid_center.frame +1 -0
- data/screen_test/settings/align/grid_center.rb +18 -0
- data/screen_test/settings/align/grid_default.frame +1 -0
- data/screen_test/settings/align/grid_default.rb +17 -0
- data/screen_test/settings/align/grid_left.frame +1 -0
- data/screen_test/settings/align/grid_left.rb +18 -0
- data/screen_test/settings/align/grid_right.frame +1 -0
- data/screen_test/settings/align/grid_right.rb +18 -0
- data/screen_test/settings/ansi/bold.frame +1 -0
- data/screen_test/{rendered/settings/height/overflow_box_t2b.rb → settings/ansi/bold.rb} +4 -4
- data/screen_test/{rendered/settings → settings}/ansi/color.frame +1 -1
- data/screen_test/{rendered/settings → settings}/ansi/color.rb +0 -0
- data/screen_test/settings/ansi/underline.frame +1 -0
- data/screen_test/{rendered/settings → settings}/ansi/underline.rb +4 -5
- data/screen_test/{rendered/settings → settings}/border.frame +1 -1
- data/screen_test/{rendered/settings → settings}/border.rb +1 -1
- data/screen_test/settings/flow/box_b2t.frame +1 -0
- data/screen_test/settings/flow/box_b2t.rb +26 -0
- data/screen_test/settings/flow/box_l2r.frame +1 -0
- data/screen_test/settings/flow/box_l2r.rb +26 -0
- data/screen_test/settings/flow/box_r2l.frame +1 -0
- data/screen_test/settings/flow/box_r2l.rb +26 -0
- data/screen_test/settings/flow/box_t2b.frame +1 -0
- data/screen_test/settings/flow/box_t2b.rb +26 -0
- data/screen_test/settings/flow/grid_b2t.frame +1 -0
- data/screen_test/{rendered/settings → settings}/flow/grid_b2t.rb +0 -0
- data/screen_test/settings/flow/grid_l2r.frame +1 -0
- data/screen_test/{rendered/settings → settings}/flow/grid_l2r.rb +0 -0
- data/screen_test/settings/flow/grid_r2l.frame +1 -0
- data/screen_test/{rendered/settings → settings}/flow/grid_r2l.rb +0 -0
- data/screen_test/settings/flow/grid_t2b.frame +1 -0
- data/screen_test/{rendered/settings → settings}/flow/grid_t2b.rb +0 -0
- data/screen_test/settings/height/box.frame +1 -0
- data/screen_test/{rendered/settings → settings}/height/box.rb +0 -0
- data/screen_test/settings/height/box_border_sizing.frame +1 -0
- data/screen_test/settings/height/box_border_sizing.rb +15 -0
- data/screen_test/settings/height/grid.frame +1 -0
- data/screen_test/{rendered/settings → settings}/height/grid.rb +0 -0
- data/screen_test/settings/height/overflow_box.frame +1 -0
- data/screen_test/settings/height/overflow_box.rb +13 -0
- data/screen_test/settings/height/overflow_box_l2r.frame +1 -0
- data/screen_test/settings/height/overflow_box_l2r.rb +17 -0
- data/screen_test/settings/height/overflow_box_t2b.frame +1 -0
- data/screen_test/settings/height/overflow_box_t2b.rb +16 -0
- data/screen_test/settings/height/overflow_grid.frame +1 -0
- data/screen_test/{rendered/settings → settings}/height/overflow_grid.rb +0 -0
- data/screen_test/settings/margin.frame +1 -0
- data/screen_test/settings/margin.rb +16 -0
- data/screen_test/settings/padding.frame +1 -0
- data/screen_test/settings/padding.rb +13 -0
- data/screen_test/settings/position/box_left.frame +1 -0
- data/screen_test/{rendered/settings → settings}/position/box_left.rb +2 -2
- data/screen_test/settings/position/box_left_negative.frame +1 -0
- data/screen_test/{rendered/settings → settings}/position/box_left_negative.rb +2 -2
- data/screen_test/settings/position/box_top.frame +1 -0
- data/screen_test/{rendered/settings → settings}/position/box_top.rb +1 -1
- data/screen_test/settings/position/box_top_negative.frame +1 -0
- data/screen_test/{rendered/settings → settings}/position/box_top_negative.rb +2 -2
- data/screen_test/settings/position/grid_left.frame +1 -0
- data/screen_test/{rendered/settings → settings}/position/grid_left.rb +1 -1
- data/screen_test/settings/position/grid_left_negative.frame +1 -0
- data/screen_test/{rendered/settings → settings}/position/grid_left_negative.rb +1 -1
- data/screen_test/settings/position/grid_top.frame +1 -0
- data/screen_test/{rendered/settings → settings}/position/grid_top.rb +1 -1
- data/screen_test/settings/position/grid_top_negative.frame +1 -0
- data/screen_test/{rendered/settings → settings}/position/grid_top_negative.rb +1 -1
- data/screen_test/settings/scroll/horiz_box.frame +1 -0
- data/screen_test/settings/scroll/horiz_box.rb +17 -0
- data/screen_test/settings/scroll/horiz_box_align_center.rb +18 -0
- data/screen_test/settings/scroll/horiz_box_align_right.rb +18 -0
- data/screen_test/settings/scroll/vert_box.frame +1 -0
- data/screen_test/settings/scroll/vert_box.rb +20 -0
- data/screen_test/settings/title_font.frame +1 -0
- data/screen_test/{rendered/settings → settings}/title_font.rb +1 -1
- data/screen_test/settings/valign/box_around.frame +1 -0
- data/screen_test/settings/valign/box_around.rb +17 -0
- data/screen_test/settings/valign/box_between.frame +1 -0
- data/screen_test/settings/valign/box_between.rb +17 -0
- data/screen_test/settings/valign/box_bottom.frame +1 -0
- data/screen_test/settings/valign/box_bottom.rb +17 -0
- data/screen_test/settings/valign/box_default.frame +1 -0
- data/screen_test/settings/valign/box_default.rb +16 -0
- data/screen_test/settings/valign/box_evenly.frame +1 -0
- data/screen_test/settings/valign/box_evenly.rb +17 -0
- data/screen_test/settings/valign/box_middle.frame +1 -0
- data/screen_test/settings/valign/box_middle.rb +17 -0
- data/screen_test/settings/valign/box_top.frame +1 -0
- data/screen_test/settings/valign/box_top.rb +17 -0
- data/screen_test/settings/valign/grid_bottom.frame +1 -0
- data/screen_test/settings/valign/grid_bottom.rb +15 -0
- data/screen_test/settings/valign/grid_default.frame +1 -0
- data/screen_test/settings/valign/grid_default.rb +14 -0
- data/screen_test/settings/valign/grid_middle.frame +1 -0
- data/screen_test/settings/valign/grid_middle.rb +15 -0
- data/screen_test/settings/valign/grid_top.frame +1 -0
- data/screen_test/settings/valign/grid_top.rb +15 -0
- data/screen_test/settings/width/box_border_sizing.frame +1 -0
- data/screen_test/settings/width/box_border_sizing.rb +15 -0
- data/screen_test/settings/width/box_content.frame +1 -0
- data/screen_test/settings/width/box_content.rb +15 -0
- data/screen_test/settings/width/box_default.frame +1 -0
- data/screen_test/{rendered/settings/width/box.rb → settings/width/box_default.rb} +3 -2
- data/screen_test/settings/width/grid.frame +1 -0
- data/screen_test/{rendered/settings → settings}/width/grid.rb +2 -2
- data/screen_test/settings/width/overflow_align_center.frame +1 -0
- data/screen_test/settings/width/overflow_align_center.rb +14 -0
- data/screen_test/settings/width/overflow_align_right.frame +1 -0
- data/screen_test/settings/width/overflow_align_right.rb +14 -0
- data/screen_test/settings/width/overflow_box.frame +1 -0
- data/screen_test/settings/width/overflow_box.rb +13 -0
- data/screen_test/settings/width/overflow_box_l2r.frame +1 -0
- data/screen_test/settings/width/overflow_box_l2r.rb +16 -0
- data/screen_test/settings/width/overflow_box_t2b.frame +1 -0
- data/screen_test/settings/width/overflow_box_t2b.rb +17 -0
- data/screen_test/settings/width/overflow_grid.frame +1 -0
- data/screen_test/{rendered/settings → settings}/width/overflow_grid.rb +0 -0
- data/tools/whirled_peas/tools/screen_tester.rb +233 -0
- metadata +154 -98
- data/lib/whirled_peas/settings/text_align.rb +0 -19
- data/screen_test/rendered/elements/grid.frame +0 -1
- data/screen_test/rendered/elements/screen_overflow.frame +0 -1
- data/screen_test/rendered/elements/text.frame +0 -1
- data/screen_test/rendered/elements/text_multiline.frame +0 -1
- data/screen_test/rendered/settings/align/box.frame +0 -1
- data/screen_test/rendered/settings/align/box.rb +0 -24
- data/screen_test/rendered/settings/align/children_center.frame +0 -1
- data/screen_test/rendered/settings/align/children_center.rb +0 -13
- data/screen_test/rendered/settings/align/children_left.frame +0 -1
- data/screen_test/rendered/settings/align/children_left.rb +0 -13
- data/screen_test/rendered/settings/align/children_right.frame +0 -1
- data/screen_test/rendered/settings/align/children_right.rb +0 -13
- data/screen_test/rendered/settings/align/grid.frame +0 -1
- data/screen_test/rendered/settings/ansi/bold.frame +0 -1
- data/screen_test/rendered/settings/ansi/bold.rb +0 -15
- data/screen_test/rendered/settings/ansi/underline.frame +0 -1
- data/screen_test/rendered/settings/flow/box_b2t.frame +0 -1
- data/screen_test/rendered/settings/flow/box_b2t.rb +0 -24
- data/screen_test/rendered/settings/flow/box_l2r.frame +0 -1
- data/screen_test/rendered/settings/flow/box_l2r.rb +0 -24
- data/screen_test/rendered/settings/flow/box_r2l.frame +0 -1
- data/screen_test/rendered/settings/flow/box_r2l.rb +0 -24
- data/screen_test/rendered/settings/flow/box_t2b.frame +0 -1
- data/screen_test/rendered/settings/flow/box_t2b.rb +0 -24
- data/screen_test/rendered/settings/flow/grid_b2t.frame +0 -1
- data/screen_test/rendered/settings/flow/grid_l2r.frame +0 -1
- data/screen_test/rendered/settings/flow/grid_r2l.frame +0 -1
- data/screen_test/rendered/settings/flow/grid_t2b.frame +0 -1
- data/screen_test/rendered/settings/height/box.frame +0 -1
- data/screen_test/rendered/settings/height/grid.frame +0 -1
- data/screen_test/rendered/settings/height/overflow_box.frame +0 -1
- data/screen_test/rendered/settings/height/overflow_box.rb +0 -13
- data/screen_test/rendered/settings/height/overflow_box_l2r.frame +0 -1
- data/screen_test/rendered/settings/height/overflow_box_l2r.rb +0 -15
- data/screen_test/rendered/settings/height/overflow_box_t2b.frame +0 -1
- data/screen_test/rendered/settings/height/overflow_grid.frame +0 -1
- data/screen_test/rendered/settings/margin.frame +0 -1
- data/screen_test/rendered/settings/margin.rb +0 -14
- data/screen_test/rendered/settings/padding.frame +0 -1
- data/screen_test/rendered/settings/padding.rb +0 -11
- data/screen_test/rendered/settings/position/box_left.frame +0 -1
- data/screen_test/rendered/settings/position/box_left_negative.frame +0 -1
- data/screen_test/rendered/settings/position/box_top.frame +0 -1
- data/screen_test/rendered/settings/position/box_top_negative.frame +0 -1
- data/screen_test/rendered/settings/position/grid_left.frame +0 -1
- data/screen_test/rendered/settings/position/grid_left_negative.frame +0 -1
- data/screen_test/rendered/settings/position/grid_top.frame +0 -1
- data/screen_test/rendered/settings/position/grid_top_negative.frame +0 -1
- data/screen_test/rendered/settings/scroll/horiz_box.frame +0 -1
- data/screen_test/rendered/settings/scroll/horiz_box.rb +0 -15
- data/screen_test/rendered/settings/scroll/vert_box.frame +0 -1
- data/screen_test/rendered/settings/scroll/vert_box.rb +0 -18
- data/screen_test/rendered/settings/title_font.frame +0 -1
- data/screen_test/rendered/settings/width/box.frame +0 -1
- data/screen_test/rendered/settings/width/grid.frame +0 -1
- data/screen_test/rendered/settings/width/overflow_box.frame +0 -1
- data/screen_test/rendered/settings/width/overflow_box.rb +0 -11
- data/screen_test/rendered/settings/width/overflow_box_l2r.frame +0 -1
- data/screen_test/rendered/settings/width/overflow_box_l2r.rb +0 -14
- data/screen_test/rendered/settings/width/overflow_box_t2b.frame +0 -1
- data/screen_test/rendered/settings/width/overflow_box_t2b.rb +0 -15
- data/screen_test/rendered/settings/width/overflow_grid.frame +0 -1
- data/screen_test/screen_tester.rb +0 -201
@@ -8,11 +8,15 @@ module WhirledPeas
|
|
8
8
|
@name = name
|
9
9
|
end
|
10
10
|
|
11
|
-
def paint(canvas, &block)
|
11
|
+
def paint(canvas, left, top, &block)
|
12
12
|
end
|
13
13
|
|
14
14
|
def dimensions
|
15
15
|
end
|
16
|
+
|
17
|
+
def inspect
|
18
|
+
"#{self.class.name.split('::').last}(name=#{name.inspect})"
|
19
|
+
end
|
16
20
|
end
|
17
21
|
private_constant :Painter
|
18
22
|
end
|
@@ -10,7 +10,12 @@ module WhirledPeas
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def paint(&block)
|
13
|
-
template
|
13
|
+
# Modify the template's settings so that it fills the entire screen
|
14
|
+
template.settings.width = width
|
15
|
+
template.settings.height = height
|
16
|
+
template.settings.sizing = :border
|
17
|
+
template.settings.set_margin(left: 0, top: 0, right: 0, bottom: 0)
|
18
|
+
template.paint(Canvas.new(0, 0, width, height), 0, 0, &block)
|
14
19
|
end
|
15
20
|
|
16
21
|
private
|
@@ -9,7 +9,7 @@ module WhirledPeas
|
|
9
9
|
class TextPainter < Painter
|
10
10
|
attr_reader :content
|
11
11
|
|
12
|
-
def paint(canvas, &block)
|
12
|
+
def paint(canvas, left, top, &block)
|
13
13
|
return unless canvas.writable?
|
14
14
|
formatting = [*settings.color, *settings.bg_color]
|
15
15
|
formatting << Utils::Ansi::BOLD if settings.bold?
|
@@ -17,7 +17,7 @@ module WhirledPeas
|
|
17
17
|
formatting << Utils::Ansi::UNDERLINE
|
18
18
|
end
|
19
19
|
content.each.with_index do |line, index|
|
20
|
-
canvas.stroke(
|
20
|
+
canvas.stroke(left, top + index, line, formatting, &block)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module WhirledPeas
|
2
|
+
module Settings
|
3
|
+
module Alignment
|
4
|
+
LEFT = :left
|
5
|
+
CENTER = :center
|
6
|
+
RIGHT = :right
|
7
|
+
BETWEEN = :between
|
8
|
+
AROUND = :around
|
9
|
+
EVENLY = :evenly
|
10
|
+
|
11
|
+
DEFAULT = LEFT
|
12
|
+
|
13
|
+
VALID = [LEFT, CENTER, RIGHT, BETWEEN, AROUND, EVENLY]
|
14
|
+
private_constant :VALID
|
15
|
+
|
16
|
+
def self.validate!(align)
|
17
|
+
return if align.nil?
|
18
|
+
return align if VALID.include?(align)
|
19
|
+
raise ArgumentError, "Unsupported alignment: #{align.inspect}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
private_constant :Alignment
|
23
|
+
end
|
24
|
+
end
|
@@ -34,20 +34,20 @@ module WhirledPeas
|
|
34
34
|
'╚', '═', '╩', '╝'
|
35
35
|
)
|
36
36
|
|
37
|
+
DEFAULT = BOLD
|
38
|
+
|
37
39
|
def self.validate!(style)
|
38
|
-
return
|
40
|
+
return if style.nil?
|
41
|
+
return style if style.is_a?(Border::Style)
|
39
42
|
if style.is_a?(Symbol)
|
40
|
-
|
41
|
-
|
42
|
-
style = self.const_get(style.upcase)
|
43
|
-
raise ArgumentError, error_message unless style.is_a?(Style)
|
44
|
-
style
|
45
|
-
rescue NameError
|
46
|
-
raise ArgumentError, error_message
|
47
|
-
end
|
48
|
-
else
|
49
|
-
style
|
43
|
+
style_class = self.const_get(style.upcase)
|
44
|
+
return style_class if style_class.is_a?(Border::Style)
|
50
45
|
end
|
46
|
+
error_message = "Unsupported border style: #{style.inspect}"
|
47
|
+
raise ArgumentError, error_message
|
48
|
+
rescue NameError
|
49
|
+
error_message = "Unsupported border style: #{style.inspect}"
|
50
|
+
raise ArgumentError, error_message
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -82,20 +82,20 @@ module WhirledPeas
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def style
|
85
|
-
@style || Styles::
|
85
|
+
@style || Styles::DEFAULT
|
86
86
|
end
|
87
87
|
|
88
88
|
def style=(val)
|
89
89
|
@style = Styles.validate!(val)
|
90
90
|
end
|
91
91
|
|
92
|
-
def color
|
93
|
-
@color || TextColor::WHITE
|
94
|
-
end
|
95
|
-
|
96
92
|
def color=(val)
|
97
93
|
@color = TextColor.validate!(val)
|
98
94
|
end
|
95
|
+
|
96
|
+
def color
|
97
|
+
@color || TextColor::DEFAULT
|
98
|
+
end
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -13,25 +13,24 @@ module WhirledPeas
|
|
13
13
|
# @return [Color|Symbol] the value passed in if valid, otherwise an ArgumentError
|
14
14
|
# is raised.
|
15
15
|
def self.validate!(color)
|
16
|
-
return
|
16
|
+
return if color.nil?
|
17
|
+
return color if color.is_a?(self)
|
17
18
|
if color.is_a?(Symbol)
|
18
|
-
error_message = "Unsupported #{self.name.split('::').last}: #{color.inspect}"
|
19
19
|
match = color.to_s.match(/^(bright_)?(\w+)$/)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
else
|
27
|
-
color
|
20
|
+
color_class = self.const_get(match[2].upcase)
|
21
|
+
if color_class.is_a?(self)
|
22
|
+
if !match[1]
|
23
|
+
return color_class
|
24
|
+
elsif !color_class.bright?
|
25
|
+
return color_class.bright
|
28
26
|
end
|
29
|
-
rescue NameError
|
30
|
-
raise ArgumentError, error_message
|
31
27
|
end
|
32
|
-
else
|
33
|
-
color
|
34
28
|
end
|
29
|
+
error_message = "Unsupported #{self.name.split('::').last}: #{color.inspect}"
|
30
|
+
raise ArgumentError, error_message
|
31
|
+
rescue NameError
|
32
|
+
error_message = "Unsupported #{self.name.split('::').last}: #{color.inspect}"
|
33
|
+
raise ArgumentError, error_message
|
35
34
|
end
|
36
35
|
|
37
36
|
def initialize(code, bright=false)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require_relative 'alignment'
|
1
2
|
require_relative 'border'
|
2
3
|
require_relative 'display_flow'
|
3
4
|
require_relative 'element_settings'
|
@@ -5,6 +6,8 @@ require_relative 'margin'
|
|
5
6
|
require_relative 'padding'
|
6
7
|
require_relative 'position'
|
7
8
|
require_relative 'scrollbar'
|
9
|
+
require_relative 'sizing'
|
10
|
+
require_relative 'vert_alignment'
|
8
11
|
|
9
12
|
module WhirledPeas
|
10
13
|
module Settings
|
@@ -12,37 +15,80 @@ module WhirledPeas
|
|
12
15
|
attr_accessor :width, :height
|
13
16
|
|
14
17
|
def align
|
15
|
-
@_align ||
|
18
|
+
@_align || Alignment::DEFAULT
|
16
19
|
end
|
17
20
|
|
18
21
|
def align_left?
|
19
|
-
align ==
|
22
|
+
align == Alignment::LEFT
|
20
23
|
end
|
21
24
|
|
22
25
|
def align_center?
|
23
|
-
align ==
|
26
|
+
align == Alignment::CENTER
|
24
27
|
end
|
25
28
|
|
26
29
|
def align_right?
|
27
|
-
align ==
|
30
|
+
align == Alignment::RIGHT
|
31
|
+
end
|
32
|
+
|
33
|
+
def align_between?
|
34
|
+
align == Alignment::BETWEEN
|
35
|
+
end
|
36
|
+
|
37
|
+
def align_around?
|
38
|
+
align == Alignment::AROUND
|
39
|
+
end
|
40
|
+
|
41
|
+
def align_evenly?
|
42
|
+
align == Alignment::EVENLY
|
28
43
|
end
|
29
44
|
|
30
45
|
def align=(align)
|
31
|
-
@_align =
|
46
|
+
@_align = Alignment.validate!(align)
|
47
|
+
end
|
48
|
+
|
49
|
+
def valign
|
50
|
+
@_valign || VertAlignment::DEFAULT
|
51
|
+
end
|
52
|
+
|
53
|
+
def valign_top?
|
54
|
+
valign == VertAlignment::TOP
|
55
|
+
end
|
56
|
+
|
57
|
+
def valign_middle?
|
58
|
+
valign == VertAlignment::MIDDLE
|
59
|
+
end
|
60
|
+
|
61
|
+
def valign_bottom?
|
62
|
+
valign == VertAlignment::BOTTOM
|
63
|
+
end
|
64
|
+
|
65
|
+
def valign_between?
|
66
|
+
valign == VertAlignment::BETWEEN
|
67
|
+
end
|
68
|
+
|
69
|
+
def valign_around?
|
70
|
+
valign == VertAlignment::AROUND
|
71
|
+
end
|
72
|
+
|
73
|
+
def valign_evenly?
|
74
|
+
valign == VertAlignment::EVENLY
|
75
|
+
end
|
76
|
+
|
77
|
+
def valign=(valign)
|
78
|
+
@_valign = VertAlignment.validate!(valign)
|
32
79
|
end
|
33
80
|
|
34
81
|
def set_border(
|
35
82
|
left: nil, top: nil, right: nil, bottom: nil, inner_horiz: nil, inner_vert: nil, style: nil, color: nil
|
36
83
|
)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@_border.color = color unless color.nil?
|
84
|
+
border.left = left unless left.nil?
|
85
|
+
border.top = top unless top.nil?
|
86
|
+
border.right = right unless right.nil?
|
87
|
+
border.bottom = bottom unless bottom.nil?
|
88
|
+
border.inner_horiz = inner_horiz unless inner_horiz.nil?
|
89
|
+
border.inner_vert = inner_vert unless inner_vert.nil?
|
90
|
+
border.style = style unless style.nil?
|
91
|
+
border.color = color unless color.nil?
|
46
92
|
end
|
47
93
|
|
48
94
|
def full_border(style: nil, color: nil)
|
@@ -52,7 +98,7 @@ module WhirledPeas
|
|
52
98
|
end
|
53
99
|
|
54
100
|
def border
|
55
|
-
@_border
|
101
|
+
@_border ||= Border.new
|
56
102
|
end
|
57
103
|
|
58
104
|
def flow=(flow)
|
@@ -60,7 +106,7 @@ module WhirledPeas
|
|
60
106
|
end
|
61
107
|
|
62
108
|
def flow
|
63
|
-
@_flow || DisplayFlow::
|
109
|
+
@_flow || DisplayFlow::DEFAULT
|
64
110
|
end
|
65
111
|
|
66
112
|
def horizontal_flow?
|
@@ -79,61 +125,99 @@ module WhirledPeas
|
|
79
125
|
!forward_flow?
|
80
126
|
end
|
81
127
|
|
82
|
-
def set_margin(left: nil, top: nil, right: nil, bottom: nil)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
128
|
+
def set_margin(left: nil, top: nil, right: nil, bottom: nil, horiz: nil, vert: nil)
|
129
|
+
if horiz && (left || right)
|
130
|
+
raise ArgumentError, 'Cannot set horizontal margin when setting left/right'
|
131
|
+
elsif vert && (top || bottom)
|
132
|
+
raise ArgumentError, 'Cannot set vertical margin when setting top/bottom'
|
133
|
+
end
|
134
|
+
|
135
|
+
if horiz
|
136
|
+
margin.horiz = horiz
|
137
|
+
else
|
138
|
+
margin.left = left if left
|
139
|
+
margin.right = right if right
|
140
|
+
end
|
141
|
+
|
142
|
+
if vert
|
143
|
+
margin.vert = vert
|
144
|
+
else
|
145
|
+
margin.top = top if top
|
146
|
+
margin.bottom = bottom if bottom
|
147
|
+
end
|
88
148
|
end
|
89
149
|
|
90
150
|
def margin
|
91
|
-
@_margin
|
151
|
+
@_margin ||= Margin.new
|
92
152
|
end
|
93
153
|
|
94
|
-
def set_padding(left: nil, top: nil, right: nil, bottom: nil)
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
154
|
+
def set_padding(left: nil, top: nil, right: nil, bottom: nil, horiz: nil, vert: nil)
|
155
|
+
if horiz && (left || right)
|
156
|
+
raise ArgumentError, 'Cannot set horizontal padding when setting left/right'
|
157
|
+
elsif vert && (top || bottom)
|
158
|
+
raise ArgumentError, 'Cannot set vertical padding when setting top/bottom'
|
159
|
+
end
|
160
|
+
|
161
|
+
if horiz
|
162
|
+
padding.horiz = horiz
|
163
|
+
else
|
164
|
+
padding.left = left if left
|
165
|
+
padding.right = right if right
|
166
|
+
end
|
167
|
+
|
168
|
+
if vert
|
169
|
+
padding.vert = vert
|
170
|
+
else
|
171
|
+
padding.top = top if top
|
172
|
+
padding.bottom = bottom if bottom
|
173
|
+
end
|
100
174
|
end
|
101
175
|
|
102
176
|
def padding
|
103
|
-
@_padding
|
177
|
+
@_padding ||= Padding.new
|
104
178
|
end
|
105
179
|
|
106
180
|
def set_position(left: nil, top: nil)
|
107
|
-
|
108
|
-
|
109
|
-
@_position.top = top if top
|
181
|
+
position.left = left if left
|
182
|
+
position.top = top if top
|
110
183
|
end
|
111
184
|
|
112
185
|
def position
|
113
|
-
@_position
|
186
|
+
@_position ||= Position.new
|
114
187
|
end
|
115
188
|
|
116
189
|
def set_scrollbar(horiz: nil, vert: nil)
|
117
|
-
|
118
|
-
|
119
|
-
@_scrollbar.vert = vert unless vert.nil?
|
190
|
+
scrollbar.horiz = horiz unless horiz.nil?
|
191
|
+
scrollbar.vert = vert unless vert.nil?
|
120
192
|
end
|
121
193
|
|
122
194
|
def scrollbar
|
123
|
-
@_scrollbar
|
195
|
+
@_scrollbar ||= Scrollbar.new
|
196
|
+
end
|
197
|
+
|
198
|
+
def sizing
|
199
|
+
@_sizing || Sizing::DEFAULT
|
200
|
+
end
|
201
|
+
|
202
|
+
def border_sizing?
|
203
|
+
@_sizing == Sizing::BORDER
|
204
|
+
end
|
205
|
+
|
206
|
+
def content_sizing?
|
207
|
+
@_sizing == Sizing::CONTENT
|
208
|
+
end
|
209
|
+
|
210
|
+
def sizing=(sizing)
|
211
|
+
@_sizing = Sizing.validate!(sizing)
|
124
212
|
end
|
125
213
|
|
126
214
|
def inherit(parent)
|
127
215
|
super
|
128
216
|
return unless parent.is_a?(ContainerSettings)
|
129
|
-
@_align = parent._align
|
130
|
-
@_flow = parent._flow
|
131
217
|
set_border(color: parent.border.color, style: parent.border.style)
|
132
218
|
end
|
133
219
|
|
134
220
|
protected
|
135
|
-
|
136
|
-
attr_accessor :_align, :_flow
|
137
221
|
end
|
138
222
|
end
|
139
223
|
end
|
@@ -6,18 +6,20 @@ module WhirledPeas
|
|
6
6
|
TOP_TO_BOTTOM = :t2b
|
7
7
|
BOTTOM_TO_TOP = :b2t
|
8
8
|
|
9
|
+
DEFAULT = LEFT_TO_RIGHT
|
10
|
+
|
11
|
+
VALID = [
|
12
|
+
DisplayFlow::LEFT_TO_RIGHT,
|
13
|
+
DisplayFlow::RIGHT_TO_LEFT,
|
14
|
+
DisplayFlow::TOP_TO_BOTTOM,
|
15
|
+
DisplayFlow::BOTTOM_TO_TOP
|
16
|
+
]
|
17
|
+
private_constant :VALID
|
18
|
+
|
9
19
|
def self.validate!(flow)
|
10
|
-
return
|
11
|
-
if
|
12
|
-
|
13
|
-
DisplayFlow::RIGHT_TO_LEFT,
|
14
|
-
DisplayFlow::TOP_TO_BOTTOM,
|
15
|
-
DisplayFlow::BOTTOM_TO_TOP
|
16
|
-
].include?(flow)
|
17
|
-
flow
|
18
|
-
else
|
19
|
-
raise ArgumentError, "Unsupported display flow: #{flow}"
|
20
|
-
end
|
20
|
+
return if flow.nil?
|
21
|
+
return flow if VALID.include?(flow)
|
22
|
+
raise ArgumentError, "Unsupported display flow: #{flow.inspect}"
|
21
23
|
end
|
22
24
|
end
|
23
25
|
private_constant :DisplayFlow
|