registers ticking, but objects not showing
This commit is contained in:
parent
ed2a054ca6
commit
68f67eda54
14
lib/base/constant_view.rb
Normal file
14
lib/base/constant_view.rb
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
require_relative "element_view"
|
||||||
|
|
||||||
|
class ConstantView < ElementView
|
||||||
|
|
||||||
|
def initialize class_or_id , text = nil
|
||||||
|
@class_or_id = class_or_id
|
||||||
|
@text = text
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw
|
||||||
|
@element = div(@class_or_id , @text)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -4,10 +4,20 @@ class ElementView
|
|||||||
@element = nil
|
@element = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#abstract function that should return the single element that is being represented
|
||||||
|
# the element is also stored in @element
|
||||||
def draw
|
def draw
|
||||||
raise "implement me to return an Element"
|
raise "implement me to return an Element"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# helper function to create an element with possible classes, id and text
|
||||||
|
# The first argument is a bit haml inspired, so "tagname.classname" is the format
|
||||||
|
# but if tagname is ommited it will default to div
|
||||||
|
# also several classnames may be given
|
||||||
|
# if one of the names ends in a ! (bang) it will be assigned as the id
|
||||||
|
# second argument is optional, but if given will be added as text (content) to the newly
|
||||||
|
# created Element
|
||||||
|
# return the new Element, which is not linked into the dom at that point (see << and add*)
|
||||||
def div name_class , text = nil
|
def div name_class , text = nil
|
||||||
name , clazz = name_class.split(".")
|
name , clazz = name_class.split(".")
|
||||||
name = "div" if name.empty?
|
name = "div" if name.empty?
|
||||||
@ -46,9 +56,19 @@ class ElementView
|
|||||||
wrapper << node
|
wrapper << node
|
||||||
end
|
end
|
||||||
|
|
||||||
def add class_or_id , tex = nil
|
# add the given element the @element
|
||||||
element = div( class_or_id , tex)
|
# return the div that was passed in (use << to return the @element)
|
||||||
element.append_to @element
|
def add_element div
|
||||||
element
|
div.append_to @element
|
||||||
|
div
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# create a new element with class and possibly text
|
||||||
|
# add that new element to the @element
|
||||||
|
# return the newly created element
|
||||||
|
def add class_or_id , tex = nil
|
||||||
|
add_element div( class_or_id , tex)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -7,18 +7,31 @@ class ListView < ElementView
|
|||||||
@elements = []
|
@elements = []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# can be overriden to return a string that will be passed to div to create the root
|
||||||
|
# element for the list. See "div" in ElementView for possible strings
|
||||||
def root
|
def root
|
||||||
"div"
|
"div"
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw on
|
# create a root node acording to the "root" function (default div)
|
||||||
|
# draw all chilren and keep the elements as @elements
|
||||||
|
# return (as per base class) the single root of the collection
|
||||||
|
def draw
|
||||||
@element = div(self.root)
|
@element = div(self.root)
|
||||||
@elements = @children.collect do | c |
|
@elements = @children.collect do | c |
|
||||||
elem = c.draw(@element)
|
add_element c.draw
|
||||||
elem.append_to(@element)
|
|
||||||
elem
|
|
||||||
end
|
end
|
||||||
@element
|
@element
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# replace the child at index with the given one (second arg)
|
||||||
|
# The child must be an ElementView , which will be rendered and
|
||||||
|
# the old node will be replaces in the live dom
|
||||||
|
def replace_at index , with
|
||||||
|
old = @elements[index]
|
||||||
|
@chilren[index] = with
|
||||||
|
rendered = with.draw
|
||||||
|
@elements[index] = rendered
|
||||||
|
old.replace_with rendered
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -59,7 +59,4 @@ class ObjectView
|
|||||||
fields
|
fields
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_object?( id )
|
|
||||||
Virtual.machine.objects[id] != nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -18,8 +18,8 @@ class RegistersView < ListView
|
|||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
list = super()
|
super()
|
||||||
list = list.children.each do |reg|
|
@element.children.each do |reg|
|
||||||
elem = div("div.register_view")
|
elem = div("div.register_view")
|
||||||
wrap_node_with reg , elem
|
wrap_node_with reg , elem
|
||||||
end
|
end
|
||||||
@ -28,9 +28,17 @@ class RegistersView < ListView
|
|||||||
|
|
||||||
def register_changed reg , old , value
|
def register_changed reg , old , value
|
||||||
reg = reg.symbol unless reg.is_a? Symbol
|
reg = reg.symbol unless reg.is_a? Symbol
|
||||||
return unless reg == register
|
index = reg.to_s[1 .. -1 ].to_i
|
||||||
objects_id! value
|
if( is_object? value )
|
||||||
calc_fields
|
swap = ObjectView.new( value )
|
||||||
|
else
|
||||||
|
swap = ValueView.new value
|
||||||
|
end
|
||||||
|
replace_at index , swap
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_object?( id )
|
||||||
|
Virtual.machine.objects[id] != nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def calc_fields
|
def calc_fields
|
||||||
|
Loading…
Reference in New Issue
Block a user