mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 21:22:33 +00:00
Using Element margin now
This commit is contained in:
@@ -1,8 +1,15 @@
|
|||||||
module CyberarmEngine
|
module CyberarmEngine
|
||||||
class Button < Label
|
class Button < Label
|
||||||
def draw
|
def draw
|
||||||
@text.draw
|
draw_text
|
||||||
|
draw_button
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw_text
|
||||||
|
@text.draw
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw_button
|
||||||
$window.draw_rect(relative_x, relative_y, width, height, @options[:element_background], @z+1)
|
$window.draw_rect(relative_x, relative_y, width, height, @options[:element_background], @z+1)
|
||||||
|
|
||||||
if mouse_over? && $window.button_down?(Gosu::MsLeft)
|
if mouse_over? && $window.button_down?(Gosu::MsLeft)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
Gosu.clip_to(@x, @y, @width + @spacing_x, @height + @spacing_y) do
|
Gosu.clip_to(@x, @y, @width, @height) do
|
||||||
background
|
background
|
||||||
|
|
||||||
Gosu.translate(@scroll_x, @scroll_y) do
|
Gosu.translate(@scroll_x, @scroll_y) do
|
||||||
@@ -116,7 +116,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def background
|
def background
|
||||||
Gosu.draw_rect(@x, @y, @width + @spacing_x, @height + @spacing_y, @background_color, @z)
|
Gosu.draw_rect(@x, @y, @width, @height, @background_color, @z)
|
||||||
end
|
end
|
||||||
|
|
||||||
def recalculate
|
def recalculate
|
||||||
@@ -126,27 +126,35 @@ module CyberarmEngine
|
|||||||
@packing_x = 0
|
@packing_x = 0
|
||||||
@packing_y = 0
|
@packing_y = 0
|
||||||
|
|
||||||
@spacing_x = 0
|
|
||||||
@spacing_y = 0
|
|
||||||
|
|
||||||
@spacer = 1
|
|
||||||
|
|
||||||
@width = @origin_width
|
@width = @origin_width
|
||||||
@height= @origin_height
|
@height= @origin_height
|
||||||
|
|
||||||
|
padded_margin = 0
|
||||||
|
@elements.reverse.each do |e|
|
||||||
|
if defined?(e.margin)
|
||||||
|
padded_margin = e.margin
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@elements.each do |element|
|
@elements.each do |element|
|
||||||
flow(element) if @mode == :flow
|
flow(element) if @mode == :flow
|
||||||
stack(element) if @mode == :stack
|
stack(element) if @mode == :stack
|
||||||
|
|
||||||
|
margin = 0
|
||||||
|
margin = element.margin if defined?(element.margin)
|
||||||
case @mode
|
case @mode
|
||||||
when :flow
|
when :flow
|
||||||
@width += element.width unless @origin_width.nonzero?
|
@width += element.width + margin unless @origin_width.nonzero?
|
||||||
@height = element.height if element.height > @height unless @origin_height.nonzero?
|
@height = element.height + margin if element.height + margin > @height + margin unless @origin_height.nonzero?
|
||||||
when :stack
|
when :stack
|
||||||
@width = element.width if element.width > @width unless @origin_width.nonzero?
|
@width = element.width + margin if element.width + margin > @width + margin unless @origin_width.nonzero?
|
||||||
@height += element.height unless @origin_height.nonzero?
|
@height += element.height + margin unless @origin_height.nonzero?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@width += padded_margin unless @origin_width.nonzero?
|
||||||
|
@height += padded_margin unless @origin_height.nonzero?
|
||||||
end
|
end
|
||||||
|
|
||||||
def flow(element)
|
def flow(element)
|
||||||
@@ -158,8 +166,8 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
element.recalculate
|
element.recalculate
|
||||||
|
|
||||||
@packing_x += element.width + @spacer
|
@packing_x += element.margin if defined?(element.margin)
|
||||||
@spacing_x += @spacer
|
@packing_x += element.width
|
||||||
end
|
end
|
||||||
|
|
||||||
def stack(element)
|
def stack(element)
|
||||||
@@ -171,8 +179,8 @@ module CyberarmEngine
|
|||||||
element.y = @packing_y
|
element.y = @packing_y
|
||||||
element.recalculate
|
element.recalculate
|
||||||
|
|
||||||
@packing_y += element.height + @spacer
|
@packing_y += element.margin if defined?(element.margin)
|
||||||
@spacing_y += @spacer
|
@packing_y += element.height
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -21,10 +21,11 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def draw
|
def draw
|
||||||
Gosu.clip_to(relative_x, relative_y, width, height) do
|
Gosu.clip_to(relative_x, relative_y, width, height) do
|
||||||
super
|
draw_text
|
||||||
|
|
||||||
Gosu.draw_rect(caret_position, @text.y, @caret_width, @caret_height, @caret_color, @z + 40) if @show_caret
|
Gosu.draw_rect(caret_position, @text.y, @caret_width, @caret_height, @caret_color, @z + 40) if @show_caret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
draw_button
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@@ -69,8 +70,10 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def width
|
def recalculate
|
||||||
@options[:edit_line_width]
|
super
|
||||||
|
|
||||||
|
@width = @options[:edit_line_width]
|
||||||
end
|
end
|
||||||
|
|
||||||
def value
|
def value
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ module CyberarmEngine
|
|||||||
checkmark: "√", # √
|
checkmark: "√", # √
|
||||||
|
|
||||||
padding: 20,
|
padding: 20,
|
||||||
margin: 0,
|
margin: 2,
|
||||||
|
|
||||||
element_background: Gosu::Color.rgb(12,12,12),
|
element_background: Gosu::Color.rgb(12,12,12),
|
||||||
|
|
||||||
@@ -91,11 +91,11 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def relative_x
|
def relative_x
|
||||||
@parent.x + @parent.scroll_x + @x
|
@parent.x + @parent.scroll_x + @x + @margin
|
||||||
end
|
end
|
||||||
|
|
||||||
def relative_y
|
def relative_y
|
||||||
@parent.y + @parent.scroll_y + @y
|
@parent.y + @parent.scroll_y + @y + @margin
|
||||||
end
|
end
|
||||||
|
|
||||||
def recalculate
|
def recalculate
|
||||||
|
|||||||
Reference in New Issue
Block a user