mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 05:02:34 +00:00
Improved theme handling
This commit is contained in:
@@ -15,12 +15,9 @@ module CyberarmEngine
|
||||
@text_color = options[:color]
|
||||
|
||||
@children = []
|
||||
|
||||
@theme = {}
|
||||
end
|
||||
|
||||
def build
|
||||
@theme.merge(@parent.theme) if @parent
|
||||
@block.call(self) if @block
|
||||
|
||||
recalculate
|
||||
@@ -40,14 +37,6 @@ module CyberarmEngine
|
||||
@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
|
||||
@@ -66,6 +55,7 @@ module CyberarmEngine
|
||||
def recalculate
|
||||
@current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
|
||||
return unless visible?
|
||||
stylize
|
||||
|
||||
layout
|
||||
|
||||
@@ -76,9 +66,10 @@ module CyberarmEngine
|
||||
@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
|
||||
|
||||
@@ -2,7 +2,7 @@ module CyberarmEngine
|
||||
module DSL
|
||||
def flow(options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
options[:theme] = current_theme
|
||||
_container = Flow.new(options, block)
|
||||
@containers << _container
|
||||
_container.build
|
||||
@@ -14,7 +14,7 @@ module CyberarmEngine
|
||||
|
||||
def stack(options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
options[:theme] = current_theme
|
||||
_container = Stack.new(options, block)
|
||||
@containers << _container
|
||||
_container.build
|
||||
@@ -79,16 +79,11 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def background(color = Gosu::Color::NONE)
|
||||
@containers.last.background = color
|
||||
end
|
||||
|
||||
# Foreground color, e.g. Text
|
||||
def color(color)
|
||||
@containers.last.color(color)
|
||||
@containers.last.style.background = color
|
||||
end
|
||||
|
||||
def theme(theme)
|
||||
@current_theme = theme
|
||||
@containers.last.options[:theme] = theme
|
||||
end
|
||||
|
||||
def current_theme
|
||||
|
||||
@@ -13,43 +13,41 @@ module CyberarmEngine
|
||||
@options = options
|
||||
@block = block
|
||||
|
||||
@style = Style.new(options)
|
||||
@focus = false
|
||||
@style.background_canvas = Background.new
|
||||
@style.border_canvas = BorderCanvas.new(element: self)
|
||||
@focus = false
|
||||
@enabled = true
|
||||
@visible = true
|
||||
|
||||
@x = default(:x)
|
||||
@y = default(:y)
|
||||
@z = default(:z)
|
||||
@style = Style.new(options)
|
||||
|
||||
@x = @style.x
|
||||
@y = @style.y
|
||||
@z = @style.z
|
||||
|
||||
@fixed_x = @x if @x != 0
|
||||
@fixed_y = @y if @y != 0
|
||||
|
||||
@style.width = default(:width) || $window.width
|
||||
@style.height = default(:height) || $window.height
|
||||
|
||||
set_border_thickness(default(:border_thickness))
|
||||
|
||||
set_padding(default(:padding))
|
||||
|
||||
set_margin(default(:margin))
|
||||
|
||||
set_background(default(:background))
|
||||
set_border_color(default(:border_color))
|
||||
|
||||
raise "#{self.class} 'x' must be a number" unless @x.is_a?(Numeric)
|
||||
raise "#{self.class} 'y' must be a number" unless @y.is_a?(Numeric)
|
||||
raise "#{self.class} 'z' must be a number" unless @z.is_a?(Numeric)
|
||||
raise "#{self.class} 'options' must be a Hash" unless @options.is_a?(Hash)
|
||||
|
||||
# raise "#{self.class} 'padding' must be a number" unless @padding.is_a?(Numeric)
|
||||
|
||||
@enabled = true
|
||||
@visible = true
|
||||
stylize
|
||||
|
||||
default_events
|
||||
end
|
||||
|
||||
def stylize
|
||||
@style.width = @style.width || $window.width
|
||||
@style.height = @style.height || $window.height
|
||||
|
||||
set_border_thickness(@style.border_thickness)
|
||||
|
||||
set_padding(@style.padding)
|
||||
|
||||
set_margin(@style.margin)
|
||||
|
||||
@style.background_canvas = Background.new
|
||||
@style.border_canvas = BorderCanvas.new(element: self)
|
||||
|
||||
set_background(@style.background)
|
||||
set_border_color(@style.border_color)
|
||||
end
|
||||
|
||||
def set_background(background)
|
||||
@style.background = background
|
||||
@style.background_canvas.background = background
|
||||
@@ -221,7 +219,6 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def reposition
|
||||
raise "#{self.class}#reposition was not overridden!"
|
||||
end
|
||||
|
||||
def value
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module CyberarmEngine
|
||||
class Style
|
||||
def initialize(hash)
|
||||
def initialize(hash = {})
|
||||
@hash = hash
|
||||
end
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ module CyberarmEngine
|
||||
raise "Error" unless self.class.ancestors.include?(CyberarmEngine::Element)
|
||||
_theme = THEME
|
||||
_theme = _theme.merge(options[:theme]) if options[:theme]
|
||||
options.delete(:theme)
|
||||
_theme.delete(:theme) if options[:theme]
|
||||
|
||||
hash = {}
|
||||
class_names = self.class.ancestors
|
||||
|
||||
Reference in New Issue
Block a user