Class: Fidgit::TextLine
- Defined in:
- lib/fidgit/elements/text_line.rb
Overview
Used internally by the label.
Direct Known Subclasses
Constant Summary collapse
- VALID_JUSTIFICATION =
[:left, :right, :center]
Constants inherited from Element
Element::DEFAULT_SCHEMA_FILE, Element::VALID_ALIGN_H, Element::VALID_ALIGN_V
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#justify ⇒ Object
Returns the value of attribute justify.
Attributes inherited from Element
#align_h, #align_v, #background_color, #border_thickness, #font, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #tip, #z
Instance Method Summary collapse
- #draw_foreground ⇒ Object
-
#initialize(text, options = {}) ⇒ TextLine
constructor
A new instance of TextLine.
- #min_width ⇒ Object
- #text ⇒ Object
- #text=(text) ⇒ Object
- #to_s ⇒ Object
Methods inherited from Element
#default, #drag?, #draw, #draw_frame, #draw_rect, #enabled=, #enabled?, #height, #height=, #hit?, #max_height, #max_width, #min_height, new, original_new, #outer_height, #outer_width, #recalc, schema, #update, #width, #width=, #with, #x, #x=, #y, #y=
Methods included from Event
#events, included, new_event_handlers, #publish, #subscribe, #unsubscribe
Constructor Details
#initialize(text, options = {}) ⇒ TextLine
Returns a new instance of TextLine.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fidgit/elements/text_line.rb', line 37 def initialize(text, = {}) = { color: default(:color), justify: default(:justify), }.merge! super() self.justify = [:justify] self.color = [:color] self.text = text end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
6 7 8 |
# File 'lib/fidgit/elements/text_line.rb', line 6 def color @color end |
#justify ⇒ Object
Returns the value of attribute justify.
6 7 8 |
# File 'lib/fidgit/elements/text_line.rb', line 6 def justify @justify end |
Instance Method Details
#draw_foreground ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fidgit/elements/text_line.rb', line 50 def draw_foreground case @justify when :left rel_x = 0.0 draw_x = x + padding_left when :right rel_x = 1.0 draw_x = x + rect.width - padding_right when :center rel_x = 0.5 draw_x = (x + padding_left) + (rect.width - padding_right - padding_left) / 2.0 end font.draw_rel(@text, draw_x, y + padding_top, z, rel_x, 0, 1, 1, color) end |
#min_width ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/fidgit/elements/text_line.rb', line 68 def min_width if @text.empty? [padding_left + padding_right, super].max else [padding_left + font.text_width(@text) + padding_right, super].max end end |
#text ⇒ Object
16 |
# File 'lib/fidgit/elements/text_line.rb', line 16 def text; @text.dup; end |
#text=(text) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/fidgit/elements/text_line.rb', line 18 def text=(text) raise ArgumentError.new("Text must be a String") unless text.respond_to? :to_s @text = text.to_s.dup recalc text end |
#to_s ⇒ Object
88 89 90 |
# File 'lib/fidgit/elements/text_line.rb', line 88 def to_s "#{super} '#{@text}'" end |