finish off instruction view (+small rename)

This commit is contained in:
Torsten Ruger 2015-08-24 02:04:07 +02:00
parent c5a07be6ac
commit 7d214e7013
4 changed files with 22 additions and 6 deletions

View File

@ -30,7 +30,23 @@ class ListView < ElementView
old.replace_with rendered
end
def append view
# remove the first child and element (from view)
def remove_first
remove_at 0
end
# remove both child and element at given position
def remove_at index
raise "insex out of bounds #{index} => #{@children.length}" if(index >= @children.length or index < 0)
@children.delete_at( index )
element = @elements.delete_at(index)
element.remove
end
# append a View instnace to the children array
# render it and append it to the html element
# and keep a copy in @elements
def append_view view
@children << view
rendered = view.draw
@elements << rendered # add to internal array

View File

@ -17,8 +17,8 @@ class BlocksView < ListView
def instruction_changed
return if @interpreter.block.name == active_block_name
@elements.last.at_css(".bright").remove_class("bright")
append( BlockView.new(@interpreter.block) )
remove_first if( @elements.length > 5)
append_view( BlockView.new(@interpreter.block) )
remove_first if( @elements.length > 6)
new_name = method_name
return if new_name == @method_name
@method_name = new_name

View File

@ -11,9 +11,9 @@ class InstructionView < ListView
def instruction_changed
@element.at_css(".bright").remove_class("bright")
instruction = append( ConstantView.new( "span.bright" , instruction_text ) )
instruction = append_view( ConstantView.new( "span.bright" , instruction_text ) )
wrap_node_with instruction , div
remove_first if( @elements.length > 5)
remove_first if( @elements.length > 6)
end
def draw

View File

@ -31,7 +31,7 @@ class RefView < ListView
def hover
puts "hovering #{@name}"
append ObjectView.new(@value)
append_view ObjectView.new(@value)
@element.off("hover")
end