diff --git a/lib/cyberarm_engine/ui/dsl.rb b/lib/cyberarm_engine/ui/dsl.rb index d811968..0b742c6 100644 --- a/lib/cyberarm_engine/ui/dsl.rb +++ b/lib/cyberarm_engine/ui/dsl.rb @@ -2,6 +2,7 @@ module CyberarmEngine module DSL def flow(options = {}, &block) options[:parent] = @containers.last + options[:theme] = @current_theme _container = Flow.new(options, block) @containers << _container _container.build @@ -13,6 +14,7 @@ module CyberarmEngine def stack(options = {}, &block) options[:parent] = @containers.last + options[:theme] = @current_theme _container = Stack.new(options, block) @containers << _container _container.build @@ -24,6 +26,7 @@ module CyberarmEngine def label(text, options = {}, &block) options[:parent] = @containers.last + options[:theme] = @current_theme _element = Label.new(text, options, block) @containers.last.add(_element) @@ -32,6 +35,7 @@ module CyberarmEngine def button(text, options = {}, &block) options[:parent] = @containers.last + options[:theme] = @current_theme _element = Button.new(text, options, block) { if block.is_a?(Proc); block.call; end } @containers.last.add(_element) @@ -40,6 +44,7 @@ module CyberarmEngine def edit_line(text, options = {}, &block) options[:parent] = @containers.last + options[:theme] = @current_theme _element = EditLine.new(text, options, block) @containers.last.add(_element) @@ -48,6 +53,7 @@ module CyberarmEngine def toggle_button(options = {}, &block) options[:parent] = @containers.last + options[:theme] = @current_theme _element = ToggleButton.new(options, block) @containers.last.add(_element) @@ -56,6 +62,7 @@ module CyberarmEngine def check_box(text, options = {}, &block) options[:parent] = @containers.last + options[:theme] = @current_theme _element = CheckBox.new(text, options, block) @containers.last.add(_element) @@ -64,6 +71,7 @@ module CyberarmEngine def image(path, options = {}, &block) options[:parent] = @containers.last + options[:theme] = @current_theme _element = Image.new(path, options, block) @containers.last.add(_element) @@ -78,5 +86,9 @@ module CyberarmEngine def color(color) @containers.last.color(color) end + + def set_theme(theme) + @current_theme = theme + end end end \ No newline at end of file diff --git a/lib/cyberarm_engine/ui/element.rb b/lib/cyberarm_engine/ui/element.rb index 2c6999b..429850c 100644 --- a/lib/cyberarm_engine/ui/element.rb +++ b/lib/cyberarm_engine/ui/element.rb @@ -15,7 +15,7 @@ module CyberarmEngine def initialize(options = {}, block = nil) @parent = options[:parent] # parent Container (i.e. flow/stack) - options = theme_defaults.merge(options) + options = theme_defaults(options) @options = options @block = block @@ -206,6 +206,10 @@ module CyberarmEngine raise "#{self.class}#recalculate was not overridden!" end + def reposition + raise "#{self.class}#reposition was not overridden!" + end + def value raise "#{self.class}#value was not overridden!" end diff --git a/lib/cyberarm_engine/ui/theme.rb b/lib/cyberarm_engine/ui/theme.rb index b8fb5f9..2c22c70 100644 --- a/lib/cyberarm_engine/ui/theme.rb +++ b/lib/cyberarm_engine/ui/theme.rb @@ -9,21 +9,24 @@ module CyberarmEngine value end - def theme_defaults + def theme_defaults(options) raise "Error" unless self.class.ancestors.include?(CyberarmEngine::Element) + _theme = THEME + _theme = _theme.merge(options[:theme]) if options[:theme] + options.delete(:theme) hash = {} class_names = self.class.ancestors class_names = class_names[0..class_names.index(CyberarmEngine::Element)].map! {|c| c.to_s.split("::").last.to_sym}.reverse! class_names.each do |klass| - next unless data = THEME.dig(klass) + next unless data = _theme.dig(klass) data.each do |key, value| hash.merge!(data) end end - hash + hash.merge(options) end THEME = { @@ -86,6 +89,6 @@ module CyberarmEngine ToggleButton: { # < Button checkmark: "√" } - } + }.freeze end end \ No newline at end of file