Class: Scarpe::WebviewListBox
- Inherits:
-
WebviewWidget
- Object
- Shoes::Linkable
- WebviewWidget
- Scarpe::WebviewListBox
- Defined in:
- lib/scarpe/wv/list_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
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#selected_item ⇒ Object
readonly
Returns the value of attribute selected_item.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Attributes inherited from WebviewWidget
#children, #parent, #shoes_linkable_id
Attributes inherited from Shoes::Linkable
Instance Method Summary collapse
- #element ⇒ Object
-
#initialize(properties) ⇒ WebviewListBox
constructor
A new instance of WebviewListBox.
- #properties_changed(changes) ⇒ Object
- #style ⇒ Object protected
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) ⇒ WebviewListBox
Returns a new instance of WebviewListBox.
7 8 9 10 11 12 13 14 |
# File 'lib/scarpe/wv/list_box.rb', line 7 def initialize(properties) super(properties) # The JS handler sends a "change" event, which we forward to the Shoes widget tree bind("change") do |new_item| send_self_event(new_item, event_name: "change") end end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
5 6 7 |
# File 'lib/scarpe/wv/list_box.rb', line 5 def height @height end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
5 6 7 |
# File 'lib/scarpe/wv/list_box.rb', line 5 def items @items end |
#selected_item ⇒ Object (readonly)
Returns the value of attribute selected_item.
5 6 7 |
# File 'lib/scarpe/wv/list_box.rb', line 5 def selected_item @selected_item end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
5 6 7 |
# File 'lib/scarpe/wv/list_box.rb', line 5 def width @width end |
Instance Method Details
#element ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/scarpe/wv/list_box.rb', line 24 def element onchange = handler_js_code("change", "this.options[this.selectedIndex].value") select_attrs = { id: html_id, onchange: onchange, style: style } option_attrs = { value: nil, selected: false } HTML.render do |h| h.select(**select_attrs) do items.each do |item| h.option(**option_attrs, value: item, selected: (item == selected_item)) { item } end end end end |
#properties_changed(changes) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/scarpe/wv/list_box.rb', line 16 def properties_changed(changes) selected = changes.delete("selected_item") if selected html_element.value = selected end super end |
#style ⇒ Object (protected)
41 42 43 44 45 46 47 48 |
# File 'lib/scarpe/wv/list_box.rb', line 41 def style styles = super styles[:height] = Dimensions.length(height) if height styles[:width] = Dimensions.length(width) if width styles end |