Class: Shoes::Para

Inherits:
Drawable show all
Includes:
FontHelper
Defined in:
lacci/lib/shoes/drawables/para.rb

Constant Summary

Constants inherited from Drawable

Drawable::DRAW_CONTEXT_STYLES

Constants included from Log

Log::DEFAULT_COMPONENT, Log::DEFAULT_DEBUG_LOG_CONFIG, Log::DEFAULT_LOG_CONFIG

Instance Attribute Summary

Attributes inherited from Drawable

#debug_id, #destroyed, #parent

Attributes inherited from Linkable

#linkable_id

Instance Method Summary collapse

Methods included from FontHelper

#contains_number?, #parse_font

Methods inherited from Drawable

allocate_drawable_id, #app, #banner, #caption, convert_to_float, convert_to_integer, #destroy, #download, drawable_by_id, drawable_class_by_name, dsl_name, #event, expects_parent?, feature_for_shoes_style, get_shoes_events, #hide, #hover, init_args, #inscription, #inspect, is_widget_class?, #leave, #method_missing, #motion, opt_init_args, optional_init_args, register_drawable_id, registered_shoes_events?, required_init_args, #respond_to_missing?, #set_parent, shoes_events, shoes_style, shoes_style_hashes, shoes_style_name?, shoes_style_names, #shoes_style_values, shoes_styles, #show, #style, #subtitle, #tagline, #title, #toggle, unregister_drawable_id, use_current_app, validate_as, with_current_app

Methods included from MarginHelper

#margin_parse

Methods included from Colors

#gray, #rgb, #to_rgb

Methods included from Log

configure_logger, #log_init, logger

Methods inherited from Linkable

#bind_shoes_event, #send_self_event, #send_shoes_event, #unsub_all_shoes_events, #unsub_shoes_event

Constructor Details

#initialize(*args, **kwargs) ⇒ Para

Initializes a new instance of the Para drawable. There are different methods to instantiate slightly different styles of Para, such as tagline, caption and subtitle. These will always be different sizes, but may be generally styled differently for some display services.

Examples:

Shoes.app do
  p = para "Hello, This is at the top!", stroke: red, size: :title, font: "Arial"

  banner("Welcome to Shoes!")
  title("Shoes Examples")
  subtitle("Explore the Features")
  tagline("Step into a World of Shoes")
  caption("A GUI Framework for Ruby")
  inscription("Designed for Easy Development")

  p.replace "On top we'll switch to ", strong("bold"), "!"
end


43
44
45
46
47
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
79
80
81
82
83
84
85
86
87
88
# File 'lacci/lib/shoes/drawables/para.rb', line 43

def initialize(*args, **kwargs)

  if kwargs[:font]
    arr= parse_font(kwargs[:font])
    
    if arr[0] != nil

      kwargs[:emphasis] = arr[0]

    end

    if arr[1] != nil

      kwargs[:font_variant] = arr[1]

    end

    if arr[2] != nil

      kwargs[:font_weight] = arr[2]

    end

    if arr[3] != nil

      kwargs[:size] = arr[3]

    end

    if arr[4] != ""

      kwargs[:family] = arr[4]

    end

  end
 
  # Don't pass text_children args to Drawable#initialize
  super(*[], **kwargs)
    
  # Text_children alternates strings and TextDrawables, so we can't just pass
  # it as a Shoes style. It won't serialize.
  update_text_children(args)

  create_display_drawable
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Shoes::Drawable

Instance Method Details

#replace(*children) ⇒ void

This method returns an undefined value.

Sets the paragraph text to a new value, which can include TextDrawables like em(), strong(), etc.



105
106
107
# File 'lacci/lib/shoes/drawables/para.rb', line 105

def replace(*children)
  update_text_children(children)
end

#textString

Return the text, but not the styling, of the para's contents. For example, if the contents had strong and emphasized text, the bold and emphasized would be removed but the text would be returned.



124
125
126
# File 'lacci/lib/shoes/drawables/para.rb', line 124

def text
  @text_children.map(&:to_s).join
end

#text=(*children) ⇒ void

This method returns an undefined value.

Set the paragraph text to a single String. To use bold, italics, etc. use #replace instead.



114
115
116
# File 'lacci/lib/shoes/drawables/para.rb', line 114

def text=(*children)
  update_text_children(children)
end

#to_sString

Return the text but not styling from the para. This is the same as #text.



132
133
134
# File 'lacci/lib/shoes/drawables/para.rb', line 132

def to_s
  self.text
end