Class: Scarpe::WebviewButton

Inherits:
WebviewWidget show all
Defined in:
lib/scarpe/wv/button.rb

Constant Summary

Constants included from Shoes::Log

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

Instance Attribute Summary

Attributes inherited from WebviewWidget

#children, #parent, #shoes_linkable_id

Attributes inherited from Shoes::Linkable

#linkable_id

Instance Method Summary collapse

Methods inherited from WebviewWidget

#add_child, #bind, #destroy_self, display_class_for, #handler_js_code, #html_element, #html_id, #inspect, #needs_update!, #promise_update, #properties_changed, #remove_child, #rgb_to_hex, #set_parent, #to_html

Methods included from Shoes::Log

configure_logger, #log_init, logger

Methods inherited from Shoes::Linkable

#bind_shoes_event, #send_self_event, #send_shoes_event, #unsub_shoes_event

Constructor Details

#initialize(properties) ⇒ WebviewButton



5
6
7
8
9
10
11
12
13
# File 'lib/scarpe/wv/button.rb', line 5

def initialize(properties)
  super

  # Bind to display-side handler for "click"
  bind("click") do
    # This will be sent to the bind_self_event in Button
    send_self_event(event_name: "click")
  end
end

Instance Method Details

#elementObject



15
16
17
18
19
20
21
# File 'lib/scarpe/wv/button.rb', line 15

def element
  HTML.render do |h|
    h.button(id: html_id, onclick: handler_js_code("click"), style: style) do
      @text
    end
  end
end

#font_sizeObject (protected)



46
47
48
49
50
# File 'lib/scarpe/wv/button.rb', line 46

def font_size
  font_size = @size.is_a?(Symbol) ? SIZES[@size] : @size

  Dimensions.length(font_size)
end

#styleObject (protected)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/scarpe/wv/button.rb', line 25

def style
  styles = super

  styles[:"background-color"] = @color
  styles[:"padding-top"] = @padding_top
  styles[:"padding-bottom"] = @padding_bottom
  styles[:color] = @text_color
  styles[:width] = Dimensions.length(@width) if @width
  styles[:height] = Dimensions.length(@height) if @height
  styles[:"font-size"] = @font_size

  styles[:top] = Dimensions.length(@top) if @top
  styles[:left] = Dimensions.length(@left) if @left
  styles[:position] = "absolute" if @top || @left
  styles[:"font-size"] = Dimensions.length(font_size) if @size
  styles[:"font-family"] = @font if @font
  styles[:color] = rgb_to_hex(@stroke) if @stroke

  styles
end