Sha256: 12fe528ed35c01c338eea2271cf4be85427f7059aa463f63e51b869352ed80cb

Contents?: true

Size: 901 Bytes

Versions: 6

Compression:

Stored size: 901 Bytes

Contents

# frozen_string_literal: true

class Scarpe
  class GlimmerLibUIEditBox < Scarpe::GlimmerLibUIWidget
    attr_reader :text, :height, :width

    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

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

      super
    end

    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

    private

    def style
      styles = {}

      styles[:height] = Dimensions.length(height)
      styles[:width] = Dimensions.length(width)

      styles.compact
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
scarpe-0.4.0 spikes/glibui/edit_box.rb
scarpe-0.3.0 spikes/glibui/edit_box.rb
scarpe-0.2.2 spikes/glibui/edit_box.rb
lacci-0.2.1 lib/scarpe/glibui/edit_box.rb
scarpe-0.2.1 lib/scarpe/glibui/edit_box.rb
scarpe-0.2.0 lib/scarpe/glibui/edit_box.rb