Class: Shoes::Common::UIElement

Inherits:
Object
  • Object
show all
Includes:
Attachable, Inspect, Positioning, Remove, SafelyEvaluate, Style, Visibility
Defined in:
shoes-core/lib/shoes/common/ui_element.rb

Constant Summary

Constants included from Style

Style::DEFAULT_STYLES, Style::STYLE_GROUPS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Style

#applicable_app_styles, #create_style_hash, included, #style, #style_init

Methods included from SafelyEvaluate

#safely_evaluate

Methods included from Remove

#remove

Methods included from Positioning

#_position, #displace, #move

Methods included from Visibility

#hidden?, #hidden_from_view?, #hide, #outside_parent_view?, #show, #toggle, #visible?

Methods included from Inspect

#inspect, #to_s

Methods included from Attachable

#attached_to

Constructor Details

#initialize(app, parent, *args) ⇒ UIElement

Returns a new instance of UIElement


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 17

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

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app


15
16
17
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 15

def app
  @app
end

#dimensionsObject (readonly)

Returns the value of attribute dimensions


15
16
17
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 15

def dimensions
  @dimensions
end

#guiObject (readonly)

Returns the value of attribute gui


15
16
17
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 15

def gui
  @gui
end

#parentObject (readonly)

Returns the value of attribute parent


15
16
17
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 15

def parent
  @parent
end

Instance Method Details

#add_to_parent(*_) ⇒ Object

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)


62
63
64
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 62

def add_to_parent(*_)
  @parent.add_child self
end

#after_initialize(*_) ⇒ Object

Final method called in initialize. Intended for any final setup after the rest of the object has been set up fully.


77
78
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 77

def after_initialize(*_)
end

#before_initialize(_styles, *_) ⇒ Object

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.


44
45
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 44

def before_initialize(_styles, *_)
end

#create_backendObject

Call to create the backend (aka @gui)


55
56
57
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 55

def create_backend
  @gui = Shoes.backend_for self
end

#create_dimensions(*_) ⇒ Object

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.


50
51
52
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 50

def create_dimensions(*_)
  @dimensions = Dimensions.new @parent, @style
end

#handle_block(blk) ⇒ Object

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)


71
72
73
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 71

def handle_block(blk)
  register_click blk if respond_to?(:register_click)
end

#needs_rotate?Boolean

Nobody rotates by default, but we need to let you check

Returns:

  • (Boolean)

81
82
83
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 81

def needs_rotate?
  false
end

#painted?Boolean

Returns:

  • (Boolean)

112
113
114
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 112

def painted?
  false
end

#redraw_heightObject


108
109
110
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 108

def redraw_height
  element_height
end

#redraw_leftObject

Some element types (arrows, shapes) don't necessarily track their element locations in the standard way. Let them inform redrawing about the actual bounds to redraw within by overriding these methods


96
97
98
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 96

def redraw_left
  element_left
end

#redraw_topObject


100
101
102
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 100

def redraw_top
  element_top
end

#redraw_widthObject


104
105
106
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 104

def redraw_width
  element_width
end

#update_fillObject

Expected to be overridden by pulling in Common::Fill or Common::Stroke if element needs to actually notify GUI classes of colors changes.


87
88
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 87

def update_fill
end

#update_strokeObject


90
91
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 90

def update_stroke
end