mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 13:12:34 +00:00
Improved flow behavior, renamed stroke to color, added outer_width and outer_height to elements, added setters for width, and height.
This commit is contained in:
@@ -44,12 +44,8 @@ module CyberarmEngine
|
||||
@theme
|
||||
end
|
||||
|
||||
def stroke(color)
|
||||
@theme[:stroke] = color
|
||||
end
|
||||
|
||||
def fill(color)
|
||||
@theme[:fill] = color
|
||||
def color(color)
|
||||
@theme[:color] = color
|
||||
end
|
||||
|
||||
def hit_element?(x, y)
|
||||
@@ -72,8 +68,8 @@ module CyberarmEngine
|
||||
|
||||
layout
|
||||
|
||||
@width = @max_width ? @max_width : (@children.map {|c| c.x + c.width + c.margin_right}.max || 0).round
|
||||
@height = @max_height ? @max_height : (@children.map {|c| c.y + c.height+ c.margin_top }.max || 0).round
|
||||
@width = @max_width ? @max_width : (@children.map {|c| c.x + c.width + c.margin_right }.max || 0).round
|
||||
@height = @max_height ? @max_height : (@children.map {|c| c.y + c.height + c.margin_bottom}.max || 0).round
|
||||
|
||||
# Move child to parent after positioning
|
||||
@children.each do |child|
|
||||
@@ -95,27 +91,50 @@ module CyberarmEngine
|
||||
@max_width ? @max_width : window.width - (@parent ? @parent.margin_right + @margin_right : @margin_right)
|
||||
end
|
||||
|
||||
def fits_on_line?(element)
|
||||
@current_position.x + element.margin_left + element.width + element.margin_right <= max_width
|
||||
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)
|
||||
def position_on_current_line(element) # Flow
|
||||
element.x = element.margin_left + @current_position.x
|
||||
element.y = element.margin_top + @current_position.y
|
||||
|
||||
element.recalculate
|
||||
|
||||
@current_position.x += element.width + element.margin_right
|
||||
@current_position.x = @margin_left + @x if @current_position.x >= max_width
|
||||
@current_position.x += element.outer_width
|
||||
@current_position.x = @margin_left if @current_position.x >= max_width
|
||||
end
|
||||
|
||||
def move_to_next_line(element)
|
||||
def tallest_neighbor(querier, y_position) # Flow
|
||||
response = querier
|
||||
@children.each do |child|
|
||||
response = child if child.outer_height > response.outer_height
|
||||
break if child == querier
|
||||
end
|
||||
|
||||
return response
|
||||
end
|
||||
|
||||
def position_on_next_line(child) # Flow
|
||||
@current_position.x = @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.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.recalculate
|
||||
|
||||
@current_position.y += element.height + element.margin_bottom
|
||||
@current_position.y += element.outer_height
|
||||
end
|
||||
|
||||
# def mouse_wheel_up(sender, x, y)
|
||||
|
||||
@@ -75,13 +75,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
# Foreground color, e.g. Text
|
||||
def stroke(color)
|
||||
@containers.last.stroke(color)
|
||||
end
|
||||
|
||||
# Element background color
|
||||
def fill(color)
|
||||
@containers.last.fill(color)
|
||||
def color(color)
|
||||
@containers.last.color(color)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -20,9 +20,11 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def render
|
||||
Gosu.clip_to(@text.x, @text.y, @width, @text.height) do
|
||||
draw_text
|
||||
Gosu.draw_rect(caret_position, @text.y, @caret_width, @caret_height, @caret_color, @z + 40) if @focus && @show_caret
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @type == :password
|
||||
|
||||
@@ -4,8 +4,8 @@ module CyberarmEngine
|
||||
include Event
|
||||
include Common
|
||||
|
||||
attr_accessor :x, :y, :z, :width, :height, :enabled
|
||||
attr_reader :parent, :options, :event_handler, :background_canvas, :border_canvas
|
||||
attr_accessor :x, :y, :z, :enabled
|
||||
attr_reader :width, :height, :parent, :options, :event_handler, :background_canvas, :border_canvas
|
||||
|
||||
attr_reader :border_thickness, :border_thickness_left, :border_thickness_right, :border_thickness_top, :border_thickness_bottom
|
||||
attr_reader :border_color, :border_color_left, :border_color_right, :border_color_top, :border_color_bottom
|
||||
@@ -58,6 +58,9 @@ module CyberarmEngine
|
||||
default_events
|
||||
end
|
||||
|
||||
def width=(n); @max_width = n; end
|
||||
def height=(n); @max_height = n; end
|
||||
|
||||
def set_background(background)
|
||||
@background = background
|
||||
@background_canvas.background = background
|
||||
@@ -150,10 +153,18 @@ module CyberarmEngine
|
||||
(@border_thickness_left + @padding_left) + @width + (@padding_right + @border_thickness_right)
|
||||
end
|
||||
|
||||
def outer_width
|
||||
@margin_left + width + @margin_right
|
||||
end
|
||||
|
||||
def height
|
||||
(@border_thickness_top + @padding_top) + @height + (@padding_bottom + @border_thickness_bottom)
|
||||
end
|
||||
|
||||
def outer_height
|
||||
@margin_top + height + @margin_bottom
|
||||
end
|
||||
|
||||
def background=(_background)
|
||||
@background_canvas.background=(_background)
|
||||
update_background
|
||||
|
||||
@@ -7,15 +7,7 @@ module CyberarmEngine
|
||||
if fits_on_line?(child)
|
||||
position_on_current_line(child)
|
||||
else
|
||||
@current_position.x = @margin_left + @x
|
||||
@current_position.y += child.height + child.margin_bottom
|
||||
|
||||
child.x = element.margin_left + @current_position.x
|
||||
child.y = element.margin_top + @current_position.y
|
||||
|
||||
child.recalculate
|
||||
|
||||
@current_position.x += child.width + child.margin_right
|
||||
position_on_next_line(child)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ module CyberarmEngine
|
||||
def initialize(text, options = {}, block = nil)
|
||||
super(options, block)
|
||||
|
||||
@text = Text.new(text, font: @options[:font], z: @z, color: @options[:stroke], size: @options[:text_size], shadow: @options[:text_shadow])
|
||||
@text = Text.new(text, font: @options[:font], z: @z, color: @options[:color], size: @options[:text_size], shadow: @options[:text_shadow])
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user