lib/cyberarm_engine/ui/container.rb in cyberarm_engine-0.7.1 vs lib/cyberarm_engine/ui/container.rb in cyberarm_engine-0.8.0
- old
+ new
@@ -13,16 +13,13 @@
@scroll_speed = 10
@text_color = options[:color]
@children = []
-
- @theme = {}
end
def build
- @theme.merge(@parent.theme) if @parent
@block.call(self) if @block
recalculate
end
@@ -38,18 +35,10 @@
def update
@children.each(&:update)
end
- def theme
- @theme
- end
-
- def color(color)
- @theme[:color] = color
- end
-
def hit_element?(x, y)
@children.reverse_each do |child|
case child
when Container
if element = child.hit_element?(x, y)
@@ -62,55 +51,53 @@
self if hit?(x, y)
end
def recalculate
- @current_position = Vector.new(@margin_left + @padding_left, @margin_top + @padding_top)
- unless @visible
- @width = 0
- @height= 0
- return
- end
+ @current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
+ return unless visible?
+ stylize
layout
- @width = @max_width ? @max_width : (@children.map {|c| c.x + c.outer_width }.max || 0).round
- @height = @max_height ? @max_height : (@children.map {|c| c.y + c.outer_height}.max || 0).round
+ @style.width = @max_width ? @max_width : (@children.map {|c| c.x + c.outer_width }.max || 0).round
+ @style.height = @max_height ? @max_height : (@children.map {|c| c.y + c.outer_height}.max || 0).round
# Move child to parent after positioning
@children.each do |child|
child.x += @x
child.y += @y
-
- # Fix child being displaced
+
+ child.stylize
child.recalculate
+ child.reposition # TODO: Implement top,bottom,left,center, and right positioning
end
update_background
end
def layout
raise "Not overridden"
end
def max_width
- @max_width ? @max_width : window.width - (@parent ? @parent.margin_right + @margin_right : @margin_right)
+ @max_width ? @max_width : window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right)
end
def fits_on_line?(element) # Flow
@current_position.x + element.outer_width <= max_width &&
@current_position.x + element.outer_width <= window.width
end
def position_on_current_line(element) # Flow
- element.x = element.margin_left + @current_position.x
- element.y = element.margin_top + @current_position.y
+ element.x = element.style.margin_left + @current_position.x
+ element.y = element.style.margin_top + @current_position.y
element.recalculate
@current_position.x += element.outer_width
- @current_position.x = @margin_left if @current_position.x >= max_width
+ @current_position.x = @style.margin_left if @current_position.x >= max_width
end
def tallest_neighbor(querier, y_position) # Flow
response = querier
@children.each do |child|
@@ -120,23 +107,23 @@
return response
end
def position_on_next_line(child) # Flow
- @current_position.x = @margin_left
+ @current_position.x = @style.margin_left
@current_position.y += tallest_neighbor(child, @current_position.y).outer_height
- child.x = child.margin_left + @current_position.x
- child.y = child.margin_top + @current_position.y
+ child.x = child.style.margin_left + @current_position.x
+ child.y = child.style.margin_top + @current_position.y
child.recalculate
@current_position.x += child.outer_width
end
def move_to_next_line(element) # Stack
- element.x = element.margin_left + @current_position.x
- element.y = element.margin_top + @current_position.y
+ element.x = element.style.margin_left + @current_position.x
+ element.y = element.style.margin_top + @current_position.y
element.recalculate
@current_position.y += element.outer_height
end
\ No newline at end of file