mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 13:12:34 +00:00
Fixed word wrapping weirdness and made it the default text_wrap method from :none
This commit is contained in:
@@ -63,7 +63,7 @@ module CyberarmEngine
|
|||||||
wrap_behavior = style.text_wrap
|
wrap_behavior = style.text_wrap
|
||||||
copy = @raw_text.to_s.dup
|
copy = @raw_text.to_s.dup
|
||||||
|
|
||||||
if max_width >= line_width(copy[0]) && line_width(copy) > max_width && wrap_behavior != :none
|
if line_width(copy[0]) <= max_width && line_width(copy) > max_width && wrap_behavior != :none
|
||||||
breaks = []
|
breaks = []
|
||||||
line_start = 0
|
line_start = 0
|
||||||
line_end = copy.length
|
line_end = copy.length
|
||||||
@@ -71,6 +71,7 @@ module CyberarmEngine
|
|||||||
while line_start != copy.length
|
while line_start != copy.length
|
||||||
if line_width(copy[line_start...line_end]) > max_width
|
if line_width(copy[line_start...line_end]) > max_width
|
||||||
line_end = ((line_end - line_start) / 2.0)
|
line_end = ((line_end - line_start) / 2.0)
|
||||||
|
line_end = 1.0 if line_end <= 1
|
||||||
elsif line_end < copy.length && line_width(copy[line_start...line_end + 1]) < max_width
|
elsif line_end < copy.length && line_width(copy[line_start...line_end + 1]) < max_width
|
||||||
# To small, grow!
|
# To small, grow!
|
||||||
# TODO: find a more efficient way
|
# TODO: find a more efficient way
|
||||||
@@ -87,7 +88,7 @@ module CyberarmEngine
|
|||||||
break if copy[line_end.floor - i].to_s.match(/[[:punct:]]| /)
|
break if copy[line_end.floor - i].to_s.match(/[[:punct:]]| /)
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "Max width: #{max_width}/#{line_width(@raw_text)} Reach: {#{reach}/#{max_reach}} Line Start: #{line_start}/#{line_end.floor} (#{copy.length}|#{@raw_text.length}) [#{entering_line_end}] '#{copy}' {#{copy[line_start...line_end]}}"
|
# puts "Max width: #{max_width}/#{line_width(@raw_text)} Reach: {#{reach}/#{max_reach}} Line Start: #{line_start}/#{line_end.floor} (#{copy.length}|#{@raw_text.length}) [#{entering_line_end}] '#{copy}' {#{copy[line_start...line_end]}}"
|
||||||
line_end = line_end.floor - reach + 1 if reach != max_reach # Add +1 to walk in front of punctuation
|
line_end = line_end.floor - reach + 1 if reach != max_reach # Add +1 to walk in front of punctuation
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -108,7 +109,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def line_width(text)
|
def line_width(text)
|
||||||
(@x + @text.textobject.markup_width(text) + noncontent_width)
|
(@text.textobject.markup_width(text) + noncontent_width)
|
||||||
end
|
end
|
||||||
|
|
||||||
def value
|
def value
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
TextBlock: { # < Element
|
TextBlock: { # < Element
|
||||||
text_size: 28,
|
text_size: 28,
|
||||||
text_wrap: :none, # :word_wrap, :break_word, :none
|
text_wrap: :word_wrap, # :word_wrap, :break_word, :none
|
||||||
text_shadow: false,
|
text_shadow: false,
|
||||||
text_align: :left,
|
text_align: :left,
|
||||||
font: "Arial",
|
font: "Arial",
|
||||||
|
|||||||
Reference in New Issue
Block a user