Class: Hokusai::Blocks::Label
- Inherits:
-
Hokusai::Block
- Object
- Hokusai::Block
- Hokusai::Blocks::Label
- Defined in:
- ui/src/hokusai/blocks/label.rb
Instance Attribute Summary
Attributes inherited from Hokusai::Block
Instance Method Summary collapse
-
#initialize(**args) ⇒ Label
constructor
A new instance of Label.
- #render(canvas) ⇒ Object
Methods inherited from Hokusai::Block
#children, #children?, compile, computed, computed!, #draw, #draw_with, #dump, #emit, inject, inject!, #method_missing, mount, #on_resize, provide, provides, style, styles_get, template, template_from_file, template_get, #update, use, uses
Constructor Details
#initialize(**args) ⇒ Label
Returns a new instance of Label.
14 15 16 17 18 19 20 21 |
# File 'ui/src/hokusai/blocks/label.rb', line 14 def initialize(**args) @content_width = 0.0 @content_height = 0.0 @updated = false @last_content = nil super(**args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Hokusai::Block
Instance Method Details
#render(canvas) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'ui/src/hokusai/blocks/label.rb', line 23 def render(canvas) if @last_content != content width, height = Hokusai.fonts.active.measure(content.to_s, size.to_i) node..set_prop(:width, width + padding.right + padding.left) node..set_prop(:height, height + padding.top + padding.bottom) emit("width_updated", width + padding.right + padding.left) @last_content = content end draw do text(content, canvas.x, canvas.y) do |command| command.color = color command.size = size command.padding = padding command.font = font unless font.nil? end end end |