cura 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +15 -0
  3. data/Gemfile.lock +122 -0
  4. data/LICENSE +20 -0
  5. data/README.md +159 -0
  6. data/Rakefile +42 -0
  7. data/cura.gemspec +23 -0
  8. data/examples/box_model/bin/box_model +11 -0
  9. data/examples/box_model/debug.log +0 -0
  10. data/examples/box_model/lib/box_model.rb +21 -0
  11. data/examples/box_model/lib/box_model/application.rb +24 -0
  12. data/examples/hello_world/bin/hello_world +10 -0
  13. data/examples/hello_world/lib/hello_world.rb +201 -0
  14. data/examples/mruby-examples/README.md +10 -0
  15. data/examples/mruby-examples/include/cura_examples.h +6 -0
  16. data/examples/mruby-examples/mrbgem.rake +14 -0
  17. data/examples/mruby-examples/src/gem_init.c +34 -0
  18. data/examples/mruby-examples/tools/hello_world/hello_world.c +6 -0
  19. data/examples/todo_list/app.log +9 -0
  20. data/examples/todo_list/bin/todo_list +26 -0
  21. data/examples/todo_list/data.db +0 -0
  22. data/examples/todo_list/debug.log +0 -0
  23. data/examples/todo_list/lib/todo_list.rb +28 -0
  24. data/examples/todo_list/lib/todo_list/application.rb +54 -0
  25. data/examples/todo_list/lib/todo_list/component/header.rb +27 -0
  26. data/examples/todo_list/lib/todo_list/component/list.rb +50 -0
  27. data/examples/todo_list/lib/todo_list/component/list_item.rb +28 -0
  28. data/examples/todo_list/lib/todo_list/component/list_items.rb +97 -0
  29. data/examples/todo_list/lib/todo_list/component/lists.rb +89 -0
  30. data/examples/todo_list/lib/todo_list/database.rb +50 -0
  31. data/examples/todo_list/lib/todo_list/model/list.rb +9 -0
  32. data/examples/todo_list/lib/todo_list/model/list_item.rb +9 -0
  33. data/examples/todo_list/profile.html +11354 -0
  34. data/lib/cura.rb +13 -0
  35. data/lib/cura/adapter.rb +67 -0
  36. data/lib/cura/application.rb +245 -0
  37. data/lib/cura/attributes/has_ancestry.rb +40 -0
  38. data/lib/cura/attributes/has_application.rb +31 -0
  39. data/lib/cura/attributes/has_attributes.rb +89 -0
  40. data/lib/cura/attributes/has_children.rb +113 -0
  41. data/lib/cura/attributes/has_colors.rb +66 -0
  42. data/lib/cura/attributes/has_coordinates.rb +49 -0
  43. data/lib/cura/attributes/has_dimensions.rb +63 -0
  44. data/lib/cura/attributes/has_events.rb +89 -0
  45. data/lib/cura/attributes/has_focusability.rb +37 -0
  46. data/lib/cura/attributes/has_initialize.rb +15 -0
  47. data/lib/cura/attributes/has_offsets.rb +82 -0
  48. data/lib/cura/attributes/has_orientation.rb +53 -0
  49. data/lib/cura/attributes/has_relative_coordinates.rb +39 -0
  50. data/lib/cura/attributes/has_root.rb +104 -0
  51. data/lib/cura/attributes/has_side_attributes.rb +95 -0
  52. data/lib/cura/attributes/has_windows.rb +70 -0
  53. data/lib/cura/borders.rb +16 -0
  54. data/lib/cura/color.rb +330 -0
  55. data/lib/cura/component/base.rb +180 -0
  56. data/lib/cura/component/button.rb +57 -0
  57. data/lib/cura/component/group.rb +77 -0
  58. data/lib/cura/component/label.rb +224 -0
  59. data/lib/cura/component/listbox.rb +152 -0
  60. data/lib/cura/component/pack.rb +144 -0
  61. data/lib/cura/component/scrollbar.rb +184 -0
  62. data/lib/cura/component/textbox.rb +118 -0
  63. data/lib/cura/cursor.rb +77 -0
  64. data/lib/cura/error/base.rb +10 -0
  65. data/lib/cura/error/invalid_adapter.rb +18 -0
  66. data/lib/cura/error/invalid_application.rb +18 -0
  67. data/lib/cura/error/invalid_color.rb +18 -0
  68. data/lib/cura/error/invalid_component.rb +18 -0
  69. data/lib/cura/error/invalid_middleware.rb +18 -0
  70. data/lib/cura/event.rb +38 -0
  71. data/lib/cura/event/base.rb +108 -0
  72. data/lib/cura/event/click.rb +14 -0
  73. data/lib/cura/event/dispatcher.rb +122 -0
  74. data/lib/cura/event/focus.rb +14 -0
  75. data/lib/cura/event/handler.rb +74 -0
  76. data/lib/cura/event/key_down.rb +68 -0
  77. data/lib/cura/event/middleware/aimer/base.rb +38 -0
  78. data/lib/cura/event/middleware/aimer/dispatcher_target.rb +24 -0
  79. data/lib/cura/event/middleware/aimer/mouse_focus.rb +48 -0
  80. data/lib/cura/event/middleware/aimer/target_option.rb +38 -0
  81. data/lib/cura/event/middleware/base.rb +21 -0
  82. data/lib/cura/event/middleware/dispatch.rb +20 -0
  83. data/lib/cura/event/middleware/translator/base.rb +37 -0
  84. data/lib/cura/event/middleware/translator/mouse_click.rb +44 -0
  85. data/lib/cura/event/mouse.rb +34 -0
  86. data/lib/cura/event/mouse_button.rb +103 -0
  87. data/lib/cura/event/mouse_wheel_down.rb +14 -0
  88. data/lib/cura/event/mouse_wheel_up.rb +14 -0
  89. data/lib/cura/event/resize.rb +17 -0
  90. data/lib/cura/event/selected.rb +14 -0
  91. data/lib/cura/event/unfocus.rb +14 -0
  92. data/lib/cura/focus_controller.rb +89 -0
  93. data/lib/cura/key.rb +313 -0
  94. data/lib/cura/margins.rb +16 -0
  95. data/lib/cura/offsets.rb +91 -0
  96. data/lib/cura/padding.rb +16 -0
  97. data/lib/cura/pencil.rb +29 -0
  98. data/lib/cura/version.rb +6 -0
  99. data/lib/cura/window.rb +85 -0
  100. data/spec/cura/attributes/has_ancestry_spec.rb +108 -0
  101. data/spec/cura/attributes/has_application_spec.rb +59 -0
  102. data/spec/cura/attributes/has_attributes_spec.rb +75 -0
  103. data/spec/cura/attributes/has_children_spec.rb +169 -0
  104. data/spec/cura/attributes/has_colors_spec.rb +20 -0
  105. data/spec/cura/attributes/has_coordinates_spec.rb +19 -0
  106. data/spec/cura/attributes/has_dimensions_spec.rb +19 -0
  107. data/spec/cura/attributes/has_events_spec.rb +18 -0
  108. data/spec/cura/attributes/has_focusability_spec.rb +58 -0
  109. data/spec/cura/attributes/has_offsets_spec.rb +18 -0
  110. data/spec/cura/attributes/has_orientation_spec.rb +102 -0
  111. data/spec/cura/attributes/has_relative_coordinates_spec.rb +18 -0
  112. data/spec/cura/attributes/has_side_attributes_spec.rb +19 -0
  113. data/spec/spec_helper.rb +12 -0
  114. data/spec/support/shared_examples_for_attributes.rb +122 -0
  115. metadata +211 -0
