Sha256: f4d9d6906816388c77bb0cc870be2243258353923893e7e62e71f5eee4beaa12

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

class Shoes
  class InputBox < Common::UIElement
    include Common::Changeable
    include Common::Focus
    include Common::State

    def before_initialize(styles, text)
      styles[:text] = text.to_s
    end

    def handle_block(blk)
      change(&blk) if blk
      update_visibility
    end

    def text
      @gui.text
    end

    def text=(value)
      style(text: value.to_s)
      @gui.text = value.to_s
    end

    def highlight_text(start_index, final_index)
      @gui.highlight_text(start_index, final_index)
    end

    def caret_to(index)
      @gui.caret_to(index)
    end

    def readonly?
      state.to_s == "readonly"
    end

    def update_from_state
      super
      @gui.readonly = readonly?
    end
  end

  class EditBox < InputBox
    style_with :change, :common_styles, :dimensions, :text, :state
    STYLES = { width: 200, height: 108, text: '' }.freeze
  end

  class EditLine < InputBox
    style_with :change, :common_styles, :dimensions, :text, :secret, :state
    STYLES = { width: 200, height: 28, text: '' }.freeze

    def secret?
      secret
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoes-core-4.0.0.rc1 lib/shoes/input_box.rb