cura 0.0.1
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 +7 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +122 -0
- data/LICENSE +20 -0
- data/README.md +159 -0
- data/Rakefile +42 -0
- data/cura.gemspec +23 -0
- data/examples/box_model/bin/box_model +11 -0
- data/examples/box_model/debug.log +0 -0
- data/examples/box_model/lib/box_model.rb +21 -0
- data/examples/box_model/lib/box_model/application.rb +24 -0
- data/examples/hello_world/bin/hello_world +10 -0
- data/examples/hello_world/lib/hello_world.rb +201 -0
- data/examples/mruby-examples/README.md +10 -0
- data/examples/mruby-examples/include/cura_examples.h +6 -0
- data/examples/mruby-examples/mrbgem.rake +14 -0
- data/examples/mruby-examples/src/gem_init.c +34 -0
- data/examples/mruby-examples/tools/hello_world/hello_world.c +6 -0
- data/examples/todo_list/app.log +9 -0
- data/examples/todo_list/bin/todo_list +26 -0
- data/examples/todo_list/data.db +0 -0
- data/examples/todo_list/debug.log +0 -0
- data/examples/todo_list/lib/todo_list.rb +28 -0
- data/examples/todo_list/lib/todo_list/application.rb +54 -0
- data/examples/todo_list/lib/todo_list/component/header.rb +27 -0
- data/examples/todo_list/lib/todo_list/component/list.rb +50 -0
- data/examples/todo_list/lib/todo_list/component/list_item.rb +28 -0
- data/examples/todo_list/lib/todo_list/component/list_items.rb +97 -0
- data/examples/todo_list/lib/todo_list/component/lists.rb +89 -0
- data/examples/todo_list/lib/todo_list/database.rb +50 -0
- data/examples/todo_list/lib/todo_list/model/list.rb +9 -0
- data/examples/todo_list/lib/todo_list/model/list_item.rb +9 -0
- data/examples/todo_list/profile.html +11354 -0
- data/lib/cura.rb +13 -0
- data/lib/cura/adapter.rb +67 -0
- data/lib/cura/application.rb +245 -0
- data/lib/cura/attributes/has_ancestry.rb +40 -0
- data/lib/cura/attributes/has_application.rb +31 -0
- data/lib/cura/attributes/has_attributes.rb +89 -0
- data/lib/cura/attributes/has_children.rb +113 -0
- data/lib/cura/attributes/has_colors.rb +66 -0
- data/lib/cura/attributes/has_coordinates.rb +49 -0
- data/lib/cura/attributes/has_dimensions.rb +63 -0
- data/lib/cura/attributes/has_events.rb +89 -0
- data/lib/cura/attributes/has_focusability.rb +37 -0
- data/lib/cura/attributes/has_initialize.rb +15 -0
- data/lib/cura/attributes/has_offsets.rb +82 -0
- data/lib/cura/attributes/has_orientation.rb +53 -0
- data/lib/cura/attributes/has_relative_coordinates.rb +39 -0
- data/lib/cura/attributes/has_root.rb +104 -0
- data/lib/cura/attributes/has_side_attributes.rb +95 -0
- data/lib/cura/attributes/has_windows.rb +70 -0
- data/lib/cura/borders.rb +16 -0
- data/lib/cura/color.rb +330 -0
- data/lib/cura/component/base.rb +180 -0
- data/lib/cura/component/button.rb +57 -0
- data/lib/cura/component/group.rb +77 -0
- data/lib/cura/component/label.rb +224 -0
- data/lib/cura/component/listbox.rb +152 -0
- data/lib/cura/component/pack.rb +144 -0
- data/lib/cura/component/scrollbar.rb +184 -0
- data/lib/cura/component/textbox.rb +118 -0
- data/lib/cura/cursor.rb +77 -0
- data/lib/cura/error/base.rb +10 -0
- data/lib/cura/error/invalid_adapter.rb +18 -0
- data/lib/cura/error/invalid_application.rb +18 -0
- data/lib/cura/error/invalid_color.rb +18 -0
- data/lib/cura/error/invalid_component.rb +18 -0
- data/lib/cura/error/invalid_middleware.rb +18 -0
- data/lib/cura/event.rb +38 -0
- data/lib/cura/event/base.rb +108 -0
- data/lib/cura/event/click.rb +14 -0
- data/lib/cura/event/dispatcher.rb +122 -0
- data/lib/cura/event/focus.rb +14 -0
- data/lib/cura/event/handler.rb +74 -0
- data/lib/cura/event/key_down.rb +68 -0
- data/lib/cura/event/middleware/aimer/base.rb +38 -0
- data/lib/cura/event/middleware/aimer/dispatcher_target.rb +24 -0
- data/lib/cura/event/middleware/aimer/mouse_focus.rb +48 -0
- data/lib/cura/event/middleware/aimer/target_option.rb +38 -0
- data/lib/cura/event/middleware/base.rb +21 -0
- data/lib/cura/event/middleware/dispatch.rb +20 -0
- data/lib/cura/event/middleware/translator/base.rb +37 -0
- data/lib/cura/event/middleware/translator/mouse_click.rb +44 -0
- data/lib/cura/event/mouse.rb +34 -0
- data/lib/cura/event/mouse_button.rb +103 -0
- data/lib/cura/event/mouse_wheel_down.rb +14 -0
- data/lib/cura/event/mouse_wheel_up.rb +14 -0
- data/lib/cura/event/resize.rb +17 -0
- data/lib/cura/event/selected.rb +14 -0
- data/lib/cura/event/unfocus.rb +14 -0
- data/lib/cura/focus_controller.rb +89 -0
- data/lib/cura/key.rb +313 -0
- data/lib/cura/margins.rb +16 -0
- data/lib/cura/offsets.rb +91 -0
- data/lib/cura/padding.rb +16 -0
- data/lib/cura/pencil.rb +29 -0
- data/lib/cura/version.rb +6 -0
- data/lib/cura/window.rb +85 -0
- data/spec/cura/attributes/has_ancestry_spec.rb +108 -0
- data/spec/cura/attributes/has_application_spec.rb +59 -0
- data/spec/cura/attributes/has_attributes_spec.rb +75 -0
- data/spec/cura/attributes/has_children_spec.rb +169 -0
- data/spec/cura/attributes/has_colors_spec.rb +20 -0
- data/spec/cura/attributes/has_coordinates_spec.rb +19 -0
- data/spec/cura/attributes/has_dimensions_spec.rb +19 -0
- data/spec/cura/attributes/has_events_spec.rb +18 -0
- data/spec/cura/attributes/has_focusability_spec.rb +58 -0
- data/spec/cura/attributes/has_offsets_spec.rb +18 -0
- data/spec/cura/attributes/has_orientation_spec.rb +102 -0
- data/spec/cura/attributes/has_relative_coordinates_spec.rb +18 -0
- data/spec/cura/attributes/has_side_attributes_spec.rb +19 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/shared_examples_for_attributes.rb +122 -0
- metadata +211 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
if Kernel.respond_to?(:require)
|
2
|
+
require "cura/component/base"
|
3
|
+
|
4
|
+
require "cura/error/invalid_component"
|
5
|
+
end
|
6
|
+
|
7
|
+
module Cura
|
8
|
+
module Attributes
|
9
|
+
|
10
|
+
# Allows an object to have child components.
|
11
|
+
# TODO: Lots of code is the same as HasWindows
|
12
|
+
module HasChildren
|
13
|
+
|
14
|
+
include Enumerable
|
15
|
+
|
16
|
+
def initialize(*arguments)
|
17
|
+
@children = []
|
18
|
+
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
# Traverse the children of this object.
|
23
|
+
#
|
24
|
+
# @return [Array]
|
25
|
+
def each(&block)
|
26
|
+
@children.each(&block)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Get the children of this object.
|
30
|
+
#
|
31
|
+
# @param [Boolean] recursive Determines if the children should be gathered recursively to retrieve all of this object's decendants.
|
32
|
+
# @return [<Component>]
|
33
|
+
def children(recursive=false)
|
34
|
+
if recursive
|
35
|
+
@children.collect { |child| child.respond_to?(:children) ? [child] + child.children(true) : child }.flatten # TODO: Shouldn't flatten?
|
36
|
+
else
|
37
|
+
@children
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Add a child to this group.
|
42
|
+
#
|
43
|
+
# @param [Component] component
|
44
|
+
# @return [Component]
|
45
|
+
def add_child(component)
|
46
|
+
raise TypeError, "component must be a Cura::Component" unless component.is_a?(Component::Base)
|
47
|
+
|
48
|
+
@children << component
|
49
|
+
|
50
|
+
component
|
51
|
+
end
|
52
|
+
|
53
|
+
# Add multiple children to this group.
|
54
|
+
#
|
55
|
+
# @param [<Component>] children
|
56
|
+
# @return [<Component>]
|
57
|
+
def add_children(*children)
|
58
|
+
children.each { |child| add_child(child) }
|
59
|
+
end
|
60
|
+
|
61
|
+
# Remove a child from this object's children at the given index.
|
62
|
+
#
|
63
|
+
# @param [#to_i] index
|
64
|
+
# @return [Component]
|
65
|
+
def delete_child_at(index)
|
66
|
+
@children.delete_at(index.to_i)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Remove a child from this object's children.
|
70
|
+
#
|
71
|
+
# @param [Component] component
|
72
|
+
# @return [Component]
|
73
|
+
def delete_child(component)
|
74
|
+
validate_component(component)
|
75
|
+
|
76
|
+
delete_child_at(@children.index(component))
|
77
|
+
end
|
78
|
+
|
79
|
+
# Remove all children.
|
80
|
+
#
|
81
|
+
# @return [Group]
|
82
|
+
def delete_children
|
83
|
+
|
84
|
+
(0...@children.count).to_a.reverse_each { |index| delete_child_at(index) } # TODO: Why reverse?
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
# Determine if this group has children.
|
89
|
+
#
|
90
|
+
# @return [Boolean]
|
91
|
+
def children?
|
92
|
+
@children.any?
|
93
|
+
end
|
94
|
+
|
95
|
+
protected
|
96
|
+
|
97
|
+
|
98
|
+
def validate_component(component)
|
99
|
+
raise Error::InvalidComponent unless component.is_a?(Component::Base)
|
100
|
+
end
|
101
|
+
|
102
|
+
def update_children
|
103
|
+
children.each(&:update)
|
104
|
+
end
|
105
|
+
|
106
|
+
def draw_children
|
107
|
+
children.each(&:draw)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
if Kernel.respond_to?(:require)
|
2
|
+
require "cura/attributes/has_attributes"
|
3
|
+
|
4
|
+
require "cura/error/invalid_color"
|
5
|
+
|
6
|
+
require "cura/color"
|
7
|
+
end
|
8
|
+
|
9
|
+
module Cura
|
10
|
+
module Attributes
|
11
|
+
|
12
|
+
# Adds the #foreground and #background attributes.
|
13
|
+
# TODO: Should be color and background... HasBackground and HasColor
|
14
|
+
module HasColors
|
15
|
+
|
16
|
+
include HasAttributes
|
17
|
+
|
18
|
+
def initialize(attributes={})
|
19
|
+
@foreground = :inherit unless instance_variable_defined?(:@foreground)
|
20
|
+
@background = :inherit unless instance_variable_defined?(:@background)
|
21
|
+
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
# @method foreground
|
26
|
+
# Get the foreground color of this object.
|
27
|
+
#
|
28
|
+
# @return [Color]
|
29
|
+
|
30
|
+
# @method foreground=(value)
|
31
|
+
# Set the foreground color of this object.
|
32
|
+
#
|
33
|
+
# @param [Color] value
|
34
|
+
# @return [Color]
|
35
|
+
|
36
|
+
attribute(:foreground) { |value| validate_color_attribute(value) }
|
37
|
+
|
38
|
+
# @method background
|
39
|
+
# Get the background color of this object.
|
40
|
+
#
|
41
|
+
# @return [Color]
|
42
|
+
|
43
|
+
# @method background=(value)
|
44
|
+
# Set the background color of this object.
|
45
|
+
#
|
46
|
+
# @param [Color] value
|
47
|
+
# @return [Color]
|
48
|
+
|
49
|
+
attribute(:background) { |value| validate_color_attribute(value) }
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def validate_color_attribute(value)
|
54
|
+
unless value.is_a?(Cura::Color)
|
55
|
+
value = value.to_sym
|
56
|
+
|
57
|
+
raise Error::InvalidColor unless value == :inherit
|
58
|
+
end
|
59
|
+
|
60
|
+
value
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
if Kernel.respond_to?(:require)
|
2
|
+
require "cura/attributes/has_attributes"
|
3
|
+
end
|
4
|
+
|
5
|
+
module Cura
|
6
|
+
module Attributes
|
7
|
+
|
8
|
+
# Adds the `x` and `y` attributes.
|
9
|
+
module HasCoordinates
|
10
|
+
|
11
|
+
include HasAttributes
|
12
|
+
|
13
|
+
def initialize(attributes={})
|
14
|
+
@x = 0 unless instance_variable_defined?(:@x)
|
15
|
+
@y = 0 unless instance_variable_defined?(:@y)
|
16
|
+
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
# @method x
|
21
|
+
# Get the X coordinate of this object.
|
22
|
+
#
|
23
|
+
# @return [Integer]
|
24
|
+
|
25
|
+
# @method x=(value)
|
26
|
+
# Set the X coordinate of this object.
|
27
|
+
#
|
28
|
+
# @param [#to_i] value
|
29
|
+
# @return [Integer]
|
30
|
+
|
31
|
+
attribute(:x) { |value| value.to_i }
|
32
|
+
|
33
|
+
# @method y
|
34
|
+
# Get the Y coordinate of this object.
|
35
|
+
#
|
36
|
+
# @return [Integer]
|
37
|
+
|
38
|
+
# @method y=(value)
|
39
|
+
# Set the Y coordinate of this object.
|
40
|
+
#
|
41
|
+
# @param [#to_i] value
|
42
|
+
# @return [Integer]
|
43
|
+
|
44
|
+
attribute(:y) { |value| value.to_i }
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
if Kernel.respond_to?(:require)
|
2
|
+
require "cura/attributes/has_attributes"
|
3
|
+
end
|
4
|
+
|
5
|
+
module Cura
|
6
|
+
module Attributes
|
7
|
+
|
8
|
+
# Adds the `width` and `height` attributes.
|
9
|
+
module HasDimensions
|
10
|
+
|
11
|
+
include HasAttributes
|
12
|
+
|
13
|
+
def initialize(attributes={})
|
14
|
+
@width = :auto unless instance_variable_defined?(:@width)
|
15
|
+
@height = :auto unless instance_variable_defined?(:@height)
|
16
|
+
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
# @method width
|
21
|
+
# Get the width dimension of this object.
|
22
|
+
#
|
23
|
+
# @param [#to_i] value
|
24
|
+
# @return [Integer]
|
25
|
+
|
26
|
+
# @method width=(value)
|
27
|
+
# Set the width dimension of this object.
|
28
|
+
#
|
29
|
+
# @return [Integer]
|
30
|
+
|
31
|
+
attribute(:width) { |value| validate_size_attribute(value) }
|
32
|
+
|
33
|
+
# @method height
|
34
|
+
# Get the height dimension of this object.
|
35
|
+
#
|
36
|
+
# @return [Integer]
|
37
|
+
|
38
|
+
# @method height=(value)
|
39
|
+
# Set the height dimension of this object.
|
40
|
+
#
|
41
|
+
# @param [#to_i] value
|
42
|
+
# @return [Integer]
|
43
|
+
|
44
|
+
attribute(:height) { |value| validate_size_attribute(value) }
|
45
|
+
|
46
|
+
# Set one or both of the dimensions of this object.
|
47
|
+
# @param [#to_h] options
|
48
|
+
# @option options [#to_i] :width
|
49
|
+
# @option options [#to_i] :height
|
50
|
+
# @return [Object] This object
|
51
|
+
def resize(options)
|
52
|
+
options = options.to_h
|
53
|
+
|
54
|
+
self.width = options[:width] if options.key?(:width)
|
55
|
+
self.height = options[:height] if options.key?(:height)
|
56
|
+
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
if Kernel.respond_to?(:require)
|
2
|
+
require "cura/attributes/has_ancestry"
|
3
|
+
require "cura/event/handler"
|
4
|
+
end
|
5
|
+
|
6
|
+
module Cura
|
7
|
+
module Attributes
|
8
|
+
|
9
|
+
# Adds an `event_handler` attribute as well as `callbacks` and `on_event` class methods.
|
10
|
+
# When subclassed, the callbacks are inherited.
|
11
|
+
# TODO: Rename to HasEventHandler
|
12
|
+
module HasEvents
|
13
|
+
|
14
|
+
# The class methods to be mixed in when included.
|
15
|
+
module ClassMethods
|
16
|
+
|
17
|
+
# The callbacks stored on this class.
|
18
|
+
#
|
19
|
+
# @return [Hash<Symbol,Array<Proc>>]
|
20
|
+
def callbacks
|
21
|
+
@callbacks ||= {}
|
22
|
+
end
|
23
|
+
|
24
|
+
# Store a callback on this class.
|
25
|
+
# Stored callbacks will be registered on the event handler on initialization.
|
26
|
+
#
|
27
|
+
# @param [nil, #to_sym] event_name The event name.
|
28
|
+
# @yield The callback block.
|
29
|
+
# @return [Proc] The callback block.
|
30
|
+
def on_event(event_name=:default, &block)
|
31
|
+
(callbacks[event_name.to_sym] ||= []) << block
|
32
|
+
|
33
|
+
block
|
34
|
+
end
|
35
|
+
|
36
|
+
# Register this classes callbacks onto the subclass, when inherited.
|
37
|
+
def inherited(subclass)
|
38
|
+
callbacks.each do |event_name, blocks|
|
39
|
+
blocks.each do |block|
|
40
|
+
subclass.on_event(event_name, &block)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
class << self
|
48
|
+
|
49
|
+
def included(base)
|
50
|
+
base.send(:extend, ClassMethods)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def initialize(attributes={})
|
56
|
+
@event_handler = Event::Handler.new(self)
|
57
|
+
register_class_callbacks
|
58
|
+
|
59
|
+
super
|
60
|
+
end
|
61
|
+
|
62
|
+
# Get the event handler for this object.
|
63
|
+
#
|
64
|
+
# @return [Event::Handler]
|
65
|
+
attr_reader :event_handler
|
66
|
+
|
67
|
+
# Register a callback for an event to this instance.
|
68
|
+
#
|
69
|
+
# @param [nil, #to_sym] event_name The event name.
|
70
|
+
# @yield The callback block.
|
71
|
+
# @return [Proc] The callback block.
|
72
|
+
def on_event(event_name=:default, *arguments, &block)
|
73
|
+
event_handler.register(event_name, *arguments, &block)
|
74
|
+
end
|
75
|
+
|
76
|
+
protected
|
77
|
+
|
78
|
+
def register_class_callbacks
|
79
|
+
self.class.callbacks.each do |event_name, blocks|
|
80
|
+
blocks.each do |block|
|
81
|
+
@event_handler.register(event_name, &block)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
if Kernel.respond_to?(:require)
|
2
|
+
require "cura/attributes/has_attributes"
|
3
|
+
end
|
4
|
+
|
5
|
+
module Cura
|
6
|
+
module Attributes
|
7
|
+
|
8
|
+
# Adds the `focusable` attribute to objects.
|
9
|
+
module HasFocusability
|
10
|
+
|
11
|
+
include HasAttributes
|
12
|
+
|
13
|
+
def initialize(attributes={})
|
14
|
+
@focusable = false unless instance_variable_defined?(:@focusable)
|
15
|
+
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
# Get whether this object is focusable or not.
|
20
|
+
#
|
21
|
+
# @return [Boolean]
|
22
|
+
def focusable?
|
23
|
+
@focusable
|
24
|
+
end
|
25
|
+
|
26
|
+
# Set whether this object is focusable or not.
|
27
|
+
#
|
28
|
+
# @param [Object] value
|
29
|
+
# @return [Boolean]
|
30
|
+
def focusable=(value)
|
31
|
+
@focusable = !!value
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Cura
|
2
|
+
module Attributes
|
3
|
+
|
4
|
+
# Stops the initialize super chain.
|
5
|
+
# Must be included before any Cura::Attributes modules which define an #initialize method.
|
6
|
+
module HasInitialize
|
7
|
+
|
8
|
+
def initialize(*arguments)
|
9
|
+
# Blank on purpose. Carry on, my wayward son.
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
if Kernel.respond_to?(:require)
|
2
|
+
require "cura/attributes/has_attributes"
|
3
|
+
require "cura/borders"
|
4
|
+
require "cura/margins"
|
5
|
+
require "cura/padding"
|
6
|
+
require "cura/offsets"
|
7
|
+
end
|
8
|
+
|
9
|
+
module Cura
|
10
|
+
module Attributes
|
11
|
+
|
12
|
+
# Adds the `offsets` attribute to objects.
|
13
|
+
module HasOffsets
|
14
|
+
|
15
|
+
include HasAttributes
|
16
|
+
|
17
|
+
# @method border
|
18
|
+
# Get the borders of this object.
|
19
|
+
#
|
20
|
+
# @return [Borders]
|
21
|
+
|
22
|
+
# @method border=(value)
|
23
|
+
# Set the borders of this object.
|
24
|
+
#
|
25
|
+
# @param [Borders, #to_h] value
|
26
|
+
# @return [Borders]
|
27
|
+
|
28
|
+
attribute(:border, type: Borders) { |value, options| validate_offset_attribute(value, options[:type]) }
|
29
|
+
|
30
|
+
# @method margin
|
31
|
+
# Get the margins of this object.
|
32
|
+
#
|
33
|
+
# @return [Margins]
|
34
|
+
|
35
|
+
# @method margin=(value)
|
36
|
+
# Set the margins of this object.
|
37
|
+
#
|
38
|
+
# @param [Margins, #to_h] value
|
39
|
+
# @return [Margins]
|
40
|
+
|
41
|
+
attribute(:margin, type: Margins) { |value, options| validate_offset_attribute(value, options[:type]) }
|
42
|
+
|
43
|
+
# @method padding
|
44
|
+
# Get the padding of this object.
|
45
|
+
#
|
46
|
+
# @return [Padding]
|
47
|
+
|
48
|
+
# @method padding=(value)
|
49
|
+
# Set the padding of this object.
|
50
|
+
#
|
51
|
+
# @param [Padding, #to_h] value
|
52
|
+
# @return [Padding]
|
53
|
+
|
54
|
+
attribute(:padding, type: Padding) { |value, options| validate_offset_attribute(value, options[:type]) }
|
55
|
+
|
56
|
+
def initialize(attributes={})
|
57
|
+
@offsets = Offsets.new(component: self)
|
58
|
+
|
59
|
+
self.margin = attributes[:margin]
|
60
|
+
self.border = attributes[:border]
|
61
|
+
self.padding = attributes[:padding]
|
62
|
+
|
63
|
+
super
|
64
|
+
end
|
65
|
+
|
66
|
+
# Get the offsets of this object.
|
67
|
+
#
|
68
|
+
# @return [Offsets]
|
69
|
+
attr_reader :offsets
|
70
|
+
|
71
|
+
protected
|
72
|
+
|
73
|
+
def validate_offset_attribute(value, type)
|
74
|
+
value ||= {}
|
75
|
+
|
76
|
+
value.is_a?(type) ? value : type.new(value)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|