Inline some inputs

878 views
Skip to first unread message

Daaron Dwyer

unread,
Nov 2, 2016, 9:50:04 PM11/2/16
to Blockly
Hello All,
I'd like to create a block to inline a group of key-value pairs, somewhat like the text join block, but each line with 2 inputs.
In effect, I'd like to inline every other field. Optimistically, I'd like to inline some inputs and inject a "newline" as a field in the block definition.

Any thoughts?

Cheers,
Daaron

Andrew n marshall

unread,
Nov 3, 2016, 2:36:07 AM11/3/16
to blo...@googlegroups.com
This can be achieved by following each inlined input with an empty dummy input.  If you're using JSON, its probably even easier to use multiple message/arg pairs, described here. Effectively, this inserts the dummy input automatically.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Neil Fraser

unread,
Nov 3, 2016, 6:21:12 AM11/3/16
to blo...@googlegroups.com
Andrew, can you demonstrate what you mean in the Block Factory and provide an example?  Thanks.

Andrew n marshall

unread,
Nov 3, 2016, 2:36:51 PM11/3/16
to blo...@googlegroups.com
Okay, messing around with this didn't work like I thought I did.  I expected the dummy input to start a new line even when inlineInputs is set to true. Here is what I expected to work:
https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#5g8sfz

Seems like a valid case to cover, though in talking with Rachel, its probably not something we can add to our priority list.

Rachel Fenichel

unread,
Nov 3, 2016, 2:48:45 PM11/3/16
to Blockly
If you want to hack this in place in your own code, I can offer you a starting point.  The code I'm giving you isn't going into blockly proper because it's a hack and fragile.  Caveat emptor.

To get a block that looks like this:

I defined my block here, with two value inputs, then a statement input named HIDE_ME, then two more value inputs.  I changed renderCompute_ in block_render_svg to check the name of each input and 1) not render an input named HIDE_ME and 2) make a new row if the previous input was named HIDE_ME.  Here's the diff:


diff --git a/core/block_render_svg.js b/core/block_render_svg.js

index 14c42b0..07f3d0c 100644

--- a/core/block_render_svg.js

+++ b/core/block_render_svg.js

@@ -354,17 +354,20 @@ Blockly.BlockSvg.prototype.renderCompute_ = function(iconWidth) {

   var hasStatement = false;

   var hasDummy = false;

   var lastType = undefined;

+  var lastName = '';

   var isInline = this.getInputsInline() && !this.isCollapsed();

   for (var i = 0, input; input = inputList[i]; i++) {

-    if (!input.isVisible()) {

+    if (!input.isVisible() || input.name == 'HIDE_ME') {

+      lastName = input.name;

       continue;

     }

     var row;

     if (!isInline || !lastType ||

         lastType == Blockly.NEXT_STATEMENT ||

-        input.type == Blockly.NEXT_STATEMENT) {

+        input.type == Blockly.NEXT_STATEMENT || lastName == 'HIDE_ME') {

       // Create new row.

       lastType = input.type;

+      lastName = input.name;

       row = [];

       if (isInline && input.type != Blockly.NEXT_STATEMENT) {

         row.type = Blockly.BlockSvg.INLINE;



On Thursday, November 3, 2016 at 11:36:51 AM UTC-7, Andrew n marshall wrote:
Okay, messing around with this didn't work like I thought I did.  I expected the dummy input to start a new line even when inlineInputs is set to true. Here is what I expected to work:
https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#5g8sfz

Seems like a valid case to cover, though in talking with Rachel, its probably not something we can add to our priority list.
On Thu, Nov 3, 2016 at 3:20 AM, Neil Fraser <ro...@neil.fraser.name> wrote:
Andrew, can you demonstrate what you mean in the Block Factory and provide an example?  Thanks.
On 2 November 2016 at 23:36, Andrew n marshall <a...@anm.me> wrote:
This can be achieved by following each inlined input with an empty dummy input.  If you're using JSON, its probably even easier to use multiple message/arg pairs, described here. Effectively, this inserts the dummy input automatically.
On Wed, Nov 2, 2016 at 6:50 PM, Daaron Dwyer <daa...@gmail.com> wrote:
Hello All,
I'd like to create a block to inline a group of key-value pairs, somewhat like the text join block, but each line with 2 inputs.
In effect, I'd like to inline every other field. Optimistically, I'd like to inline some inputs and inject a "newline" as a field in the block definition.

Any thoughts?

Cheers,
Daaron

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.

frm...@gmail.com

unread,
Oct 28, 2020, 12:40:11 PM10/28/20
to Blockly
Googled and this is exactly what I need :).
Is there any non-hacky to do such with current implementation?
Cheers,
Oded 

Reply all
Reply to author
Forward
0 new messages