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
data/lib/cura/margins.rb
CHANGED
data/lib/cura/offsets.rb
CHANGED
@@ -5,59 +5,57 @@ if Kernel.respond_to?(:require)
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module Cura
|
8
|
-
|
9
8
|
# The offsets of a component's drawing area.
|
10
9
|
class Offsets
|
11
|
-
|
12
10
|
include Attributes::HasInitialize
|
13
11
|
include Attributes::HasAttributes
|
14
|
-
|
12
|
+
|
15
13
|
def initialize(attributes={})
|
16
14
|
super
|
17
|
-
|
15
|
+
|
18
16
|
raise ArgumentError, "component must be set" if @component.nil?
|
19
17
|
end
|
20
|
-
|
18
|
+
|
21
19
|
# @method component
|
22
20
|
# Get the component to calculate offsets for.
|
23
21
|
#
|
24
22
|
# @return [Component]
|
25
|
-
|
23
|
+
|
26
24
|
# @method component=(value)
|
27
25
|
# Set the component to calculate offsets for.
|
28
26
|
#
|
29
27
|
# @param [Component] value
|
30
28
|
# @return [Component]
|
31
29
|
attribute(:component) { |value| validate_component(value) }
|
32
|
-
|
30
|
+
|
33
31
|
# Get the top offset from the contents of a component from the top.
|
34
32
|
#
|
35
33
|
# @return [Integer]
|
36
34
|
def top
|
37
35
|
attribute_sum(:top)
|
38
36
|
end
|
39
|
-
|
37
|
+
|
40
38
|
# Get the right offset from the contents of a component from the right.
|
41
39
|
#
|
42
40
|
# @return [Integer]
|
43
41
|
def right
|
44
42
|
attribute_sum(:right)
|
45
43
|
end
|
46
|
-
|
44
|
+
|
47
45
|
# Get the bottom offset from the contents of a component from the bottom.
|
48
46
|
#
|
49
47
|
# @return [Integer]
|
50
48
|
def bottom
|
51
49
|
attribute_sum(:bottom)
|
52
50
|
end
|
53
|
-
|
51
|
+
|
54
52
|
# Get the left offset from the contents of a component from the left.
|
55
53
|
#
|
56
54
|
# @return [Integer]
|
57
55
|
def left
|
58
56
|
attribute_sum(:left)
|
59
57
|
end
|
60
|
-
|
58
|
+
|
61
59
|
# Get the full height of offsets of a component.
|
62
60
|
#
|
63
61
|
# @return [Integer]
|
@@ -65,7 +63,7 @@ module Cura
|
|
65
63
|
# top + bottom
|
66
64
|
attribute_sum(:height)
|
67
65
|
end
|
68
|
-
|
66
|
+
|
69
67
|
# Get the full width of offsets of a component.
|
70
68
|
#
|
71
69
|
# @return [Integer]
|
@@ -73,19 +71,17 @@ module Cura
|
|
73
71
|
# left + right
|
74
72
|
attribute_sum(:width)
|
75
73
|
end
|
76
|
-
|
74
|
+
|
77
75
|
protected
|
78
|
-
|
76
|
+
|
79
77
|
def attribute_sum(method)
|
80
78
|
@component.padding.send(method) + @component.border.send(method) + @component.margin.send(method)
|
81
79
|
end
|
82
|
-
|
80
|
+
|
83
81
|
def validate_component(value)
|
84
82
|
raise TypeError, "value must be a Cura::Component::Base" unless value.is_a?(Cura::Component::Base)
|
85
|
-
|
83
|
+
|
86
84
|
value
|
87
85
|
end
|
88
|
-
|
89
86
|
end
|
90
|
-
|
91
87
|
end
|
data/lib/cura/padding.rb
CHANGED
data/lib/cura/pencil.rb
CHANGED
@@ -1,29 +1,25 @@
|
|
1
1
|
module Cura
|
2
|
-
|
3
2
|
# The tool used for drawing on a surface.
|
4
3
|
class Pencil
|
5
|
-
|
6
4
|
# Draw a point.
|
7
5
|
def draw_point(x, y, color=Cura::Color.black)
|
8
6
|
super
|
9
7
|
end
|
10
|
-
|
8
|
+
|
11
9
|
# Draw a rectangle.
|
12
10
|
# TODO: filled argument
|
13
11
|
def draw_rectangle(x, y, width, height, color=Cura::Color.black)
|
14
12
|
super
|
15
13
|
end
|
16
|
-
|
14
|
+
|
17
15
|
# Draw a single character.
|
18
16
|
def draw_character(x, y, character, foreground=Cura::Color.black, background=Cura::Color.white, bold=false, underline=false)
|
19
17
|
super
|
20
18
|
end
|
21
|
-
|
19
|
+
|
22
20
|
# Draw text.
|
23
21
|
def draw_text(x, y, text, foreground=Cura::Color.black, background=Cura::Color.white, bold=false, underline=false)
|
24
22
|
super
|
25
23
|
end
|
26
|
-
|
27
24
|
end
|
28
|
-
|
29
25
|
end
|
data/lib/cura/version.rb
CHANGED
data/lib/cura/window.rb
CHANGED
@@ -6,41 +6,38 @@ if Kernel.respond_to?(:require)
|
|
6
6
|
require "cura/attributes/has_dimensions"
|
7
7
|
require "cura/attributes/has_events"
|
8
8
|
require "cura/attributes/has_root"
|
9
|
-
|
10
9
|
require "cura/focus_controller"
|
11
10
|
end
|
12
11
|
|
13
12
|
module Cura
|
14
|
-
|
15
13
|
# A window containing a drawing area.
|
16
14
|
class Window
|
17
|
-
|
18
15
|
include Attributes::HasInitialize
|
19
16
|
include Attributes::HasApplication
|
20
17
|
include Attributes::HasCoordinates
|
21
18
|
include Attributes::HasDimensions
|
22
19
|
include Attributes::HasEvents
|
23
20
|
include Attributes::HasRoot
|
24
|
-
|
21
|
+
|
25
22
|
on_event(:key_down) do |event|
|
26
23
|
@focus_controller.index += 1 if event.name == :tab
|
27
24
|
end
|
28
|
-
|
25
|
+
|
29
26
|
def initialize(attributes={})
|
30
27
|
super
|
31
|
-
|
28
|
+
|
32
29
|
@focus_controller = FocusController.new(window: self)
|
33
30
|
end
|
34
|
-
|
31
|
+
|
35
32
|
# Update this window's components.
|
36
33
|
#
|
37
34
|
# @return [Window]
|
38
35
|
def update
|
39
36
|
@root.update
|
40
|
-
|
37
|
+
|
41
38
|
self
|
42
39
|
end
|
43
|
-
|
40
|
+
|
44
41
|
# Draw this window's children.
|
45
42
|
#
|
46
43
|
# @return [Window]
|
@@ -48,38 +45,36 @@ module Cura
|
|
48
45
|
application.adapter.clear
|
49
46
|
@root.draw
|
50
47
|
application.adapter.present
|
51
|
-
|
48
|
+
|
52
49
|
self
|
53
50
|
end
|
54
|
-
|
51
|
+
|
55
52
|
# Show this window.
|
56
53
|
#
|
57
54
|
# @return [Window]
|
58
55
|
def show
|
59
56
|
self # TODO
|
60
57
|
end
|
61
|
-
|
58
|
+
|
62
59
|
# Hide this window.
|
63
60
|
#
|
64
61
|
# @return [Window]
|
65
62
|
def hide
|
66
63
|
self # TODO
|
67
64
|
end
|
68
|
-
|
65
|
+
|
69
66
|
# Return this window's parent.
|
70
67
|
#
|
71
68
|
# @return [Window]
|
72
69
|
def parent # TODO: Needed?
|
73
70
|
@application
|
74
71
|
end
|
75
|
-
|
72
|
+
|
76
73
|
# Instance inspection.
|
77
74
|
#
|
78
75
|
# @return [String]
|
79
76
|
def inspect
|
80
77
|
"#<#{self.class}:0x#{__id__.to_s(16)} application=#{@application.class}:0x#{@application.__id__.to_s(16)}>"
|
81
78
|
end
|
82
|
-
|
83
79
|
end
|
84
|
-
|
85
80
|
end
|
@@ -4,105 +4,105 @@ require "cura/attributes/has_initialize"
|
|
4
4
|
require "cura/attributes/has_ancestry"
|
5
5
|
|
6
6
|
describe Cura::Attributes::HasAncestry do
|
7
|
-
|
7
|
+
|
8
8
|
let(:instance_class) do
|
9
9
|
instance_class = Class.new { attr_accessor :name }
|
10
10
|
instance_class.include(Cura::Attributes::HasInitialize)
|
11
11
|
instance_class.include(Cura::Attributes::HasAncestry)
|
12
|
-
|
12
|
+
|
13
13
|
instance_class
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
let(:instance) { instance_class.new }
|
17
|
-
|
17
|
+
|
18
18
|
describe "#parent" do
|
19
|
-
|
19
|
+
|
20
20
|
it "should be initialized with the correct value" do
|
21
21
|
expect(instance.parent).to eq(nil)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
describe "#parent=" do
|
27
|
-
|
27
|
+
|
28
28
|
let(:parent) { Object.new }
|
29
|
-
|
29
|
+
|
30
30
|
before { instance.parent = parent }
|
31
|
-
|
31
|
+
|
32
32
|
it "should set the attribute correctly" do
|
33
33
|
expect(instance.parent).to eq(parent)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
describe "#parent?" do
|
39
|
-
|
39
|
+
|
40
40
|
context "when the parent is unset" do
|
41
|
-
|
41
|
+
|
42
42
|
it "should return the correct value" do
|
43
43
|
expect(instance.parent?).to eq(false)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
context "when the parent is set" do
|
49
|
-
|
49
|
+
|
50
50
|
before { instance.parent = Object.new }
|
51
|
-
|
51
|
+
|
52
52
|
it "should return the correct value" do
|
53
53
|
expect(instance.parent?).to eq(true)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
describe "#ancestors" do
|
61
|
-
|
61
|
+
|
62
62
|
it "should be initialized with the correct value" do
|
63
63
|
expect(instance.ancestors).to eq([])
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
context "when the parent is unset" do
|
67
|
-
|
67
|
+
|
68
68
|
let(:parent) { Object.new }
|
69
|
-
|
69
|
+
|
70
70
|
before { instance.parent = nil }
|
71
|
-
|
71
|
+
|
72
72
|
it "should return the correct value" do
|
73
73
|
expect(instance.ancestors).to eq([])
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
context "when the parent is set" do
|
79
|
-
|
79
|
+
|
80
80
|
let(:parent) { Object.new }
|
81
|
-
|
81
|
+
|
82
82
|
before { instance.parent = parent }
|
83
|
-
|
83
|
+
|
84
84
|
it "should return the correct value" do
|
85
85
|
expect(instance.ancestors).to eq([parent])
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
context "and the parent has a parent" do
|
89
|
-
|
89
|
+
|
90
90
|
let(:parent) { instance_class.new }
|
91
91
|
let(:grandparent) { Object.new }
|
92
|
-
|
92
|
+
|
93
93
|
before do
|
94
94
|
parent.parent = grandparent
|
95
95
|
instance.parent = parent
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
it "should return the correct value" do
|
99
99
|
expect(instance.ancestors).to eq([parent, grandparent])
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
end
|
@@ -6,54 +6,54 @@ require "cura/adapter"
|
|
6
6
|
require "cura/attributes/has_application"
|
7
7
|
|
8
8
|
describe Cura::Attributes::HasApplication do
|
9
|
-
|
9
|
+
|
10
10
|
let(:instance) do
|
11
11
|
instance_class = Class.new { attr_accessor :name }
|
12
12
|
instance_class.include(Cura::Attributes::HasApplication)
|
13
|
-
|
13
|
+
|
14
14
|
instance_class.new
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
describe "#application" do
|
18
|
-
|
18
|
+
|
19
19
|
it "should be initialized with the correct value" do
|
20
20
|
expect(instance.application).to eq(nil)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
describe "#application=" do
|
26
|
-
|
26
|
+
|
27
27
|
context "when a Cura::Application is passed" do
|
28
|
-
|
28
|
+
|
29
29
|
let(:application) { Cura::Application.new(adapter: Cura::Adapter.new) }
|
30
|
-
|
30
|
+
|
31
31
|
before { instance.application = application }
|
32
|
-
|
32
|
+
|
33
33
|
it "should set the attribute correctly" do
|
34
34
|
expect(instance.application).to eq(application)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
context "when nil is passed" do
|
40
|
-
|
40
|
+
|
41
41
|
before { instance.application = nil }
|
42
|
-
|
42
|
+
|
43
43
|
it "should set the attribute correctly" do
|
44
44
|
expect(instance.application).to eq(nil)
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
context "when an invalid object is passed" do
|
50
|
-
|
50
|
+
|
51
51
|
it "should raise an error" do
|
52
52
|
expect { instance.application = "invalid thing" }.to raise_error(Cura::Error::InvalidApplication)
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
end
|