Class: Moon::Text

Inherits:
RenderContext show all
Defined in:
lib/moon/packages/render_primitives/ui/text.rb

Overview

Renderer object for rendering Fonts

Defined Under Namespace

Classes: FontChangedEvent, StringChangedEvent

Instance Attribute Summary collapse

Attributes inherited from RenderContext

#id

Attributes included from RenderPrimitive::DataAttributes

#data_attrs

Attributes included from RenderPrimitive::Rectangular

#h, #position, #w

Attributes included from RenderPrimitive::Containable

#parent

Instance Method Summary collapse

Methods inherited from RenderContext

#apply_position_modifier, #post_initialize, #pre_initialize, #render?, #render_abs, #render_content, #screen_bounds, #screen_position, #update

Methods included from RenderPrimitive::DataAttributes

#initialize_data_attrs

Methods included from RenderPrimitive::Rectangular

#align!, #bounds, #contains?, #cx, #cx=, #cy, #cy=, #move, #on_resize, #resize, #to_rect, #x, #x2, #x2=, #x=, #y, #y2, #y2=, #y=, #z, #z=

Methods included from RenderPrimitive::Containable

#containerize, #disown

Methods included from RenderPrimitive::Visibility

#hide, #invisible?, #show, #visible?

Methods included from RenderPrimitive::Renderable

#render, #render?

Methods included from RenderPrimitive::ScreenElement

#contains_pos?, #relative_contains_pos?, #relative_to_screen, #screen_to_relative

Methods included from Eventable

#allow_event?, #clear_events, #each_listener, #each_typed_listener, filter_from_options, #has_events?, #initialize_eventable, #off, #on, #ppd_ev, #trigger, #typing

Methods included from Transitionable

#key_transition, #remove_transitions, #transition

Methods included from TransitionHost

#add_transition, #finish_transitions, #remove_transition, #remove_transitions, #update_transitions

Constructor Details

#initialize(string = nil, font = nil, align = :left) ⇒ Text

Returns a new instance of Text.

Parameters:

  • string (String) (defaults to: nil)
  • font (Moon::Font) (defaults to: nil)

63
64
65
66
67
68
69
70
71
72
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 63

def initialize(string = nil, font = nil, align = :left)
  @lines = []
  @font = font
  @align = align
  @line_h = 1.2
  @opacity = 1.0
  super()
  self.color = Vector4.new(1.0, 1.0, 1.0, 1.0)
  self.string = string
end

Instance Attribute Details

#alignSymbol

Returns @enum [:left, :right, :center].

Returns:

  • (Symbol)

    @enum [:left, :right, :center]


55
56
57
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 55

def align
  @align
end

#colorMoon::Vector4

Returns:


48
49
50
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 48

def color
  @color
end

#fontMoon::Font

Returns:

  • (Moon::Font)

50
51
52
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 50

def font
  @font
end

#line_hFloat

Returns:


59
60
61
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 59

def line_h
  @line_h
end

#opacity=(value) ⇒ Object


104
105
106
107
108
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 104

def opacity=(opacity)
  old = @opacity
  @opacity = opacity
  on_opacity_changed old, @opacity
end

#stringString

Returns:


57
58
59
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 57

def string
  @string
end

#use_eventsBoolean

Returns:


46
47
48
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 46

def use_events
  @use_events
end

Instance Method Details

#disable_eventsObject

Disable events for this Text object


80
81
82
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 80

def disable_events
  @use_events = false
end

#enable_eventsObject

Enables events for this Text object


75
76
77
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 75

def enable_events
  @use_events = true
end

#on_color_changed(org, cur) ⇒ Object


88
89
90
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 88

def on_color_changed(org, cur)
  refresh_color
end

#on_font_changed(org, cur) ⇒ Object


92
93
94
95
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 92

def on_font_changed(org, cur)
  refresh_size
  trigger(FontChangedEvent.new(org, cur)) if @use_events
end

#on_opacity_changed(org, cur) ⇒ Object


84
85
86
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 84

def on_opacity_changed(org, cur)
  refresh_opacity
end

#on_string_changed(org, cur) ⇒ Object


97
98
99
100
101
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 97

def on_string_changed(org, cur)
  @lines = @string.split("\n")
  refresh_size
  trigger(StringChangedEvent.new(org, cur)) if @use_events
end

#set(options) ⇒ Object

Parameters:


132
133
134
135
136
137
138
139
# File 'lib/moon/packages/render_primitives/ui/text.rb', line 132

def set(options)
  self.string = options.fetch(:string)
  self.align = options.fetch(:align, :left)
  if fon = options[:font]
    self.font = fon
  end
  self
end