Class: Hokusai::Clamping::Segment
- Inherits:
-
Object
- Object
- Hokusai::Clamping::Segment
- Defined in:
- ui/src/hokusai/font.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #char_is_selected(char) ⇒ Object
- #chars ⇒ Object
- #each_char ⇒ Object
- #each_group ⇒ Object
- #groups ⇒ Object
- #has_selection? ⇒ Boolean
-
#initialize(raw) ⇒ Segment
constructor
A new instance of Segment.
- #make_selection(start, stop) ⇒ Object
- #offset ⇒ Object
- #select_begin ⇒ Object
- #select_begin=(val) ⇒ Object
- #select_end ⇒ Object
- #select_end=(val) ⇒ Object
- #size ⇒ Object
- #width(range = (offset...offset + size)) ⇒ Object
Constructor Details
#initialize(raw) ⇒ Segment
Returns a new instance of Segment.
105 106 107 |
# File 'ui/src/hokusai/font.rb', line 105 def initialize(raw) @raw = raw end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
103 104 105 |
# File 'ui/src/hokusai/font.rb', line 103 def raw @raw end |
Instance Method Details
#char_is_selected(char) ⇒ Object
184 185 186 187 188 |
# File 'ui/src/hokusai/font.rb', line 184 def char_is_selected(char) return false if select_begin.nil? || select_end.nil? (select_begin..select_end).include?(char.offset) end |
#chars ⇒ Object
121 122 123 124 125 126 127 128 129 130 |
# File 'ui/src/hokusai/font.rb', line 121 def chars return @chars unless @chars.nil? @chars = [] each_char do |char| @chars << char end @chars end |
#each_char ⇒ Object
132 133 134 135 136 137 138 139 140 141 |
# File 'ui/src/hokusai/font.rb', line 132 def each_char char = raw[:chars] i = 0 while !char.null? yield Char.new(char), i i += 1 char = char[:next_char] end end |
#each_group ⇒ Object
154 155 156 157 158 159 160 161 162 |
# File 'ui/src/hokusai/font.rb', line 154 def each_group group = raw[:groups] i = 0 until group.null? yield Group.new(group), i i.succ group = group[:next_group] end end |
#groups ⇒ Object
143 144 145 146 147 148 149 150 151 152 |
# File 'ui/src/hokusai/font.rb', line 143 def groups return @groups unless @groups.nil? @groups = [] each_group do |group| @groups << group end @groups end |
#has_selection? ⇒ Boolean
180 181 182 |
# File 'ui/src/hokusai/font.rb', line 180 def has_selection? !select_end.nil? && !select_begin.nil? end |
#make_selection(start, stop) ⇒ Object
190 191 192 193 |
# File 'ui/src/hokusai/font.rb', line 190 def make_selection(start, stop) self.select_begin = start self.select_end = stop end |
#offset ⇒ Object
113 114 115 |
# File 'ui/src/hokusai/font.rb', line 113 def offset raw[:offset] end |
#select_begin ⇒ Object
168 169 170 |
# File 'ui/src/hokusai/font.rb', line 168 def select_begin raw[:select_begin] end |
#select_begin=(val) ⇒ Object
172 173 174 |
# File 'ui/src/hokusai/font.rb', line 172 def select_begin=(val) raw[:select_begin] = val end |
#select_end ⇒ Object
164 165 166 |
# File 'ui/src/hokusai/font.rb', line 164 def select_end raw[:select_end] end |
#select_end=(val) ⇒ Object
176 177 178 |
# File 'ui/src/hokusai/font.rb', line 176 def select_end=(val) raw[:select_end] = val.nil? ? select_begin : val end |
#size ⇒ Object
117 118 119 |
# File 'ui/src/hokusai/font.rb', line 117 def size raw[:size] end |
#width(range = (offset...offset + size)) ⇒ Object
109 110 111 |
# File 'ui/src/hokusai/font.rb', line 109 def width(range = (offset...offset + size)) chars[range]&.sum(&:width) || 0.0 end |