Class: Fidgit::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
-
#background_color ⇒ Object
Returns the value of attribute background_color.
-
#border_color ⇒ Object
Returns the value of attribute border_color.
-
#color ⇒ Object
Returns the value of attribute color.
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#text ⇒ Object
Returns the value of attribute text.
Attributes inherited from Element
#align_h, #align_v, #border_thickness, #font_size, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #tip, #z
Instance Method Summary collapse
- #draw_foreground ⇒ Object
-
#initialize(text, options = {}) ⇒ Label
constructor
A new instance of Label.
Methods inherited from Element
#default, #drag?, #draw, #draw_frame, #draw_rect, #enabled=, #enabled?, #font, #height, #height=, #hit?, #max_height, #max_width, #min_height, #min_width, new, original_new, #outer_height, #outer_width, #recalc, schema, #update, #width, #width=, #with, #x, #x=, #y, #y=
Methods included from Event
#events, included, #publish, #subscribe
Constructor Details
#initialize(text, options = {}) ⇒ Label
Returns a new instance of Label.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fidgit/elements/label.rb', line 28 def initialize(text, = {}) = { color: default(:color), justify: default(:justify), background_color: default(:background_color), border_color: default(:border_color), }.merge! @text = text.dup @icon = [:icon] @color = [:color].dup raise "Justification must be one of #{VALID_JUSTIFICATION.inspect}" unless VALID_JUSTIFICATION.include? [:justify] @justify = [:justify] super() self.text = text # Forces stuff that manipulates text to work. end |
Instance Attribute Details
#background_color ⇒ Object
Returns the value of attribute background_color.
5 6 7 |
# File 'lib/fidgit/elements/label.rb', line 5 def background_color @background_color end |
#border_color ⇒ Object
Returns the value of attribute border_color.
5 6 7 |
# File 'lib/fidgit/elements/label.rb', line 5 def border_color @border_color end |
#color ⇒ Object
Returns the value of attribute color.
5 6 7 |
# File 'lib/fidgit/elements/label.rb', line 5 def color @color end |
#icon ⇒ Object
Returns the value of attribute icon.
6 7 8 |
# File 'lib/fidgit/elements/label.rb', line 6 def icon @icon end |
#text ⇒ Object
Returns the value of attribute text.
6 7 8 |
# File 'lib/fidgit/elements/label.rb', line 6 def text @text end |
Instance Method Details
#draw_foreground ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fidgit/elements/label.rb', line 48 def draw_foreground current_x = x + padding_left if @icon @icon.draw(current_x, y + padding_top, z) current_x += @icon.width + padding_left end unless @text.empty? case @justify when :left rel_x = 0.0 center_x = current_x when :right rel_x = 1.0 center_x = x + rect.width - padding_right when :center rel_x = 0.5 center_x = (current_x + x + rect.width - padding_right) / 2.0 end # Make text centered alongside the icon # TODO: Probably should have this as an option. center_y = y + padding_top + ((y + height - padding_bottom) - (y + padding_top)) / 2.0 font.draw_rel(@text, center_x, center_y, z, rel_x, 0.5, 1, 1, @color) end nil end |