how can I force a re-render of the workspace?

2,498 views
Skip to first unread message

Jayod

unread,
Sep 9, 2015, 11:29:41 AM9/9/15
to Blockly
I'm trying out having different color schemes for the blocks.  How can I force the workspace to re-render all the blocks once I've switched their colors?

I tried calling Blockly.WorkspaceSvg.prototype.render()  but that isn't doing it.  

Jayod

unread,
Sep 9, 2015, 11:32:12 AM9/9/15
to Blockly


Just to add:  I know my colors are being reset properly because the new blocks in the flyout have the new colors.  I just cant get existing blocks in the workspace to re-draw with the new colors.

toe...@extremenetworks.com

unread,
Sep 9, 2015, 11:53:35 AM9/9/15
to Blockly
Assuming that you are literally calling Blockly.WorkspaceSvg.prototype.render() from your code, it won't work because you need to call the render() function off the workspace object and not the prototype.  For example if you were working from the code demo, you would call Code.workspace.render(); 
In theory that should actually do the job for you as that routine doesn't optimize out calling render() when block.rendered is set.  If that doesn't quite accomplish what you are going for, you could always serialize out and then reload the workspace (again using the code demo as a basis) with:

var xml = Blockly.Xml.workspaceToDom(Code.workspace);
Blockly.Xml.domToWorkspace(Code.workspace, xml);

Good luck!
  -- John

Jayod

unread,
Sep 9, 2015, 12:17:46 PM9/9/15
to Blockly
I am calling the render() function from my workspace object.  I put a console.log() message in the function to verify that the function was being called correctly, and it is.

Jayod

unread,
Sep 9, 2015, 12:29:50 PM9/9/15
to Blockly
I figured it out.  I have to actually go through the list of blocks and call setColour() on each one.  The block doesn't run color initialization every time it renders the block.
Reply all
Reply to author
Forward
0 new messages