@@ -0,0 +1,16 @@
1
+ if Kernel.respond_to?(:require)
2
+ require "cura/attributes/has_initialize"
3
+ require "cura/attributes/has_side_attributes"
4
+ end
5
+
6
+ module Cura
7
+
8
+ # The margin side attributes of a component.
9
+ class Margins
10
+
11
+ include Attributes::HasInitialize
12
+ include Attributes::HasSideAttributes
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,91 @@
1
+ if Kernel.respond_to?(:require)
2
+ require "cura/attributes/has_initialize"
3
+ require "cura/attributes/has_attributes"
4
+ require "cura/component/base"
5
+ end
6
+
7
+ module Cura
8
+
9
+ # The offsets of a component's drawing area.
10
+ class Offsets
11
+
12
+ include Attributes::HasInitialize
13
+ include Attributes::HasAttributes
14
+
15
+ def initialize(attributes={})
16
+ super
17
+
18
+ raise ArgumentError, "component must be set" if @component.nil?
19
+ end
20
+
21
+ # @method component
22
+ # Get the component to calculate offsets for.
23
+ #
24
+ # @return [Component]
25
+
26
+ # @method component=(value)
27
+ # Set the component to calculate offsets for.
28
+ #
29
+ # @param [Component] value
30
+ # @return [Component]
31
+ attribute(:component) { |value| validate_component(value) }
32
+
33
+ # Get the top offset from the contents of a component from the top.
34
+ #
35
+ # @return [Integer]
36
+ def top
37
+ attribute_sum(:top)
38
+ end
39
+
40
+ # Get the right offset from the contents of a component from the right.
41
+ #
42
+ # @return [Integer]
43
+ def right
44
+ attribute_sum(:right)
45
+ end
46
+
47
+ # Get the bottom offset from the contents of a component from the bottom.
48
+ #
49
+ # @return [Integer]
50
+ def bottom
51
+ attribute_sum(:bottom)
52
+ end
53
+
54
+ # Get the left offset from the contents of a component from the left.
55
+ #
56
+ # @return [Integer]
57
+ def left
58
+ attribute_sum(:left)
59
+ end
60
+
61
+ # Get the full height of offsets of a component.
62
+ #
63
+ # @return [Integer]
64
+ def height
65
+ # top + bottom
66
+ attribute_sum(:height)
67
+ end
68
+
69
+ # Get the full width of offsets of a component.
70
+ #
71
+ # @return [Integer]
72
+ def width
73
+ # left + right
74
+ attribute_sum(:width)
75
+ end
76
+
77
+ protected
78
+
79
+ def attribute_sum(method)
80
+ @component.padding.send(method) + @component.border.send(method) + @component.margin.send(method)
81
+ end
82
+
83
+ def validate_component(value)
84
+ raise TypeError, "value must be a Cura::Component::Base" unless value.is_a?(Cura::Component::Base)
85
+
86
+ value
87
+ end
88
+
89
+ end
90
+
91
+ end
@@ -0,0 +1,16 @@
1
+ if Kernel.respond_to?(:require)
2
+ require "cura/attributes/has_initialize"
3
+ require "cura/attributes/has_side_attributes"
4
+ end
5
+
6
+ module Cura
7
+
8
+ # The padding side attributes of a component.
9
+ class Padding
10
+
11
+ include Attributes::HasInitialize
12
+ include Attributes::HasSideAttributes
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,29 @@
1
+ module Cura
2
+
3
+ # The tool used for drawing on a surface.
4
+ class Pencil
5
+
6
+ # Draw a point.
7
+ def draw_point(x, y, color=Cura::Color.black)
8
+ super
9
+ end
10
+
11
+ # Draw a rectangle.
12
+ # TODO: filled argument
13
+ def draw_rectangle(x, y, width, height, color=Cura::Color.black)
14
+ super
15
+ end
16
+
17
+ # Draw a single character.
18
+ def draw_character(x, y, character, foreground=Cura::Color.black, background=Cura::Color.white, bold=false, underline=false)
19
+ super
20
+ end
21
+
22
+ # Draw text.
23
+ def draw_text(x, y, text, foreground=Cura::Color.black, background=Cura::Color.white, bold=false, underline=false)
24
+ super
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,6 @@
1
+ # An adaptable component library for creating graphical and text-based user interfaces.
2
+ module Cura
3
+
4
+ VERSION = "0.0.1"
5
+
6
+ end
@@ -0,0 +1,85 @@
1
+ if Kernel.respond_to?(:require)
2
+ require "cura/attributes/has_initialize"
3
+ require "cura/attributes/has_application"
4
+ require "cura/attributes/has_children"
5
+ require "cura/attributes/has_coordinates"
6
+ require "cura/attributes/has_dimensions"
7
+ require "cura/attributes/has_events"
8
+ require "cura/attributes/has_root"
9
+
10
+ require "cura/focus_controller"
11
+ end
12
+
13
+ module Cura
14
+
15
+ # A window containing a drawing area.
16
+ class Window
17
+
18
+ include Attributes::HasInitialize
19
+ include Attributes::HasApplication
20
+ include Attributes::HasCoordinates
21
+ include Attributes::HasDimensions
22
+ include Attributes::HasEvents
23
+ include Attributes::HasRoot
24
+
25
+ on_event(:key_down) do |event|
26
+ @focus_controller.index += 1 if event.name == :tab
27
+ end
28
+
29
+ def initialize(attributes={})
30
+ super
31
+
32
+ @focus_controller = FocusController.new(window: self)
33
+ end
34
+
35
+ # Update this window's components.
36
+ #
37
+ # @return [Window]
38
+ def update
39
+ @root.update
40
+
41
+ self
42
+ end
43
+
44
+ # Draw this window's children.
45
+ #
46
+ # @return [Window]
47
+ def draw
48
+ application.adapter.clear
49
+ @root.draw
50
+ application.adapter.present
51
+
52
+ self
53
+ end
54
+
55
+ # Show this window.
56
+ #
57
+ # @return [Window]
58
+ def show
59
+ self # TODO
60
+ end
61
+
62
+ # Hide this window.
63
+ #
64
+ # @return [Window]
65
+ def hide
66
+ self # TODO
67
+ end
68
+
69
+ # Return this window's parent.
70
+ #
71
+ # @return [Window]
72
+ def parent # TODO: Needed?
73
+ @application
74
+ end
75
+
76
+ # Instance inspection.
77
+ #
78
+ # @return [String]
79
+ def inspect
80
+ "#<#{self.class}:0x#{__id__.to_s(16)} application=#{@application.class}:0x#{@application.__id__.to_s(16)}>"
81
+ end
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,108 @@
1
+ require "spec_helper"
2
+
3
+ require "cura/attributes/has_initialize"
4
+ require "cura/attributes/has_ancestry"
5
+
6
+ describe Cura::Attributes::HasAncestry do
7
+
8
+ let(:instance_class) do
9
+ instance_class = Class.new { attr_accessor :name }
10
+ instance_class.include(Cura::Attributes::HasInitialize)
11
+ instance_class.include(Cura::Attributes::HasAncestry)
12
+
13
+ instance_class
14
+ end
15
+
16
+ let(:instance) { instance_class.new }
17
+
18
+ describe "#parent" do
19
+
20
+ it "should be initialized with the correct value" do
21
+ expect(instance.parent).to eq(nil)
22
+ end
23
+
24
+ end
25
+
26
+ describe "#parent=" do
27
+
28
+ let(:parent) { Object.new }
29
+
30
+ before { instance.parent = parent }
31
+
32
+ it "should set the attribute correctly" do
33
+ expect(instance.parent).to eq(parent)
34
+ end
35
+
36
+ end
37
+
38
+ describe "#parent?" do
39
+
40
+ context "when the parent is unset" do
41
+
42
+ it "should return the correct value" do
43
+ expect(instance.parent?).to eq(false)
44
+ end
45
+
46
+ end
47
+
48
+ context "when the parent is set" do
49
+
50
+ before { instance.parent = Object.new }
51
+
52
+ it "should return the correct value" do
53
+ expect(instance.parent?).to eq(true)
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
60
+ describe "#ancestors" do
61
+
62
+ it "should be initialized with the correct value" do
63
+ expect(instance.ancestors).to eq([])
64
+ end
65
+
66
+ context "when the parent is unset" do
67
+
68
+ let(:parent) { Object.new }
69
+
70
+ before { instance.parent = nil }
71
+
72
+ it "should return the correct value" do
73
+ expect(instance.ancestors).to eq([])
74
+ end
75
+
76
+ end
77
+
78
+ context "when the parent is set" do
79
+
80
+ let(:parent) { Object.new }
81
+
82
+ before { instance.parent = parent }
83
+
84
+ it "should return the correct value" do
85
+ expect(instance.ancestors).to eq([parent])
86
+ end
87
+
88
+ context "and the parent has a parent" do
89
+
90
+ let(:parent) { instance_class.new }
91
+ let(:grandparent) { Object.new }
92
+
93
+ before do
94
+ parent.parent = grandparent
95
+ instance.parent = parent
96
+ end
97
+
98
+ it "should return the correct value" do
99
+ expect(instance.ancestors).to eq([parent, grandparent])
100
+ end
101
+
102
+ end
103
+
104
+ end
105
+
106
+ end
107
+
108
+ end
@@ -0,0 +1,59 @@
1
+ require "spec_helper"
2
+
3
+ require "cura/application"
4
+ require "cura/adapter"
5
+
6
+ require "cura/attributes/has_application"
7
+
8
+ describe Cura::Attributes::HasApplication do
9
+
10
+ let(:instance) do
11
+ instance_class = Class.new { attr_accessor :name }
12
+ instance_class.include(Cura::Attributes::HasApplication)
13
+
14
+ instance_class.new
15
+ end
16
+
17
+ describe "#application" do
18
+
19
+ it "should be initialized with the correct value" do
20
+ expect(instance.application).to eq(nil)
21
+ end
22
+
23
+ end
24
+
25
+ describe "#application=" do
26
+
27
+ context "when a Cura::Application is passed" do
28
+
29
+ let(:application) { Cura::Application.new(adapter: Cura::Adapter.new) }
30
+
31
+ before { instance.application = application }
32
+
33
+ it "should set the attribute correctly" do
34
+ expect(instance.application).to eq(application)
35
+ end
36
+
37
+ end
38
+
39
+ context "when nil is passed" do
40
+
41
+ before { instance.application = nil }
42
+
43
+ it "should set the attribute correctly" do
44
+ expect(instance.application).to eq(nil)
45
+ end
46
+
47
+ end
48
+
49
+ context "when an invalid object is passed" do
50
+
51
+ it "should raise an error" do
52
+ expect { instance.application = "invalid thing" }.to raise_error(Cura::Error::InvalidApplication)
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,75 @@
1
+ require "spec_helper"
2
+
3
+ require "cura/attributes/has_initialize"
4
+ require "cura/attributes/has_attributes"
5
+
6
+ describe Cura::Attributes::HasAttributes do
7
+
8
+ let(:instance_class) do
9
+ instance_class = Class.new { attr_accessor :name }
10
+
11
+ instance_class.include(Cura::Attributes::HasInitialize)
12
+ instance_class.include(Cura::Attributes::HasAttributes)
13
+
14
+ instance_class
15
+ end
16
+
17
+ describe ".attribute" do
18
+ # TODO
19
+ end
20
+
21
+ describe "#initialize" do
22
+
23
+ context "when no arguments are given" do
24
+
25
+ let(:instance) { instance_class.new }
26
+
27
+ it "should do nothing" do
28
+ expect(instance.name).to eq(nil)
29
+ end
30
+
31
+ end
32
+
33
+ context "when an argument is given" do
34
+
35
+ let(:instance) { instance_class.new(name: "test") }
36
+
37
+ it "should set the attribute" do
38
+ expect(instance.name).to eq("test")
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+ describe "#update_attributes" do
46
+
47
+ let(:instance) { instance_class.new }
48
+
49
+ context "when no arguments are given" do
50
+
51
+ before do
52
+ instance.update_attributes
53
+ end
54
+
55
+ it "should do nothing" do
56
+ expect(instance.name).to eq(nil)
57
+ end
58
+
59
+ end
60
+
61
+ context "when an argument is given" do
62
+
63
+ before do
64
+ instance.update_attributes(name: "test")
65
+ end
66
+
67
+ it "should set the attribute" do
68
+ expect(instance.name).to eq("test")
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+ end