class Cura::Component::Textbox

A component containing editable text.

Attributes

mask_character[R]

Get the mask character for this textbox.

@return [String]

Public Class Methods

new(attributes={}) click to toggle source
Calls superclass method Cura::Component::Label::new
# File lib/cura/component/textbox.rb, line 34
def initialize(attributes={})
  @focusable = true
  @foreground = Cura::Color.black
  @background = Cura::Color.white

  super

  # TODO
  # @width  = 1 if @width != :auto && @width < 1
  # @height = 1 if @height != :auto && @height < 1
end

Public Instance Methods

clear() click to toggle source

Clear all characters within this textbox.

@return [Textbox]

# File lib/cura/component/textbox.rb, line 49
def clear
  @text = ""

  set_cursor_position

  self
end
height=(value) click to toggle source

Set the height of this textbox.

@param [#to_i] value @return [Integer]

Calls superclass method
# File lib/cura/component/textbox.rb, line 88
def height=(value)
  super

  @height = 1 if @height < 1
end
mask_character=(value) click to toggle source

Set the mask character for this textbox. Set to anything for a “password” textbox. Only the first character of whatever is given is used.

@param [#to_s] value @return [String]

# File lib/cura/component/textbox.rb, line 67
def mask_character=(value)
  value = value.to_s.strip[0]
  value = nil if value.empty?

  @mask_character = value
end
width=(value) click to toggle source

Set the width of this textbox.

@param [#to_i] value @return [Integer]

Calls superclass method
# File lib/cura/component/textbox.rb, line 78
def width=(value)
  super

  @width = 1 if @width < 1
end

Protected Instance Methods

character_to_draw(character) click to toggle source
# File lib/cura/component/textbox.rb, line 102
def character_to_draw(character)
  @mask_character.nil? ? character : @mask_character
end
set_cursor_position() click to toggle source
# File lib/cura/component/textbox.rb, line 106
def set_cursor_position
  last_line_length = lines.last.nil? ? 0 : lines.last.length

  cursor.x = absolute_x + offsets.left + (text.length < width ? last_line_length : width - 1)
  cursor.y = absolute_y + offsets.top + text_height - 1
end
text_to_draw() click to toggle source
# File lib/cura/component/textbox.rb, line 96
def text_to_draw
  return text if text.length <= width

  focused? ? text[-width..-1] : text[0...width]
end