Class: Clogs::TextDrawable
- Defined in:
- lib/clogs/drawables/text.rb
Overview
The display side of Shoes' inline text drawables: strong, em, code, link, span and friends. These have no geometry of their own -- they contribute styled runs to whichever paragraph contains them.
Instance Attribute Summary
Attributes inherited from Drawable
#abs_x, #abs_y, #children, #height, #parent, #shoes_linkable_id, #styles, #width, #x, #y
Instance Method Summary collapse
- #emphasis_style(base) ⇒ Object
- #own_style(base) ⇒ Object
- #resolved_size(default) ⇒ Object
-
#runs(base_style) ⇒ Object
Contribute [text, style] pairs to the enclosing paragraph.
-
#style_for_tag(base) ⇒ Object
Overridden per tag.
- #truthy_underline? ⇒ Boolean
Methods inherited from Drawable
#add_child, #app, #clickable?, #contains?, #destroy_self, #draw, #each_peer, #focus_gained, #focus_lost, #focusable?, for_shoes_class, #hidden?, #initialize, #margin, #measure, #needs_layout!, #notify, #on_click, #on_key, #on_mouse_move, #on_release, #paint, #positioned?, #properties_changed, #redraw!, #remove_child, #requested_height, #requested_width, #set_parent, #style
Constructor Details
This class inherits a constructor from Clogs::Drawable
Instance Method Details
#emphasis_style(base) ⇒ Object
11 12 13 |
# File 'lib/clogs/drawables/text.rb', line 11 def emphasis_style(base) style_for_tag(base) end |
#own_style(base) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/clogs/drawables/text.rb', line 20 def own_style(base) s = style_for_tag(base) s = s.with(size: resolved_size(s.size)) if style(:size) s = s.with(color: Style.color(style(:stroke), s.color)) if style(:stroke) s = s.with(bg: Style.color(style(:fill), s.bg)) if style(:fill) s = s.with(family: style(:family)) if style(:family) s = s.with(underline: true) if truthy_underline? s = s.with(italic: true) if style(:emphasis).to_s == "italic" s.with(owner: self) end |
#resolved_size(default) ⇒ Object
36 37 38 |
# File 'lib/clogs/drawables/text.rb', line 36 def resolved_size(default) Paragraph::SIZES[style(:size).to_s.to_sym] || (style(:size).is_a?(Numeric) ? style(:size) : default) end |
#runs(base_style) ⇒ Object
Contribute [text, style] pairs to the enclosing paragraph.
41 42 43 44 |
# File 'lib/clogs/drawables/text.rb', line 41 def runs(base_style) mine = own_style(base_style) Clogs.(style(:text_items), mine) end |
#style_for_tag(base) ⇒ Object
Overridden per tag.
16 17 18 |
# File 'lib/clogs/drawables/text.rb', line 16 def style_for_tag(base) base end |
#truthy_underline? ⇒ Boolean
31 32 33 34 |
# File 'lib/clogs/drawables/text.rb', line 31 def truthy_underline? u = style(:underline) !u.nil? && u != "" && u != "none" && u != false end |