cura 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +45 -21
- data/cura.gemspec +1 -1
- data/examples/hello_world/lib/hello_world.rb +10 -10
- data/examples/mruby-examples/mrbgem.rake +5 -6
- data/examples/todo_list/data.db +0 -0
- data/examples/todo_list/lib/todo_list/application.rb +24 -18
- data/lib/cura/adapter.rb +13 -20
- data/lib/cura/application.rb +47 -51
- data/lib/cura/attributes/has_ancestry.rb +4 -8
- data/lib/cura/attributes/has_application.rb +3 -7
- data/lib/cura/attributes/has_attributes.rb +1 -9
- data/lib/cura/attributes/has_children.rb +14 -20
- data/lib/cura/attributes/has_colors.rb +14 -18
- data/lib/cura/attributes/has_coordinates.rb +9 -15
- data/lib/cura/attributes/has_dimensions.rb +12 -18
- data/lib/cura/attributes/has_events.rb +10 -18
- data/lib/cura/attributes/has_focusability.rb +5 -11
- data/lib/cura/attributes/has_initialize.rb +1 -5
- data/lib/cura/attributes/has_offsets.rb +16 -20
- data/lib/cura/attributes/has_orientation.rb +12 -18
- data/lib/cura/attributes/has_relative_coordinates.rb +4 -8
- data/lib/cura/attributes/has_root.rb +18 -22
- data/lib/cura/attributes/has_side_attributes.rb +18 -24
- data/lib/cura/attributes/has_windows.rb +13 -19
- data/lib/cura/borders.rb +0 -4
- data/lib/cura/color.rb +84 -91
- data/lib/cura/component/base.rb +29 -33
- data/lib/cura/component/button.rb +10 -16
- data/lib/cura/component/group.rb +14 -18
- data/lib/cura/component/label.rb +44 -48
- data/lib/cura/component/listbox.rb +24 -28
- data/lib/cura/component/pack.rb +14 -18
- data/lib/cura/component/scrollbar.rb +41 -45
- data/lib/cura/component/textbox.rb +21 -25
- data/lib/cura/cursor.rb +15 -23
- data/lib/cura/error/base.rb +0 -3
- data/lib/cura/error/invalid_adapter.rb +1 -7
- data/lib/cura/error/invalid_application.rb +1 -7
- data/lib/cura/error/invalid_color.rb +1 -7
- data/lib/cura/error/invalid_component.rb +1 -7
- data/lib/cura/error/invalid_middleware.rb +1 -7
- data/lib/cura/event.rb +4 -8
- data/lib/cura/event/base.rb +17 -24
- data/lib/cura/event/click.rb +1 -6
- data/lib/cura/event/dispatcher.rb +20 -26
- data/lib/cura/event/focus.rb +1 -6
- data/lib/cura/event/handler.rb +16 -24
- data/lib/cura/event/key_down.rb +11 -17
- data/lib/cura/event/middleware/aimer/base.rb +4 -10
- data/lib/cura/event/middleware/aimer/dispatcher_target.rb +2 -8
- data/lib/cura/event/middleware/aimer/mouse_focus.rb +6 -11
- data/lib/cura/event/middleware/aimer/target_option.rb +4 -10
- data/lib/cura/event/middleware/base.rb +0 -4
- data/lib/cura/event/middleware/dispatch.rb +0 -4
- data/lib/cura/event/middleware/translator/base.rb +4 -10
- data/lib/cura/event/middleware/translator/mouse_click.rb +4 -8
- data/lib/cura/event/mouse.rb +5 -11
- data/lib/cura/event/mouse_button.rb +21 -27
- data/lib/cura/event/mouse_wheel_down.rb +1 -6
- data/lib/cura/event/mouse_wheel_up.rb +1 -6
- data/lib/cura/event/resize.rb +0 -4
- data/lib/cura/event/selected.rb +1 -6
- data/lib/cura/event/unfocus.rb +1 -6
- data/lib/cura/focus_controller.rb +19 -23
- data/lib/cura/key.rb +277 -283
- data/lib/cura/margins.rb +0 -4
- data/lib/cura/offsets.rb +14 -18
- data/lib/cura/padding.rb +0 -4
- data/lib/cura/pencil.rb +3 -7
- data/lib/cura/version.rb +1 -3
- data/lib/cura/window.rb +11 -16
- data/spec/cura/attributes/has_ancestry_spec.rb +39 -39
- data/spec/cura/attributes/has_application_spec.rb +20 -20
- data/spec/cura/attributes/has_attributes_spec.rb +26 -26
- data/spec/cura/attributes/has_children_spec.rb +54 -54
- data/spec/cura/attributes/has_colors_spec.rb +4 -4
- data/spec/cura/attributes/has_coordinates_spec.rb +4 -4
- data/spec/cura/attributes/has_dimensions_spec.rb +4 -4
- data/spec/cura/attributes/has_events_spec.rb +4 -4
- data/spec/cura/attributes/has_focusability_spec.rb +18 -18
- data/spec/cura/attributes/has_offsets_spec.rb +4 -4
- data/spec/cura/attributes/has_orientation_spec.rb +38 -38
- data/spec/cura/attributes/has_relative_coordinates_spec.rb +4 -4
- data/spec/cura/attributes/has_side_attributes_spec.rb +4 -4
- data/spec/spec_helper.rb +1 -1
- data/spec/support/shared_examples_for_attributes.rb +41 -41
- metadata +1 -1
@@ -1,28 +1,24 @@
|
|
1
|
-
if Kernel.respond_to?(:require)
|
2
|
-
require "cura/attributes/has_attributes"
|
3
|
-
end
|
1
|
+
require "cura/attributes/has_attributes" if Kernel.respond_to?(:require)
|
4
2
|
|
5
3
|
module Cura
|
6
4
|
module Attributes
|
7
|
-
|
8
5
|
# Adds the `focusable` attribute to objects.
|
9
6
|
module HasFocusability
|
10
|
-
|
11
7
|
include HasAttributes
|
12
|
-
|
8
|
+
|
13
9
|
def initialize(attributes={})
|
14
10
|
@focusable = false unless instance_variable_defined?(:@focusable)
|
15
|
-
|
11
|
+
|
16
12
|
super
|
17
13
|
end
|
18
|
-
|
14
|
+
|
19
15
|
# Get whether this object is focusable or not.
|
20
16
|
#
|
21
17
|
# @return [Boolean]
|
22
18
|
def focusable?
|
23
19
|
@focusable
|
24
20
|
end
|
25
|
-
|
21
|
+
|
26
22
|
# Set whether this object is focusable or not.
|
27
23
|
#
|
28
24
|
# @param [Object] value
|
@@ -30,8 +26,6 @@ module Cura
|
|
30
26
|
def focusable=(value)
|
31
27
|
@focusable = !!value
|
32
28
|
end
|
33
|
-
|
34
29
|
end
|
35
|
-
|
36
30
|
end
|
37
31
|
end
|
@@ -1,15 +1,11 @@
|
|
1
1
|
module Cura
|
2
2
|
module Attributes
|
3
|
-
|
4
3
|
# Stops the initialize super chain.
|
5
4
|
# Must be included before any Cura::Attributes modules which define an #initialize method.
|
6
5
|
module HasInitialize
|
7
|
-
|
8
|
-
def initialize(*arguments)
|
6
|
+
def initialize(*_arguments)
|
9
7
|
# Blank on purpose. Carry on, my wayward son.
|
10
8
|
end
|
11
|
-
|
12
9
|
end
|
13
|
-
|
14
10
|
end
|
15
11
|
end
|
@@ -8,75 +8,71 @@ end
|
|
8
8
|
|
9
9
|
module Cura
|
10
10
|
module Attributes
|
11
|
-
|
12
11
|
# Adds the `offsets` attribute to objects.
|
13
12
|
module HasOffsets
|
14
|
-
|
15
13
|
include HasAttributes
|
16
|
-
|
14
|
+
|
17
15
|
# @method border
|
18
16
|
# Get the borders of this object.
|
19
17
|
#
|
20
18
|
# @return [Borders]
|
21
|
-
|
19
|
+
|
22
20
|
# @method border=(value)
|
23
21
|
# Set the borders of this object.
|
24
22
|
#
|
25
23
|
# @param [Borders, #to_h] value
|
26
24
|
# @return [Borders]
|
27
|
-
|
25
|
+
|
28
26
|
attribute(:border, type: Borders) { |value, options| validate_offset_attribute(value, options[:type]) }
|
29
|
-
|
27
|
+
|
30
28
|
# @method margin
|
31
29
|
# Get the margins of this object.
|
32
30
|
#
|
33
31
|
# @return [Margins]
|
34
|
-
|
32
|
+
|
35
33
|
# @method margin=(value)
|
36
34
|
# Set the margins of this object.
|
37
35
|
#
|
38
36
|
# @param [Margins, #to_h] value
|
39
37
|
# @return [Margins]
|
40
|
-
|
38
|
+
|
41
39
|
attribute(:margin, type: Margins) { |value, options| validate_offset_attribute(value, options[:type]) }
|
42
|
-
|
40
|
+
|
43
41
|
# @method padding
|
44
42
|
# Get the padding of this object.
|
45
43
|
#
|
46
44
|
# @return [Padding]
|
47
|
-
|
45
|
+
|
48
46
|
# @method padding=(value)
|
49
47
|
# Set the padding of this object.
|
50
48
|
#
|
51
49
|
# @param [Padding, #to_h] value
|
52
50
|
# @return [Padding]
|
53
|
-
|
51
|
+
|
54
52
|
attribute(:padding, type: Padding) { |value, options| validate_offset_attribute(value, options[:type]) }
|
55
|
-
|
53
|
+
|
56
54
|
def initialize(attributes={})
|
57
55
|
@offsets = Offsets.new(component: self)
|
58
|
-
|
56
|
+
|
59
57
|
self.margin = attributes[:margin]
|
60
58
|
self.border = attributes[:border]
|
61
59
|
self.padding = attributes[:padding]
|
62
|
-
|
60
|
+
|
63
61
|
super
|
64
62
|
end
|
65
|
-
|
63
|
+
|
66
64
|
# Get the offsets of this object.
|
67
65
|
#
|
68
66
|
# @return [Offsets]
|
69
67
|
attr_reader :offsets
|
70
|
-
|
68
|
+
|
71
69
|
protected
|
72
|
-
|
70
|
+
|
73
71
|
def validate_offset_attribute(value, type)
|
74
72
|
value ||= {}
|
75
|
-
|
73
|
+
|
76
74
|
value.is_a?(type) ? value : type.new(value)
|
77
75
|
end
|
78
|
-
|
79
76
|
end
|
80
|
-
|
81
77
|
end
|
82
78
|
end
|
@@ -1,53 +1,47 @@
|
|
1
|
-
if Kernel.respond_to?(:require)
|
2
|
-
require "cura/attributes/has_attributes"
|
3
|
-
end
|
1
|
+
require "cura/attributes/has_attributes" if Kernel.respond_to?(:require)
|
4
2
|
|
5
3
|
module Cura
|
6
4
|
module Attributes
|
7
|
-
|
8
5
|
# Adds the `orientation` attribute to objects, which can be :vertical or :horizontal.
|
9
6
|
module HasOrientation
|
10
|
-
|
11
7
|
include HasAttributes
|
12
|
-
|
8
|
+
|
13
9
|
def initialize(attributes={})
|
14
10
|
@orientation = :vertical unless instance_variable_defined?(:@orientation)
|
15
|
-
|
11
|
+
|
16
12
|
super
|
17
13
|
end
|
18
|
-
|
14
|
+
|
19
15
|
# Get the orientation of this object.
|
20
|
-
#
|
16
|
+
#
|
21
17
|
# @return [Symbol]
|
22
18
|
attr_reader :orientation
|
23
|
-
|
19
|
+
|
24
20
|
# Set the orientation of this object.
|
25
21
|
# Must be :vertical or :horizontal.
|
26
|
-
#
|
22
|
+
#
|
27
23
|
# @param [#to_sym] value
|
28
24
|
# @return [Symbol]
|
29
25
|
def orientation=(value)
|
30
26
|
value = value.to_sym
|
31
27
|
raise ArgumentError, "orientation must be one of :vertical or :horizontal" unless [:vertical, :horizontal].include?(value)
|
32
|
-
|
28
|
+
|
33
29
|
@orientation = value
|
34
30
|
end
|
35
|
-
|
31
|
+
|
36
32
|
# Check if this object's orientation is set to :horizontal.
|
37
|
-
#
|
33
|
+
#
|
38
34
|
# @return [Boolean]
|
39
35
|
def horizontal?
|
40
36
|
orientation == :horizontal
|
41
37
|
end
|
42
|
-
|
38
|
+
|
43
39
|
# Check if this object's orientation is set to :vertical.
|
44
|
-
#
|
40
|
+
#
|
45
41
|
# @return [Boolean]
|
46
42
|
def vertical?
|
47
43
|
orientation == :vertical
|
48
44
|
end
|
49
|
-
|
50
45
|
end
|
51
|
-
|
52
46
|
end
|
53
47
|
end
|
@@ -5,35 +5,31 @@ end
|
|
5
5
|
|
6
6
|
module Cura
|
7
7
|
module Attributes
|
8
|
-
|
9
8
|
# Adds the `absolute_x` and `absolute_y` attributes, which are relative to it's parent.
|
10
9
|
module HasRelativeCoordinates
|
11
|
-
|
12
10
|
include HasAncestry
|
13
11
|
include HasCoordinates
|
14
|
-
|
12
|
+
|
15
13
|
def initialize(attributes={})
|
16
14
|
@absolute_x = 0
|
17
15
|
@absolute_y = 0
|
18
|
-
|
16
|
+
|
19
17
|
super
|
20
18
|
end
|
21
|
-
|
19
|
+
|
22
20
|
# Get the absolute X coordinate of this object.
|
23
21
|
#
|
24
22
|
# @return [Integer]
|
25
23
|
def absolute_x
|
26
24
|
parent? && parent.respond_to?(:absolute_x) ? @x + parent.offsets.left + parent.absolute_x : @x
|
27
25
|
end
|
28
|
-
|
26
|
+
|
29
27
|
# Get the absolute Y coordinate of this object.
|
30
28
|
#
|
31
29
|
# @return [Integer]
|
32
30
|
def absolute_y
|
33
31
|
parent? && parent.respond_to?(:absolute_y) ? @y + parent.offsets.top + parent.absolute_y : @y
|
34
32
|
end
|
35
|
-
|
36
33
|
end
|
37
|
-
|
38
34
|
end
|
39
35
|
end
|
@@ -1,45 +1,43 @@
|
|
1
1
|
if Kernel.respond_to?(:require)
|
2
2
|
require "cura/attributes/has_attributes"
|
3
|
-
|
3
|
+
|
4
4
|
require "cura/component/group"
|
5
5
|
end
|
6
6
|
|
7
7
|
module Cura
|
8
8
|
module Attributes
|
9
|
-
|
10
9
|
# Adds the `root` attribute to an object, which defaults to a Component::Group.
|
11
10
|
module HasRoot
|
12
|
-
|
13
11
|
include Attributes::HasAttributes
|
14
|
-
|
12
|
+
|
15
13
|
def initialize(attributes={})
|
16
14
|
@root = Component::Group.new(parent: self)
|
17
|
-
|
15
|
+
|
18
16
|
super
|
19
17
|
end
|
20
|
-
|
18
|
+
|
21
19
|
# @method root
|
22
20
|
# Get root component for this object.
|
23
21
|
#
|
24
22
|
# @return [Component::Group]
|
25
|
-
|
23
|
+
|
26
24
|
# @method root=(component)
|
27
25
|
# Set root component for this object.
|
28
26
|
#
|
29
27
|
# @param [Component::Group] component
|
30
28
|
# @return [Component::Group]
|
31
|
-
|
29
|
+
|
32
30
|
attribute(:root) { |component| set_root(component) }
|
33
|
-
|
31
|
+
|
34
32
|
# Delegates -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
35
|
-
|
33
|
+
|
36
34
|
# Get the children of this object.
|
37
35
|
#
|
38
36
|
# @return [<Component>]
|
39
37
|
def children(recursive=false)
|
40
38
|
@root.children(recursive)
|
41
39
|
end
|
42
|
-
|
40
|
+
|
43
41
|
# Add a child to this object's root component.
|
44
42
|
#
|
45
43
|
# @param [Component] component
|
@@ -47,7 +45,7 @@ module Cura
|
|
47
45
|
def add_child(component)
|
48
46
|
@root.add_child(component)
|
49
47
|
end
|
50
|
-
|
48
|
+
|
51
49
|
# Add multiple children to this object's root component.
|
52
50
|
#
|
53
51
|
# @param [<Component>] children
|
@@ -55,7 +53,7 @@ module Cura
|
|
55
53
|
def add_children(*children)
|
56
54
|
@root.add_children(*children)
|
57
55
|
end
|
58
|
-
|
56
|
+
|
59
57
|
# Remove a child from object's root component at the given index.
|
60
58
|
#
|
61
59
|
# @param [Integer] index
|
@@ -63,7 +61,7 @@ module Cura
|
|
63
61
|
def delete_child_at(index)
|
64
62
|
@root.delete_child_at(index)
|
65
63
|
end
|
66
|
-
|
64
|
+
|
67
65
|
# Remove a child from this object's root component.
|
68
66
|
#
|
69
67
|
# @param [Component] component
|
@@ -71,34 +69,32 @@ module Cura
|
|
71
69
|
def delete_child(component)
|
72
70
|
@root.delete_child(component)
|
73
71
|
end
|
74
|
-
|
72
|
+
|
75
73
|
# Remove all children from object's root component.
|
76
74
|
#
|
77
75
|
# @return [HasChildren]
|
78
76
|
def delete_children
|
79
77
|
@root.delete_children
|
80
78
|
end
|
81
|
-
|
79
|
+
|
82
80
|
# Determine if this object's root component has children.
|
83
81
|
#
|
84
82
|
# @return [Boolean]
|
85
83
|
def children?
|
86
84
|
@root.children?
|
87
85
|
end
|
88
|
-
|
86
|
+
|
89
87
|
protected
|
90
|
-
|
88
|
+
|
91
89
|
def set_root(component)
|
92
90
|
raise TypeError, "root must be a Component::Group" unless component.is_a?(Component::Group)
|
93
|
-
|
91
|
+
|
94
92
|
@root.parent = nil unless @root.nil?
|
95
93
|
@root = component
|
96
94
|
@root.parent = self
|
97
|
-
|
95
|
+
|
98
96
|
@root
|
99
97
|
end
|
100
|
-
|
101
98
|
end
|
102
|
-
|
103
99
|
end
|
104
100
|
end
|
@@ -1,95 +1,89 @@
|
|
1
|
-
if Kernel.respond_to?(:require)
|
2
|
-
require "cura/attributes/has_attributes"
|
3
|
-
end
|
1
|
+
require "cura/attributes/has_attributes" if Kernel.respond_to?(:require)
|
4
2
|
|
5
3
|
module Cura
|
6
4
|
module Attributes
|
7
|
-
|
8
5
|
# Adds the `top`, `right`, `bottom`, `left`, `width`, and `height` attributes to objects.
|
9
6
|
module HasSideAttributes
|
10
|
-
|
11
7
|
include HasAttributes
|
12
|
-
|
8
|
+
|
13
9
|
# @method top
|
14
10
|
# Get the top attribute.
|
15
11
|
#
|
16
12
|
# @return [Integer]
|
17
|
-
|
13
|
+
|
18
14
|
# @method top=(value)
|
19
15
|
# Set the top attribute.
|
20
16
|
#
|
21
17
|
# @param [#to_i] value
|
22
18
|
# @return [Integer]
|
23
|
-
|
19
|
+
|
24
20
|
attribute(:top) { |value| validate_size_attribute(value) }
|
25
|
-
|
21
|
+
|
26
22
|
# @method right
|
27
23
|
# Get the right attribute.
|
28
24
|
#
|
29
25
|
# @return [Integer]
|
30
|
-
|
26
|
+
|
31
27
|
# @method right=(value)
|
32
28
|
# Set the right attribute.
|
33
29
|
#
|
34
30
|
# @param [#to_i] value
|
35
31
|
# @return [Integer]
|
36
|
-
|
32
|
+
|
37
33
|
attribute(:right) { |value| validate_size_attribute(value) }
|
38
|
-
|
34
|
+
|
39
35
|
# @method bottom
|
40
36
|
# Get the bottom attribute.
|
41
37
|
#
|
42
38
|
# @return [Integer]
|
43
|
-
|
39
|
+
|
44
40
|
# @method bottom=(value)
|
45
41
|
# Set the bottom attribute.
|
46
42
|
#
|
47
43
|
# @param [#to_i] value
|
48
44
|
# @return [Integer]
|
49
|
-
|
45
|
+
|
50
46
|
attribute(:bottom) { |value| validate_size_attribute(value) }
|
51
|
-
|
47
|
+
|
52
48
|
# @method left
|
53
49
|
# Get the left attribute.
|
54
50
|
#
|
55
51
|
# @return [Integer]
|
56
|
-
|
52
|
+
|
57
53
|
# @method left=(value)
|
58
54
|
# Set the left attribute.
|
59
55
|
#
|
60
56
|
# @param [#to_i] value
|
61
57
|
# @return [Integer]
|
62
|
-
|
58
|
+
|
63
59
|
attribute(:left) { |value| validate_size_attribute(value) }
|
64
|
-
|
60
|
+
|
65
61
|
def initialize(attributes={})
|
66
62
|
@top = 0 unless instance_variable_defined?(:@top)
|
67
63
|
@right = 0 unless instance_variable_defined?(:@right)
|
68
64
|
@bottom = 0 unless instance_variable_defined?(:@bottom)
|
69
65
|
@left = 0 unless instance_variable_defined?(:@left)
|
70
|
-
|
66
|
+
|
71
67
|
unless attributes.respond_to?(:to_hash) || attributes.respond_to?(:to_h)
|
72
68
|
attributes = { top: attributes, right: attributes, bottom: attributes, left: attributes } # Set all side attributes to the argument given
|
73
69
|
end
|
74
|
-
|
70
|
+
|
75
71
|
super
|
76
72
|
end
|
77
|
-
|
73
|
+
|
78
74
|
# Get the total height of the attributes.
|
79
75
|
#
|
80
76
|
# @return [Integer]
|
81
77
|
def height
|
82
78
|
@top + @bottom
|
83
79
|
end
|
84
|
-
|
80
|
+
|
85
81
|
# Get the total width of the attributes.
|
86
82
|
#
|
87
83
|
# @return [Integer]
|
88
84
|
def width
|
89
85
|
@left + @right
|
90
86
|
end
|
91
|
-
|
92
87
|
end
|
93
|
-
|
94
88
|
end
|
95
89
|
end
|