Compare commits

..

4 Commits

6 changed files with 17 additions and 16 deletions

View File

@@ -18,7 +18,7 @@ module CyberarmEngine
@visible = !@options.key?(:visible) ? true : @options[:visible] @visible = !@options.key?(:visible) ? true : @options[:visible]
@tip = @options[:tip] || "" @tip = @options[:tip] || ""
@debug = @options[:debug] @debug = @options[:debug] || false
@debug_color = @options[:debug_color].nil? ? Gosu::Color::RED : @options[:debug_color] @debug_color = @options[:debug_color].nil? ? Gosu::Color::RED : @options[:debug_color]
@style = Style.new(options) @style = Style.new(options)
@@ -325,12 +325,10 @@ module CyberarmEngine
@border_canvas&.draw @border_canvas&.draw
render render
debug_draw if @debug
end end
def debug_draw def debug_draw
return if @debug == false # allow elements to opt out of debug drawing, makes debugging some things easier. return unless @debug # allow elements to opt out of debug drawing, makes debugging some things easier.
return if CyberarmEngine.const_defined?("GUI_DEBUG_ONLY_ELEMENT") && self.class == GUI_DEBUG_ONLY_ELEMENT return if CyberarmEngine.const_defined?("GUI_DEBUG_ONLY_ELEMENT") && self.class == GUI_DEBUG_ONLY_ELEMENT
Gosu.draw_line( Gosu.draw_line(
@@ -622,7 +620,7 @@ module CyberarmEngine
root.gui_state.request_recalculate if @parent && !is_a?(ToolTip) && (width != old_width || height != old_height) root.gui_state.request_recalculate if @parent && !is_a?(ToolTip) && (width != old_width || height != old_height)
root.gui_state.request_repaint if width != old_width || height != old_height root.gui_state.request_repaint if width != old_width || height != old_height
root.gui_state.menu.recalculate if root.gui_state.menu && root.gui_state.menu.parent == self root.gui_state.active_menu.recalculate if root.gui_state.active_menu && root.gui_state.active_menu.parent == self
end end
def layout def layout

View File

@@ -23,8 +23,8 @@ module CyberarmEngine
def draw_image def draw_image
@image.draw( @image.draw(
styled(:border_thickness_left) + styled(:padding_left) + @x, styled(:border_thickness_left) + styled(:margin_left) + styled(:padding_left) + @x,
styled(:border_thickness_top) + styled(:padding_top) + @y, styled(:border_thickness_top) + styled(:margin_top) + styled(:padding_top) + @y,
@z + 2, @z + 2,
@scale_x, @scale_y, @text.color @scale_x, @scale_y, @text.color
) )

View File

@@ -90,6 +90,9 @@ module CyberarmEngine
@children.each(&:draw) @children.each(&:draw)
end end
end end
@children.each(&:debug_draw)
debug_draw
end end
def debug_draw def debug_draw
@@ -194,9 +197,9 @@ module CyberarmEngine
case styled(:v_align) case styled(:v_align)
when :center when :center
@y = parent.height / 2 - height / 2 @y = parent.y + parent.height / 2 - height / 2
when :bottom when :bottom
@y = parent.height - height @y = parent.y + parent.height - height
end end
end end
@@ -205,9 +208,9 @@ module CyberarmEngine
case styled(:h_align) case styled(:h_align)
when :center when :center
@x = parent.width / 2 - width / 2 @x = parent.x + parent.width / 2 - width / 2
when :right when :right
@x = parent.width - width @x = parent.x + parent.width - width
end end
end end

View File

@@ -56,7 +56,7 @@ module CyberarmEngine
def show_menu def show_menu
@menu.clear do @menu.clear do
@menu.style.width = width @menu.style.width = width - (@menu.styled(:border_thickness_left) + @menu.styled(:border_thickness_right))
@items.each do |item| @items.each do |item|
# prevent already selected item from appearing in list # prevent already selected item from appearing in list

View File

@@ -11,10 +11,10 @@ module CyberarmEngine
# FIXME: properly find scrollable parent, if any. # FIXME: properly find scrollable parent, if any.
parent_scroll_top = parent&.parent ? parent.parent.scroll_top : 0 parent_scroll_top = parent&.parent ? parent.parent.scroll_top : 0
@x = @parent.x @x = @parent.x + @parent.styled(:border_thickness_left)
@y = parent_scroll_top + @parent.y + @parent.height @y = parent_scroll_top + @parent.y + @parent.height + @parent.styled(:border_thickness_top)
@y = (parent_scroll_top + @parent.y) - height if @y + height > window.height @y = (parent_scroll_top + @parent.y + @parent.styled(:border_thickness_top)) - height if @y + height > window.height
end end
def show def show

View File

@@ -39,7 +39,7 @@ module CyberarmEngine
@tip = Element::ToolTip.new("", parent: @root_container, z: Float::INFINITY, theme: current_theme) @tip = Element::ToolTip.new("", parent: @root_container, z: Float::INFINITY, theme: current_theme)
end end
def menu def active_menu
@menu @menu
end end