Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop doing Initalization as module #1387

Merged
merged 1 commit into from Feb 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 0 additions & 71 deletions shoes-core/lib/shoes/common/initialization.rb

This file was deleted.

66 changes: 65 additions & 1 deletion shoes-core/lib/shoes/common/ui_element.rb
Expand Up @@ -3,14 +3,78 @@ class Shoes
module Common
class UIElement
include Common::Attachable
include Common::Initialization
include Common::Inspect
include Common::Visibility
include Common::Positioning
include Common::Remove
include DimensionsDelegations
include Common::Style

attr_reader :app, :parent, :dimensions, :gui

def initialize(app, parent, *args)
blk = args.pop if args.last.is_a?(Proc) || args.last.nil?
styles = args.last.is_a?(Hash) ? args.pop : {}

before_initialize(styles, *args)

@app = app
@parent = parent

style_init(styles)
create_dimensions(*args)
update_dimensions if styles_with_dimensions?

create_backend
add_to_parent(*args)

handle_block(blk)
update_visibility

after_initialize(*args)
end

# This method will get called with the incoming styles hash and the
# other arguments passed to initialize.
#
# It is intended for performing any additions to the styles hash before
# that gets sent on to style_init.
def before_initialize(_styles, *_)
end

# Set the dimensions for the element. Defaults to using the Dimensions
# class, but is expected to be overridden in other types (art elements,
# text blocks) that require different dimensioning.
def create_dimensions(*_)
@dimensions = Dimensions.new @parent, @style
end

# Call to create the backend (aka @gui)
def create_backend
@gui = Shoes.backend_for self
end

# Calls to add child in parent, after the backend has been created.
# Can be overridden for operations that must happen after backend, but
# before addition to parent (and hence positioning)
def add_to_parent(*_)
@parent.add_child self
end

# This method handles the block passed in at creation of the DSL element.
# By default it will treat things as clickable, and assumes the
# necessary methods are there.
#
# Override if DSL element uses that block for something else (i.e. slot)
def handle_block(blk)
register_click blk if respond_to?(:register_click)
end

# Final method called in initialize. Intended for any final setup after
# the rest of the object has been set up fully.
def after_initialize(*_)
end

# Nobody rotates by default, but we need to let you check
def needs_rotate?
false
Expand Down
1 change: 0 additions & 1 deletion shoes-core/lib/shoes/dsl.rb
Expand Up @@ -81,7 +81,6 @@ def gem(name)
require 'shoes/common/clickable'
require 'shoes/common/fill'
require 'shoes/common/hover'
require 'shoes/common/initialization'
require 'shoes/common/link_finder'
require 'shoes/common/positioning'
require 'shoes/common/remove'
Expand Down
2 changes: 1 addition & 1 deletion shoes-core/spec/shoes/common/style_spec.rb
Expand Up @@ -20,7 +20,7 @@ def initialize(app, styles = {})
@app = app # needed for style init
@dimensions = Shoes::Dimensions.new(@app, left: 15)

# Would normally be done by Common::Initialization
# Would normally be done by UIElement#initialize
style_init(styles, key: 'value')
update_dimensions
end
Expand Down
2 changes: 1 addition & 1 deletion shoes-core/spec/shoes/common/ui_element_spec.rb
Expand Up @@ -8,7 +8,7 @@

let(:test_class) do
Class.new(Shoes::Common::UIElement) do
# Override UIElement's Initialization include for simpler testing
# Override UIElement's initialize for simpler testing
def initialize
end
end
Expand Down