Class: Shoes::Button

Inherits:
Widget show all
Includes:
Log
Defined in:
lacci/lib/shoes/widgets/button.rb

Constant Summary

Constants included from Log

Log::DEFAULT_COMPONENT, Log::DEFAULT_DEBUG_LOG_CONFIG, Log::DEFAULT_LOG_CONFIG

Instance Attribute Summary

Attributes inherited from Widget

#parent

Attributes inherited from Linkable

#linkable_id

Instance Method Summary collapse

Methods included from Log

configure_logger, #log_init, logger

Methods inherited from Widget

#banner, #caption, #destroy, display_properties, display_property, display_property_name?, display_property_names, #display_property_values, #download, dsl_name, #hide, #inscription, #inspect, #method_missing, #respond_to_missing?, #set_parent, #show, #subtitle, #tagline, #title, #toggle, widget_class_by_name

Methods included from Colors

#gray, #rgb, #to_rgb

Methods inherited from Linkable

#bind_shoes_event, #send_self_event, #send_shoes_event, #unsub_shoes_event

Constructor Details

#initialize(text, width: nil, height: nil, top: nil, left: nil, color: nil, padding_top: nil, padding_bottom: nil, size: 12, text_color: nil, font_size: nil, &block) ⇒ Button

Returns a new instance of Button.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lacci/lib/shoes/widgets/button.rb', line 8

def initialize(text, width: nil, height: nil, top: nil, left: nil, color: nil, padding_top: nil, padding_bottom: nil, size: 12, text_color: nil,
  font_size: nil, & block)

  log_init("Button")

  # Properties passed as positional args, not keywords, don't get auto-set
  @text = text
  @color = color

  @block = block

  super

  # Bind to a handler named "click"
  bind_self_event("click") do
    @log.debug("Button clicked, calling handler") if @block
    @block&.call
  end

  create_display_widget
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Shoes::Widget

Instance Method Details

#click(&block) ⇒ Object

Set the click handler



31
32
33
# File 'lacci/lib/shoes/widgets/button.rb', line 31

def click(&block)
  @block = block
end