Sliders work better, fixed CheckBox not passing along options hash, Text width/height now accept a string, changed EditLine text selection color, temporary back to back gui recalculations to fix positioning errors until Container#layout can safely be called after determining element width and height.

This commit is contained in:
2020-05-06 12:08:20 -05:00
parent a98bb4ec82
commit 3226eb2bda
13 changed files with 96 additions and 47 deletions

View File

@@ -22,13 +22,13 @@ module CyberarmEngine
def build
@block.call(self) if @block
recalculate
root.gui_state.request_recalculate
end
def add(element)
@children << element
recalculate
root.gui_state.request_recalculate
end
def clear(&block)
@@ -41,7 +41,6 @@ module CyberarmEngine
$__current_container__ = old_container
recalculate
root.gui_state.request_recalculate
end
@@ -75,6 +74,9 @@ module CyberarmEngine
def recalculate
@current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
return unless visible?
Stats.increment(:gui_recalculations_last_frame, 1)
stylize
layout
@@ -92,7 +94,6 @@ module CyberarmEngine
@height = _height ? _height : (@children.map {|c| c.y + c.outer_height}.max || 0).round
end
# Move child to parent after positioning
@children.each do |child|
child.x += (@x + @style.border_thickness_left) - style.margin_left
@@ -101,6 +102,8 @@ module CyberarmEngine
child.stylize
child.recalculate
child.reposition # TODO: Implement top,bottom,left,center, and right positioning
Stats.increment(:gui_recalculations_last_frame, 1)
end
update_background
@@ -110,13 +113,13 @@ module CyberarmEngine
raise "Not overridden"
end
# TODO: Fix @max_width no longer exists
def max_width
@max_width ? @max_width : window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right)
_width = dimensional_size(@style.width, :width)
_width ? outer_width : window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right)
end
# TODO: Fix container automatic width (0.0..1.0) not considered
def fits_on_line?(element) # Flow
p [@options[:id], @width] if @options[:id]
@current_position.x + element.outer_width <= max_width &&
@current_position.x + element.outer_width <= window.width
end
@@ -175,6 +178,25 @@ module CyberarmEngine
def value
@children.map {|c| c.class}.join(", ")
end
def to_s
"#{self.class} x=#{x} y=#{y} width=#{width} height=#{height} children=#{@children.size}"
end
def write_tree(indent = "", index = 0)
puts self
indent = indent + " "
@children.each_with_index do |child, i|
print "#{indent}#{i}: "
if child.is_a?(Container)
child.write_tree(indent)
else
puts child
end
end
end
end
end
end