Class: Shoes::Common::UIElement
- Inherits:
-
Object
- Object
- Shoes::Common::UIElement
- Includes:
- Attachable, Inspect, Positioning, Remove, SafelyEvaluate, Style, Visibility
- Defined in:
- shoes-core/lib/shoes/common/ui_element.rb
Direct Known Subclasses
Button, Shoes::CheckButton, ArtElement, BackgroundElement, Image, InputBox, ListBox, Progress, Slot, TextBlock
Constant Summary
Constants included from Style
Style::DEFAULT_STYLES, Style::STYLE_GROUPS
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#dimensions ⇒ Object
readonly
Returns the value of attribute dimensions.
-
#gui ⇒ Object
readonly
Returns the value of attribute gui.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#add_to_parent(*_) ⇒ Object
Calls to add child in parent, after the backend has been created.
-
#after_initialize(*_) ⇒ Object
Final method called in initialize.
-
#before_initialize(_styles, *_) ⇒ Object
This method will get called with the incoming styles hash and the other arguments passed to initialize.
-
#create_backend ⇒ Object
Call to create the backend (aka @gui).
-
#create_dimensions(*_) ⇒ Object
Set the dimensions for the element.
-
#handle_block(blk) ⇒ Object
This method handles the block passed in at creation of the DSL element.
-
#initialize(app, parent, *args) ⇒ UIElement
constructor
A new instance of UIElement.
-
#needs_rotate? ⇒ Boolean
Nobody rotates by default, but we need to let you check.
- #painted? ⇒ Boolean
- #redraw_height ⇒ Object
-
#redraw_left ⇒ Object
Some element types (arrows, shapes) don’t necessarily track their element locations in the standard way.
- #redraw_top ⇒ Object
- #redraw_width ⇒ Object
-
#update_fill ⇒ Object
Expected to be overridden by pulling in Common::Fill or Common::Stroke if element needs to actually notify GUI classes of colors changes.
- #update_stroke ⇒ Object
Methods included from Style
#applicable_app_styles, #create_style_hash, included, #style, #style_init
Methods included from SafelyEvaluate
Methods included from Remove
Methods included from Positioning
Methods included from Visibility
#hidden?, #hidden_from_view?, #hide, #outside_parent_view?, #show, #toggle, #visible?
Methods included from Inspect
Methods included from Attachable
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
#app ⇒ Object (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 |
#dimensions ⇒ Object (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 |
#gui ⇒ Object (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 |
#parent ⇒ Object (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_backend ⇒ Object
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
81 82 83 |
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 81 def needs_rotate? false end |
#painted? ⇒ Boolean
112 113 114 |
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 112 def painted? false end |
#redraw_height ⇒ Object
108 109 110 |
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 108 def redraw_height element_height end |
#redraw_left ⇒ Object
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_top ⇒ Object
100 101 102 |
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 100 def redraw_top element_top end |
#redraw_width ⇒ Object
104 105 106 |
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 104 def redraw_width element_width end |
#update_fill ⇒ Object
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_stroke ⇒ Object
90 91 |
# File 'shoes-core/lib/shoes/common/ui_element.rb', line 90 def update_stroke end |