mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-17 13:32:34 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 34d53ae1cb | |||
| 74d1ddd16b | |||
| da69f057a0 | |||
| 4f4770db0e | |||
| b6730204e8 | |||
| d8dc621c62 |
@@ -21,6 +21,14 @@ module CyberarmEngine
|
|||||||
recalculate
|
recalculate
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def value
|
||||||
|
@toggle_button.value
|
||||||
|
end
|
||||||
|
|
||||||
|
def value=(bool)
|
||||||
|
@toggle_button.vlaue = bool
|
||||||
|
end
|
||||||
|
|
||||||
def define_label_singletons
|
def define_label_singletons
|
||||||
@label.define_singleton_method(:_toggle_button) do |button|
|
@label.define_singleton_method(:_toggle_button) do |button|
|
||||||
@_toggle_button = button
|
@_toggle_button = button
|
||||||
|
|||||||
@@ -64,12 +64,17 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def recalculate
|
def recalculate
|
||||||
@current_position = Vector.new(@margin_left, @margin_top)
|
@current_position = Vector.new(@margin_left + @padding_left, @margin_top + @padding_top)
|
||||||
|
unless @visible
|
||||||
|
@width = 0
|
||||||
|
@height= 0
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
layout
|
layout
|
||||||
|
|
||||||
@width = @max_width ? @max_width : (@children.map {|c| c.x + c.width + c.margin_right }.max || 0).round
|
@width = @max_width ? @max_width : (@children.map {|c| c.x + c.outer_width }.max || 0).round
|
||||||
@height = @max_height ? @max_height : (@children.map {|c| c.y + c.height + c.margin_bottom}.max || 0).round
|
@height = @max_height ? @max_height : (@children.map {|c| c.y + c.outer_height}.max || 0).round
|
||||||
|
|
||||||
# Move child to parent after positioning
|
# Move child to parent after positioning
|
||||||
@children.each do |child|
|
@children.each do |child|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ module CyberarmEngine
|
|||||||
module DSL
|
module DSL
|
||||||
def flow(options = {}, &block)
|
def flow(options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_container = Flow.new(options, block)
|
_container = Flow.new(options, block)
|
||||||
@containers << _container
|
@containers << _container
|
||||||
_container.build
|
_container.build
|
||||||
@@ -13,6 +14,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def stack(options = {}, &block)
|
def stack(options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_container = Stack.new(options, block)
|
_container = Stack.new(options, block)
|
||||||
@containers << _container
|
@containers << _container
|
||||||
_container.build
|
_container.build
|
||||||
@@ -24,6 +26,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def label(text, options = {}, &block)
|
def label(text, options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_element = Label.new(text, options, block)
|
_element = Label.new(text, options, block)
|
||||||
@containers.last.add(_element)
|
@containers.last.add(_element)
|
||||||
|
|
||||||
@@ -32,6 +35,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def button(text, options = {}, &block)
|
def button(text, options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_element = Button.new(text, options, block) { if block.is_a?(Proc); block.call; end }
|
_element = Button.new(text, options, block) { if block.is_a?(Proc); block.call; end }
|
||||||
@containers.last.add(_element)
|
@containers.last.add(_element)
|
||||||
|
|
||||||
@@ -40,6 +44,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def edit_line(text, options = {}, &block)
|
def edit_line(text, options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_element = EditLine.new(text, options, block)
|
_element = EditLine.new(text, options, block)
|
||||||
@containers.last.add(_element)
|
@containers.last.add(_element)
|
||||||
|
|
||||||
@@ -48,6 +53,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def toggle_button(options = {}, &block)
|
def toggle_button(options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_element = ToggleButton.new(options, block)
|
_element = ToggleButton.new(options, block)
|
||||||
@containers.last.add(_element)
|
@containers.last.add(_element)
|
||||||
|
|
||||||
@@ -56,6 +62,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def check_box(text, options = {}, &block)
|
def check_box(text, options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_element = CheckBox.new(text, options, block)
|
_element = CheckBox.new(text, options, block)
|
||||||
@containers.last.add(_element)
|
@containers.last.add(_element)
|
||||||
|
|
||||||
@@ -64,6 +71,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def image(path, options = {}, &block)
|
def image(path, options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_element = Image.new(path, options, block)
|
_element = Image.new(path, options, block)
|
||||||
@containers.last.add(_element)
|
@containers.last.add(_element)
|
||||||
|
|
||||||
@@ -78,5 +86,9 @@ module CyberarmEngine
|
|||||||
def color(color)
|
def color(color)
|
||||||
@containers.last.color(color)
|
@containers.last.color(color)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_theme(theme)
|
||||||
|
@current_theme = theme
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -56,6 +56,9 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def leave(sender)
|
def leave(sender)
|
||||||
|
unless @focus
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def blur(sender)
|
def blur(sender)
|
||||||
@@ -77,6 +80,12 @@ module CyberarmEngine
|
|||||||
def recalculate
|
def recalculate
|
||||||
super
|
super
|
||||||
|
|
||||||
|
unless @visible
|
||||||
|
@width = 0
|
||||||
|
@height= 0
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
@width = default(:width)
|
@width = default(:width)
|
||||||
update_background
|
update_background
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def initialize(options = {}, block = nil)
|
def initialize(options = {}, block = nil)
|
||||||
@parent = options[:parent] # parent Container (i.e. flow/stack)
|
@parent = options[:parent] # parent Container (i.e. flow/stack)
|
||||||
options = theme_defaults.merge(options)
|
options = theme_defaults(options)
|
||||||
@options = options
|
@options = options
|
||||||
@block = block
|
@block = block
|
||||||
|
|
||||||
@@ -53,6 +53,7 @@ module CyberarmEngine
|
|||||||
# raise "#{self.class} 'padding' must be a number" unless @padding.is_a?(Numeric)
|
# raise "#{self.class} 'padding' must be a number" unless @padding.is_a?(Numeric)
|
||||||
|
|
||||||
@enabled = true
|
@enabled = true
|
||||||
|
@visible = true
|
||||||
|
|
||||||
default_events
|
default_events
|
||||||
end
|
end
|
||||||
@@ -122,7 +123,28 @@ module CyberarmEngine
|
|||||||
@enabled
|
@enabled
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def visible?
|
||||||
|
@visible
|
||||||
|
end
|
||||||
|
|
||||||
|
def toggle
|
||||||
|
@visible = !@visible
|
||||||
|
root.recalculate
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@visible = true
|
||||||
|
root.recalculate
|
||||||
|
end
|
||||||
|
|
||||||
|
def hide
|
||||||
|
@visible = false
|
||||||
|
root.recalculate
|
||||||
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
|
return unless @visible
|
||||||
|
|
||||||
@background_canvas.draw
|
@background_canvas.draw
|
||||||
@border_canvas.draw
|
@border_canvas.draw
|
||||||
render
|
render
|
||||||
@@ -206,6 +228,10 @@ module CyberarmEngine
|
|||||||
raise "#{self.class}#recalculate was not overridden!"
|
raise "#{self.class}#recalculate was not overridden!"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reposition
|
||||||
|
raise "#{self.class}#reposition was not overridden!"
|
||||||
|
end
|
||||||
|
|
||||||
def value
|
def value
|
||||||
raise "#{self.class}#value was not overridden!"
|
raise "#{self.class}#value was not overridden!"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def recalculate
|
def recalculate
|
||||||
|
unless @visible
|
||||||
|
@width = 0
|
||||||
|
@height= 0
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
@width = @image.width * @scale_x
|
@width = @image.width * @scale_x
|
||||||
@height = @image.height * @scale_y
|
@height = @image.height * @scale_y
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def recalculate
|
def recalculate
|
||||||
|
unless @visible
|
||||||
|
@width = 0
|
||||||
|
@height= 0
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
@width = @text.width.round
|
@width = @text.width.round
|
||||||
@height= @text.height.round
|
@height= @text.height.round
|
||||||
|
|
||||||
|
|||||||
@@ -9,21 +9,24 @@ module CyberarmEngine
|
|||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
def theme_defaults
|
def theme_defaults(options)
|
||||||
raise "Error" unless self.class.ancestors.include?(CyberarmEngine::Element)
|
raise "Error" unless self.class.ancestors.include?(CyberarmEngine::Element)
|
||||||
|
_theme = THEME
|
||||||
|
_theme = _theme.merge(options[:theme]) if options[:theme]
|
||||||
|
options.delete(:theme)
|
||||||
|
|
||||||
hash = {}
|
hash = {}
|
||||||
class_names = self.class.ancestors
|
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 = class_names[0..class_names.index(CyberarmEngine::Element)].map! {|c| c.to_s.split("::").last.to_sym}.reverse!
|
||||||
|
|
||||||
class_names.each do |klass|
|
class_names.each do |klass|
|
||||||
next unless data = THEME.dig(klass)
|
next unless data = _theme.dig(klass)
|
||||||
data.each do |key, value|
|
data.each do |key, value|
|
||||||
hash.merge!(data)
|
hash.merge!(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
hash
|
hash.merge(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
THEME = {
|
THEME = {
|
||||||
@@ -86,6 +89,6 @@ module CyberarmEngine
|
|||||||
ToggleButton: { # < Button
|
ToggleButton: { # < Button
|
||||||
checkmark: "√"
|
checkmark: "√"
|
||||||
}
|
}
|
||||||
}
|
}.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -38,6 +38,12 @@ module CyberarmEngine
|
|||||||
def recalculate
|
def recalculate
|
||||||
super
|
super
|
||||||
|
|
||||||
|
unless @visible
|
||||||
|
@width = 0
|
||||||
|
@height= 0
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
@width = @text.textobject.text_width(@options[:checkmark])
|
@width = @text.textobject.text_width(@options[:checkmark])
|
||||||
update_background
|
update_background
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module CyberarmEngine
|
module CyberarmEngine
|
||||||
NAME = "InDev"
|
NAME = "InDev"
|
||||||
VERSION = "0.5.1"
|
VERSION = "0.7.1"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user