Class: Shoes::Widget
- Inherits:
-
Flow
- Object
- Common::UIElement
- Slot
- Flow
- Shoes::Widget
- Defined in:
- shoes-core/lib/shoes/widget.rb
Overview
This is the superclass for creating custom Shoes widgets.
To use, inherit from Widget and implement a initialize_widget method. You get a few magical effects:
-
When you inherit from Widget, you get a method in your Apps to create your widgets. The method is lower- and snake-cased. It returns an instance of your widget class.
-
Your widgets delegate missing methods to their app object. This allows you to use the Shoes DSL within your widgets.
-
Your widget otherwise behaves like a flow. If the final parameter to the widget method is a Hash, that will initialize the flow as well.
Constant Summary
Constants inherited from Slot
Slot::NEXT_ELEMENT_OFFSET, Slot::STYLES
Constants included from Common::Style
Common::Style::DEFAULT_STYLES, Common::Style::STYLE_GROUPS
Instance Attribute Summary collapse
-
#original_args ⇒ Object
Returns the value of attribute original_args.
Attributes included from Common::Hover
Attributes inherited from Slot
#blk, #contents, #dimensions, #gui, #parent, #scroll_height, #scroll_top
Attributes included from Common::Clickable
Attributes inherited from Common::UIElement
#app, #dimensions, #gui, #parent
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*_) ⇒ Widget
constructor
Having Widget define initialize makes it easier for us to detect whether subclasses have inappropriately overridden it or not.
- #initialize_widget ⇒ Object
- #shoes_base_class ⇒ Object
Methods inherited from Flow
Methods included from Common::Hover
#add_mouse_hover_control, #apply_style_from_hover_class, #apply_style_from_pre_hover, create_hover_class, #eval_hover_block, #hover, #hover_class, #hovered?, #leave, #mouse_hovered, #mouse_left
Methods inherited from Slot
#add_child, #add_mouse_hover_control, #any_sibling_slots_following?, #app, #append, #before_initialize, #bump_current_position, #bump_parent_current_position, #clear, #contents_alignment, #create_bound_block, #create_dimensions, #eval_block, #fixed_height?, #handle_block, #inspect, #prepend, #remove, #remove_child, #scroll_max, #set_default_dimension_values, #slot_grew_by, #snapshot_current_position, #variable_height?
Methods included from Common::Clickable
#click, #pass_coordinates?, #register_click, #release
Methods inherited from Common::UIElement
#add_to_parent, #after_initialize, #before_initialize, #create_backend, #create_dimensions, #handle_block, #needs_rotate?, #painted?, #redraw_height, #redraw_left, #redraw_top, #redraw_width, #update_fill, #update_stroke
Methods included from Common::Style
#applicable_app_styles, #create_style_hash, included, #style, #style_init
Methods included from Common::SafelyEvaluate
Methods included from Common::Remove
Methods included from Common::Positioning
Methods included from Common::Visibility
#hidden?, #hidden_from_view?, #hide, #outside_parent_view?, #show, #toggle, #visible?
Methods included from Common::Inspect
Methods included from Common::Attachable
Constructor Details
#initialize(*_) ⇒ Widget
Having Widget define initialize makes it easier for us to detect whether subclasses have inappropriately overridden it or not.
37 38 39 |
# File 'shoes-core/lib/shoes/widget.rb', line 37 def initialize(*_) super end |
Instance Attribute Details
#original_args ⇒ Object
Returns the value of attribute original_args.
33 34 35 |
# File 'shoes-core/lib/shoes/widget.rb', line 33 def original_args @original_args end |
Class Method Details
.dsl_method_name(klass) ⇒ Object
75 76 77 78 79 |
# File 'shoes-core/lib/shoes/widget.rb', line 75 def self.dsl_method_name(klass) klass.to_s[/(^|::)(\w+)$/, 2] .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase end |
.warn_about_initialize ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'shoes-core/lib/shoes/widget.rb', line 81 def self.warn_about_initialize return if instance_method(:initialize).owner == Shoes::Widget Shoes.logger.warn <<~EOS You've defined an `initialize` method on class '#{self}'. This is no longer supported. Your widget likely won't display, and you'll potentially receive argument errors. Instead, define `initialize_widget` and we'll call it from your generated widget method. EOS end |
Instance Method Details
#initialize_widget ⇒ Object
41 42 43 |
# File 'shoes-core/lib/shoes/widget.rb', line 41 def # Expected to be overridden by children but not guaranteed end |