2015-08-22 17:30:27 +02:00
|
|
|
|
|
|
|
class BlocksView < ListView
|
2015-08-21 00:37:41 +02:00
|
|
|
|
|
|
|
def initialize interpreter
|
|
|
|
@interpreter = interpreter
|
|
|
|
@interpreter.register_event(:instruction_changed, self)
|
2015-10-21 13:05:18 +02:00
|
|
|
@interpreter.register_event(:state_changed, self)
|
|
|
|
show = []
|
2015-10-27 11:46:53 +01:00
|
|
|
show << LabelView.new(@interpreter.instruction) if @interpreter.instruction.is_a?(Register::Label)
|
2015-10-21 13:05:18 +02:00
|
|
|
super(show)
|
2015-08-21 00:37:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def draw
|
2015-08-22 17:30:27 +02:00
|
|
|
super()
|
2015-10-27 11:46:53 +01:00
|
|
|
wrap_element div("div.label_view") << div("h4" , "Method + Block " ) << div("h4.method" , @method_name)
|
2015-08-22 17:30:27 +02:00
|
|
|
return @element
|
2015-08-21 00:37:41 +02:00
|
|
|
end
|
|
|
|
|
2015-08-22 18:37:42 +02:00
|
|
|
def instruction_changed
|
2015-10-27 11:46:53 +01:00
|
|
|
return unless @interpreter.instruction.is_a?(Register::Label)
|
2015-10-21 13:05:18 +02:00
|
|
|
if @children.last
|
2015-10-27 11:46:53 +01:00
|
|
|
return if @interpreter.instruction.object_id == @children.last.label.object_id
|
2015-10-21 13:05:18 +02:00
|
|
|
@elements.last.at_css(".bright").remove_class("bright")
|
|
|
|
end
|
2015-10-27 11:46:53 +01:00
|
|
|
append_view( LabelView.new(@interpreter.instruction) )
|
2015-08-24 02:04:07 +02:00
|
|
|
remove_first if( @elements.length > 6)
|
2015-08-21 00:37:41 +02:00
|
|
|
end
|
2015-08-22 18:37:42 +02:00
|
|
|
|
2015-10-21 13:05:18 +02:00
|
|
|
def state_changed old , new_s
|
|
|
|
return unless new_s == :running
|
|
|
|
clear_view
|
|
|
|
end
|
|
|
|
|
2015-08-21 00:37:41 +02:00
|
|
|
end
|
2015-08-24 01:49:41 +02:00
|
|
|
|
2015-10-27 11:46:53 +01:00
|
|
|
class LabelView < ElementView
|
2015-08-24 01:49:41 +02:00
|
|
|
|
2015-10-27 11:46:53 +01:00
|
|
|
def initialize label
|
|
|
|
@label = label
|
2015-08-24 01:49:41 +02:00
|
|
|
end
|
2015-10-27 11:46:53 +01:00
|
|
|
attr_reader :label
|
2015-08-24 01:49:41 +02:00
|
|
|
|
|
|
|
def draw
|
2015-10-27 11:46:53 +01:00
|
|
|
@element = div("div") << div("span.bright" , label_name )
|
2015-08-24 02:19:41 +02:00
|
|
|
end
|
|
|
|
|
2015-10-27 11:46:53 +01:00
|
|
|
def label_name
|
|
|
|
return @label if @label.is_a? String
|
|
|
|
@label.name
|
2015-08-24 01:49:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|