cura 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,26 @@
|
|
1
1
|
module Cura
|
2
2
|
module Attributes
|
3
|
-
|
4
3
|
# Allows an object to have a `parent` and `ancestors`.
|
5
4
|
module HasAncestry
|
6
|
-
|
7
5
|
def initialize(attributes={})
|
8
6
|
@ancestors = []
|
9
|
-
|
7
|
+
|
10
8
|
super
|
11
9
|
end
|
12
|
-
|
10
|
+
|
13
11
|
# Get/set the parent of this object.
|
14
12
|
# It's not recommended to set this directly as it may break the ancestory chain.
|
15
13
|
#
|
16
14
|
# @return [Object]
|
17
15
|
attr_accessor :parent
|
18
|
-
|
16
|
+
|
19
17
|
# Determine if this object has a parent.
|
20
18
|
#
|
21
19
|
# @return [Boolean]
|
22
20
|
def parent?
|
23
21
|
!@parent.nil?
|
24
22
|
end
|
25
|
-
|
23
|
+
|
26
24
|
# Get the ancestors of this object.
|
27
25
|
#
|
28
26
|
# @return [Array<Object>]
|
@@ -33,8 +31,6 @@ module Cura
|
|
33
31
|
@parent.respond_to?(:ancestors) ? [@parent] + @parent.ancestors : [@parent]
|
34
32
|
end
|
35
33
|
end
|
36
|
-
|
37
34
|
end
|
38
|
-
|
39
35
|
end
|
40
36
|
end
|
@@ -1,31 +1,27 @@
|
|
1
1
|
if Kernel.respond_to?(:require)
|
2
2
|
require "cura/application"
|
3
|
-
|
3
|
+
|
4
4
|
require "cura/error/invalid_application"
|
5
5
|
end
|
6
6
|
|
7
7
|
module Cura
|
8
8
|
module Attributes
|
9
|
-
|
10
9
|
# Allows an object to belong to a Cura::Application.
|
11
10
|
module HasApplication
|
12
|
-
|
13
11
|
# Get the application of this object.
|
14
12
|
#
|
15
13
|
# @return [Application]
|
16
14
|
attr_reader :application
|
17
|
-
|
15
|
+
|
18
16
|
# Set the application of this object.
|
19
17
|
#
|
20
18
|
# @param [Application] value
|
21
19
|
# @return [Application]
|
22
20
|
def application=(value)
|
23
21
|
raise Error::InvalidApplication unless value.nil? || value.is_a?(Cura::Application)
|
24
|
-
|
22
|
+
|
25
23
|
@application = value
|
26
24
|
end
|
27
|
-
|
28
25
|
end
|
29
|
-
|
30
26
|
end
|
31
27
|
end
|
@@ -1,12 +1,9 @@
|
|
1
1
|
module Cura
|
2
2
|
module Attributes
|
3
|
-
|
4
3
|
# Adds the `update_attributes` method.
|
5
|
-
module HasAttributes # TODO: Aspect::HasAttributes
|
6
|
-
|
4
|
+
module HasAttributes # TODO: Use Aspect::HasAttributes
|
7
5
|
# The class methods to be mixed in when included.
|
8
6
|
module ClassMethods
|
9
|
-
|
10
7
|
def attribute(name, options={}, &block)
|
11
8
|
options = options.to_h
|
12
9
|
|
@@ -30,15 +27,12 @@ module Cura
|
|
30
27
|
end
|
31
28
|
end
|
32
29
|
end
|
33
|
-
|
34
30
|
end
|
35
31
|
|
36
32
|
class << self
|
37
|
-
|
38
33
|
def included(base)
|
39
34
|
base.extend(ClassMethods)
|
40
35
|
end
|
41
|
-
|
42
36
|
end
|
43
37
|
|
44
38
|
# Initialize this object by optionally updating attributes with a Hash.
|
@@ -82,8 +76,6 @@ module Cura
|
|
82
76
|
def convert_attributes(attributes={})
|
83
77
|
attributes.to_h
|
84
78
|
end
|
85
|
-
|
86
79
|
end
|
87
|
-
|
88
80
|
end
|
89
81
|
end
|
@@ -6,26 +6,24 @@ end
|
|
6
6
|
|
7
7
|
module Cura
|
8
8
|
module Attributes
|
9
|
-
|
10
9
|
# Allows an object to have child components.
|
11
10
|
# TODO: Lots of code is the same as HasWindows
|
12
11
|
module HasChildren
|
13
|
-
|
14
12
|
include Enumerable
|
15
|
-
|
13
|
+
|
16
14
|
def initialize(*arguments)
|
17
15
|
@children = []
|
18
|
-
|
16
|
+
|
19
17
|
super
|
20
18
|
end
|
21
|
-
|
19
|
+
|
22
20
|
# Traverse the children of this object.
|
23
21
|
#
|
24
22
|
# @return [Array]
|
25
23
|
def each(&block)
|
26
24
|
@children.each(&block)
|
27
25
|
end
|
28
|
-
|
26
|
+
|
29
27
|
# Get the children of this object.
|
30
28
|
#
|
31
29
|
# @param [Boolean] recursive Determines if the children should be gathered recursively to retrieve all of this object's decendants.
|
@@ -37,19 +35,19 @@ module Cura
|
|
37
35
|
@children
|
38
36
|
end
|
39
37
|
end
|
40
|
-
|
38
|
+
|
41
39
|
# Add a child to this group.
|
42
40
|
#
|
43
41
|
# @param [Component] component
|
44
42
|
# @return [Component]
|
45
43
|
def add_child(component)
|
46
44
|
raise TypeError, "component must be a Cura::Component" unless component.is_a?(Component::Base)
|
47
|
-
|
45
|
+
|
48
46
|
@children << component
|
49
|
-
|
47
|
+
|
50
48
|
component
|
51
49
|
end
|
52
|
-
|
50
|
+
|
53
51
|
# Add multiple children to this group.
|
54
52
|
#
|
55
53
|
# @param [<Component>] children
|
@@ -57,7 +55,7 @@ module Cura
|
|
57
55
|
def add_children(*children)
|
58
56
|
children.each { |child| add_child(child) }
|
59
57
|
end
|
60
|
-
|
58
|
+
|
61
59
|
# Remove a child from this object's children at the given index.
|
62
60
|
#
|
63
61
|
# @param [#to_i] index
|
@@ -65,7 +63,7 @@ module Cura
|
|
65
63
|
def delete_child_at(index)
|
66
64
|
@children.delete_at(index.to_i)
|
67
65
|
end
|
68
|
-
|
66
|
+
|
69
67
|
# Remove a child from this object's children.
|
70
68
|
#
|
71
69
|
# @param [Component] component
|
@@ -75,25 +73,23 @@ module Cura
|
|
75
73
|
|
76
74
|
delete_child_at(@children.index(component))
|
77
75
|
end
|
78
|
-
|
76
|
+
|
79
77
|
# Remove all children.
|
80
78
|
#
|
81
79
|
# @return [Group]
|
82
80
|
def delete_children
|
83
|
-
|
84
81
|
(0...@children.count).to_a.reverse_each { |index| delete_child_at(index) } # TODO: Why reverse?
|
85
82
|
self
|
86
83
|
end
|
87
|
-
|
84
|
+
|
88
85
|
# Determine if this group has children.
|
89
86
|
#
|
90
87
|
# @return [Boolean]
|
91
88
|
def children?
|
92
89
|
@children.any?
|
93
90
|
end
|
94
|
-
|
91
|
+
|
95
92
|
protected
|
96
|
-
|
97
93
|
|
98
94
|
def validate_component(component)
|
99
95
|
raise Error::InvalidComponent unless component.is_a?(Component::Base)
|
@@ -102,12 +98,10 @@ module Cura
|
|
102
98
|
def update_children
|
103
99
|
children.each(&:update)
|
104
100
|
end
|
105
|
-
|
101
|
+
|
106
102
|
def draw_children
|
107
103
|
children.each(&:draw)
|
108
104
|
end
|
109
|
-
|
110
105
|
end
|
111
|
-
|
112
106
|
end
|
113
107
|
end
|
@@ -1,66 +1,62 @@
|
|
1
1
|
if Kernel.respond_to?(:require)
|
2
2
|
require "cura/attributes/has_attributes"
|
3
|
-
|
3
|
+
|
4
4
|
require "cura/error/invalid_color"
|
5
|
-
|
5
|
+
|
6
6
|
require "cura/color"
|
7
7
|
end
|
8
8
|
|
9
9
|
module Cura
|
10
10
|
module Attributes
|
11
|
-
|
12
11
|
# Adds the #foreground and #background attributes.
|
13
12
|
# TODO: Should be color and background... HasBackground and HasColor
|
14
13
|
module HasColors
|
15
|
-
|
16
14
|
include HasAttributes
|
17
|
-
|
15
|
+
|
18
16
|
def initialize(attributes={})
|
19
17
|
@foreground = :inherit unless instance_variable_defined?(:@foreground)
|
20
18
|
@background = :inherit unless instance_variable_defined?(:@background)
|
21
|
-
|
19
|
+
|
22
20
|
super
|
23
21
|
end
|
24
|
-
|
22
|
+
|
25
23
|
# @method foreground
|
26
24
|
# Get the foreground color of this object.
|
27
25
|
#
|
28
26
|
# @return [Color]
|
29
|
-
|
27
|
+
|
30
28
|
# @method foreground=(value)
|
31
29
|
# Set the foreground color of this object.
|
32
30
|
#
|
33
31
|
# @param [Color] value
|
34
32
|
# @return [Color]
|
35
|
-
|
33
|
+
|
36
34
|
attribute(:foreground) { |value| validate_color_attribute(value) }
|
37
|
-
|
35
|
+
|
38
36
|
# @method background
|
39
37
|
# Get the background color of this object.
|
40
38
|
#
|
41
39
|
# @return [Color]
|
42
|
-
|
40
|
+
|
43
41
|
# @method background=(value)
|
44
42
|
# Set the background color of this object.
|
45
43
|
#
|
46
44
|
# @param [Color] value
|
47
45
|
# @return [Color]
|
48
|
-
|
46
|
+
|
49
47
|
attribute(:background) { |value| validate_color_attribute(value) }
|
50
|
-
|
48
|
+
|
51
49
|
protected
|
52
|
-
|
50
|
+
|
53
51
|
def validate_color_attribute(value)
|
54
52
|
unless value.is_a?(Cura::Color)
|
55
53
|
value = value.to_sym
|
56
|
-
|
54
|
+
|
57
55
|
raise Error::InvalidColor unless value == :inherit
|
58
56
|
end
|
59
|
-
|
57
|
+
|
60
58
|
value
|
61
59
|
end
|
62
|
-
|
63
60
|
end
|
64
|
-
|
65
61
|
end
|
66
62
|
end
|
@@ -1,49 +1,43 @@
|
|
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 `x` and `y` attributes.
|
9
6
|
module HasCoordinates
|
10
|
-
|
11
7
|
include HasAttributes
|
12
|
-
|
8
|
+
|
13
9
|
def initialize(attributes={})
|
14
10
|
@x = 0 unless instance_variable_defined?(:@x)
|
15
11
|
@y = 0 unless instance_variable_defined?(:@y)
|
16
|
-
|
12
|
+
|
17
13
|
super
|
18
14
|
end
|
19
|
-
|
15
|
+
|
20
16
|
# @method x
|
21
17
|
# Get the X coordinate of this object.
|
22
18
|
#
|
23
19
|
# @return [Integer]
|
24
|
-
|
20
|
+
|
25
21
|
# @method x=(value)
|
26
22
|
# Set the X coordinate of this object.
|
27
23
|
#
|
28
24
|
# @param [#to_i] value
|
29
25
|
# @return [Integer]
|
30
|
-
|
26
|
+
|
31
27
|
attribute(:x) { |value| value.to_i }
|
32
|
-
|
28
|
+
|
33
29
|
# @method y
|
34
30
|
# Get the Y coordinate of this object.
|
35
31
|
#
|
36
32
|
# @return [Integer]
|
37
|
-
|
33
|
+
|
38
34
|
# @method y=(value)
|
39
35
|
# Set the Y coordinate of this object.
|
40
36
|
#
|
41
37
|
# @param [#to_i] value
|
42
38
|
# @return [Integer]
|
43
|
-
|
39
|
+
|
44
40
|
attribute(:y) { |value| value.to_i }
|
45
|
-
|
46
41
|
end
|
47
|
-
|
48
42
|
end
|
49
43
|
end
|
@@ -1,48 +1,44 @@
|
|
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 `width` and `height` attributes.
|
9
6
|
module HasDimensions
|
10
|
-
|
11
7
|
include HasAttributes
|
12
|
-
|
8
|
+
|
13
9
|
def initialize(attributes={})
|
14
10
|
@width = :auto unless instance_variable_defined?(:@width)
|
15
11
|
@height = :auto unless instance_variable_defined?(:@height)
|
16
|
-
|
12
|
+
|
17
13
|
super
|
18
14
|
end
|
19
|
-
|
15
|
+
|
20
16
|
# @method width
|
21
17
|
# Get the width dimension of this object.
|
22
18
|
#
|
23
19
|
# @param [#to_i] value
|
24
20
|
# @return [Integer]
|
25
|
-
|
21
|
+
|
26
22
|
# @method width=(value)
|
27
23
|
# Set the width dimension of this object.
|
28
24
|
#
|
29
25
|
# @return [Integer]
|
30
|
-
|
26
|
+
|
31
27
|
attribute(:width) { |value| validate_size_attribute(value) }
|
32
|
-
|
28
|
+
|
33
29
|
# @method height
|
34
30
|
# Get the height dimension of this object.
|
35
31
|
#
|
36
32
|
# @return [Integer]
|
37
|
-
|
33
|
+
|
38
34
|
# @method height=(value)
|
39
35
|
# Set the height dimension of this object.
|
40
36
|
#
|
41
37
|
# @param [#to_i] value
|
42
38
|
# @return [Integer]
|
43
|
-
|
39
|
+
|
44
40
|
attribute(:height) { |value| validate_size_attribute(value) }
|
45
|
-
|
41
|
+
|
46
42
|
# Set one or both of the dimensions of this object.
|
47
43
|
# @param [#to_h] options
|
48
44
|
# @option options [#to_i] :width
|
@@ -50,14 +46,12 @@ module Cura
|
|
50
46
|
# @return [Object] This object
|
51
47
|
def resize(options)
|
52
48
|
options = options.to_h
|
53
|
-
|
49
|
+
|
54
50
|
self.width = options[:width] if options.key?(:width)
|
55
51
|
self.height = options[:height] if options.key?(:height)
|
56
|
-
|
52
|
+
|
57
53
|
self
|
58
54
|
end
|
59
|
-
|
60
55
|
end
|
61
|
-
|
62
56
|
end
|
63
57
|
end
|
@@ -5,22 +5,19 @@ end
|
|
5
5
|
|
6
6
|
module Cura
|
7
7
|
module Attributes
|
8
|
-
|
9
8
|
# Adds an `event_handler` attribute as well as `callbacks` and `on_event` class methods.
|
10
9
|
# When subclassed, the callbacks are inherited.
|
11
10
|
# TODO: Rename to HasEventHandler
|
12
11
|
module HasEvents
|
13
|
-
|
14
12
|
# The class methods to be mixed in when included.
|
15
13
|
module ClassMethods
|
16
|
-
|
17
14
|
# The callbacks stored on this class.
|
18
15
|
#
|
19
16
|
# @return [Hash<Symbol,Array<Proc>>]
|
20
17
|
def callbacks
|
21
18
|
@callbacks ||= {}
|
22
19
|
end
|
23
|
-
|
20
|
+
|
24
21
|
# Store a callback on this class.
|
25
22
|
# Stored callbacks will be registered on the event handler on initialization.
|
26
23
|
#
|
@@ -29,10 +26,10 @@ module Cura
|
|
29
26
|
# @return [Proc] The callback block.
|
30
27
|
def on_event(event_name=:default, &block)
|
31
28
|
(callbacks[event_name.to_sym] ||= []) << block
|
32
|
-
|
29
|
+
|
33
30
|
block
|
34
31
|
end
|
35
|
-
|
32
|
+
|
36
33
|
# Register this classes callbacks onto the subclass, when inherited.
|
37
34
|
def inherited(subclass)
|
38
35
|
callbacks.each do |event_name, blocks|
|
@@ -41,29 +38,26 @@ module Cura
|
|
41
38
|
end
|
42
39
|
end
|
43
40
|
end
|
44
|
-
|
45
41
|
end
|
46
|
-
|
42
|
+
|
47
43
|
class << self
|
48
|
-
|
49
44
|
def included(base)
|
50
45
|
base.send(:extend, ClassMethods)
|
51
46
|
end
|
52
|
-
|
53
47
|
end
|
54
|
-
|
48
|
+
|
55
49
|
def initialize(attributes={})
|
56
50
|
@event_handler = Event::Handler.new(self)
|
57
51
|
register_class_callbacks
|
58
|
-
|
52
|
+
|
59
53
|
super
|
60
54
|
end
|
61
|
-
|
55
|
+
|
62
56
|
# Get the event handler for this object.
|
63
57
|
#
|
64
58
|
# @return [Event::Handler]
|
65
59
|
attr_reader :event_handler
|
66
|
-
|
60
|
+
|
67
61
|
# Register a callback for an event to this instance.
|
68
62
|
#
|
69
63
|
# @param [nil, #to_sym] event_name The event name.
|
@@ -72,9 +66,9 @@ module Cura
|
|
72
66
|
def on_event(event_name=:default, *arguments, &block)
|
73
67
|
event_handler.register(event_name, *arguments, &block)
|
74
68
|
end
|
75
|
-
|
69
|
+
|
76
70
|
protected
|
77
|
-
|
71
|
+
|
78
72
|
def register_class_callbacks
|
79
73
|
self.class.callbacks.each do |event_name, blocks|
|
80
74
|
blocks.each do |block|
|
@@ -82,8 +76,6 @@ module Cura
|
|
82
76
|
end
|
83
77
|
end
|
84
78
|
end
|
85
|
-
|
86
79
|
end
|
87
|
-
|
88
80
|
end
|
89
81
|
end
|