Class: Scarpe::WebviewEditBox

Inherits:
WebviewWidget show all
Defined in:
lib/scarpe/wv/edit_box.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 collapse

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, #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) ⇒ WebviewEditBox



7
8
9
10
11
12
13
14
# File 'lib/scarpe/wv/edit_box.rb', line 7

def initialize(properties)
  super

  # The JS handler sends a "change" event, which we forward to the Shoes widget tree
  bind("change") do |new_text|
    send_self_event(new_text, event_name: "change")
  end
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



5
6
7
# File 'lib/scarpe/wv/edit_box.rb', line 5

def height
  @height
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/scarpe/wv/edit_box.rb', line 5

def text
  @text
end

#widthObject (readonly)

Returns the value of attribute width.



5
6
7
# File 'lib/scarpe/wv/edit_box.rb', line 5

def width
  @width
end

Instance Method Details

#elementObject



25
26
27
28
29
30
31
# File 'lib/scarpe/wv/edit_box.rb', line 25

def element
  oninput = handler_js_code("change", "this.value")

  HTML.render do |h|
    h.textarea(id: html_id, oninput: oninput, style: style) { text }
  end
end

#properties_changed(changes) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/scarpe/wv/edit_box.rb', line 16

def properties_changed(changes)
  t = changes.delete("text")
  if t
    html_element.value = t
  end

  super
end

#styleObject (protected)



35
36
37
38
39
40
# File 'lib/scarpe/wv/edit_box.rb', line 35

def style
  super.merge({
    height: Dimensions.length(height),
    width: Dimensions.length(width),
  }.compact)
end