@@ -330,8 +330,8 @@ Blockly.BlockSvg.prototype.getHeightWidth = function() {
330
330
var nextBlock = this . getNextBlock ( ) ;
331
331
if ( nextBlock ) {
332
332
var nextHeightWidth = nextBlock . getHeightWidth ( ) ;
333
- height += nextHeightWidth . height - 4 ; // Height of tab.
334
- width = Math . max ( width , nextHeightWidth . width ) ;
333
+ width += nextHeightWidth . width ;
334
+ height = Math . max ( height , nextHeightWidth . height ) ;
335
335
} else if ( ! this . nextConnection && ! this . outputConnection ) {
336
336
// Add a bit of margin under blocks with no bottom tab.
337
337
height += 2 ;
@@ -814,6 +814,11 @@ Blockly.BlockSvg.NOTCH_BASE_HEIGHT = 32;
814
814
* @const
815
815
*/
816
816
Blockly . BlockSvg . NOTCH_HEIGHT = Blockly . BlockSvg . NOTCH_BASE_HEIGHT + Blockly . BlockSvg . NOTCH_RADIUS ;
817
+ /**
818
+ * Width of connector notch
819
+ * @const
820
+ */
821
+ Blockly . BlockSvg . NOTCH_WIDTH = Blockly . BlockSvg . NOTCH_BASE_HEIGHT / 4 ;
817
822
/**
818
823
* SVG path for drawing next/previous notch from top to bottom.
819
824
* @const
@@ -1320,6 +1325,8 @@ Blockly.BlockSvg.prototype.render = function(opt_bubble) {
1320
1325
this . rendered = true ;
1321
1326
1322
1327
var metrics = this . renderCompute_ ( ) ;
1328
+ this . height = metrics . height ;
1329
+ this . width = metrics . width ;
1323
1330
this . renderDraw_ ( metrics ) ;
1324
1331
1325
1332
if ( opt_bubble !== false ) {
@@ -1387,16 +1394,31 @@ Blockly.BlockSvg.prototype.render = function(opt_bubble) {
1387
1394
*/
1388
1395
Blockly . BlockSvg . prototype . renderCompute_ = function ( ) {
1389
1396
var metrics = {
1390
- hasStatement : false ,
1397
+ statement : null ,
1391
1398
icon : null ,
1392
1399
width : 0 ,
1393
- height : 0
1400
+ height : 0 ,
1401
+ bayHeight : 0 ,
1402
+ bayWidth : 0
1394
1403
} ;
1395
1404
1396
1405
// Does block have a statement?
1397
1406
for ( var i = 0 , input ; input = this . inputList [ i ] ; i ++ ) {
1398
1407
if ( input . type == Blockly . NEXT_STATEMENT ) {
1399
- metrics . hasStatement = true ;
1408
+ metrics . statement = input ;
1409
+ // Compute minimum input size.
1410
+ // @todo Why 3?
1411
+ metrics . bayHeight = Blockly . BlockSvg . NOTCH_HEIGHT + 16 +
1412
+ Blockly . BlockSvg . CORNER_RADIUS * 3 ;
1413
+ metrics . bayWidth = Blockly . BlockSvg . NOTCH_WIDTH * 2 +
1414
+ Blockly . BlockSvg . SEP_SPACE_X ;
1415
+ // Expand input size if there is a connection.
1416
+ if ( input . connection && input . connection . targetConnection ) {
1417
+ var linkedBlock = input . connection . targetBlock ( ) ;
1418
+ var bBox = linkedBlock . getHeightWidth ( ) ;
1419
+ metrics . bayHeight = Math . max ( metrics . bayHeight , bBox . height ) ;
1420
+ metrics . bayWidth = Math . max ( metrics . bayWidth , bBox . width ) ;
1421
+ }
1400
1422
}
1401
1423
1402
1424
// Find icon
@@ -1408,12 +1430,16 @@ Blockly.BlockSvg.prototype.renderCompute_ = function() {
1408
1430
}
1409
1431
1410
1432
var iconSize = ( metrics . icon ) ? metrics . icon . getSize ( ) : new goog . math . Size ( 0 , 0 ) ;
1411
- metrics . width = Blockly . BlockSvg . SEP_SPACE_X * 2 + iconSize . width ;
1433
+ metrics . width =
1434
+ Blockly . BlockSvg . SEP_SPACE_X * 2 + iconSize . width + metrics . bayWidth ;
1435
+ if ( metrics . statement ) {
1436
+ metrics . width += 2 * Blockly . BlockSvg . CORNER_RADIUS + 8 ;
1437
+ }
1412
1438
metrics . height = Math . max (
1413
1439
Blockly . BlockSvg . SEP_SPACE_Y * 2 + iconSize . height ,
1414
- Blockly . BlockSvg . NOTCH_HEIGHT + 16 + Blockly . BlockSvg . CORNER_RADIUS * 2
1440
+ Blockly . BlockSvg . NOTCH_HEIGHT + 16 + Blockly . BlockSvg . CORNER_RADIUS * 2 ,
1441
+ metrics . bayHeight + Blockly . BlockSvg . SEP_SPACE_Y
1415
1442
) ;
1416
-
1417
1443
return metrics ;
1418
1444
1419
1445
// var inputList = this.inputList;
@@ -1587,8 +1613,10 @@ Blockly.BlockSvg.prototype.renderDraw_ = function(metrics) {
1587
1613
// Position icon
1588
1614
if ( metrics . icon ) {
1589
1615
var icon = metrics . icon . getSvgRoot ( ) ;
1616
+ var iconSize = metrics . icon . getSize ( ) ;
1590
1617
icon . setAttribute ( 'transform' ,
1591
- 'translate(' + ( metrics . width - metrics . icon . getSize ( ) . width - Blockly . BlockSvg . SEP_SPACE_X / 2 ) + ',' + Blockly . BlockSvg . SEP_SPACE_Y + ')' ) ;
1618
+ 'translate(' + ( metrics . width - iconSize . width - Blockly . BlockSvg . SEP_SPACE_X / 2 ) + ',' +
1619
+ ( metrics . height - iconSize . height - Blockly . BlockSvg . SEP_SPACE_Y ) + ')' ) ;
1592
1620
// @todo RTL
1593
1621
}
1594
1622
} ;
@@ -1625,7 +1653,6 @@ Blockly.BlockSvg.prototype.renderDrawLeft_ =
1625
1653
steps . push ( Blockly . BlockSvg . HAT_TOP_LEFT_CORNER ) ;
1626
1654
steps . push ( 'V' , metrics . height - Blockly . BlockSvg . HAT_CORNER_RADIUS ) ;
1627
1655
}
1628
- this . height = metrics . height ;
1629
1656
} ;
1630
1657
1631
1658
/**
@@ -1654,32 +1681,43 @@ Blockly.BlockSvg.prototype.renderDrawBottom_ = function(steps,
1654
1681
}
1655
1682
1656
1683
// Has statement
1657
- if ( metrics . hasStatement ) {
1684
+ if ( metrics . statement ) {
1658
1685
steps . push ( 'h' , 8 ) ;
1659
1686
steps . push ( 'a' , Blockly . BlockSvg . CORNER_RADIUS + ',' +
1660
1687
Blockly . BlockSvg . CORNER_RADIUS + ' 0 0,0 ' +
1661
1688
Blockly . BlockSvg . CORNER_RADIUS + ',-' +
1662
1689
Blockly . BlockSvg . CORNER_RADIUS ) ;
1663
1690
steps . push ( 'v' , - 8 ) ;
1664
1691
steps . push ( Blockly . BlockSvg . NOTCH_PATH_UP ) ;
1665
- steps . push ( 'v' , - 50 + ( Blockly . BlockSvg . CORNER_RADIUS * 2 ) + Blockly . BlockSvg . NOTCH_HEIGHT + 8 ) ;
1692
+ // @todo Why 3?
1693
+ steps . push ( 'v' , - metrics . bayHeight + ( Blockly . BlockSvg . CORNER_RADIUS * 3 ) + Blockly . BlockSvg . NOTCH_HEIGHT + 8 ) ;
1666
1694
steps . push ( 'a' , Blockly . BlockSvg . CORNER_RADIUS + ',' +
1667
1695
Blockly . BlockSvg . CORNER_RADIUS + ' 0 0,1 ' +
1668
1696
Blockly . BlockSvg . CORNER_RADIUS + ',-' +
1669
1697
Blockly . BlockSvg . CORNER_RADIUS ) ;
1670
- steps . push ( 'h' , 20 - ( Blockly . BlockSvg . CORNER_RADIUS * 2 ) ) ;
1698
+ steps . push ( 'h' , metrics . bayWidth - ( Blockly . BlockSvg . CORNER_RADIUS * 2 ) ) ;
1671
1699
steps . push ( 'a' , Blockly . BlockSvg . CORNER_RADIUS + ',' +
1672
1700
Blockly . BlockSvg . CORNER_RADIUS + ' 0 0,1 ' +
1673
1701
Blockly . BlockSvg . CORNER_RADIUS + ',' +
1674
1702
Blockly . BlockSvg . CORNER_RADIUS ) ;
1675
- steps . push ( 'v' , 50 - ( Blockly . BlockSvg . CORNER_RADIUS * 2 ) - Blockly . BlockSvg . NOTCH_HEIGHT - 8 ) ;
1703
+ steps . push ( 'v' , metrics . bayHeight - ( Blockly . BlockSvg . CORNER_RADIUS * 3 ) - Blockly . BlockSvg . NOTCH_HEIGHT - 8 ) ;
1676
1704
steps . push ( Blockly . BlockSvg . NOTCH_PATH_DOWN ) ;
1677
1705
steps . push ( 'v' , 8 ) ;
1678
1706
steps . push ( 'a' , Blockly . BlockSvg . CORNER_RADIUS + ',' +
1679
1707
Blockly . BlockSvg . CORNER_RADIUS + ' 0 0,0 ' +
1680
1708
Blockly . BlockSvg . CORNER_RADIUS + ',' +
1681
1709
Blockly . BlockSvg . CORNER_RADIUS ) ;
1682
1710
1711
+ // Create statement connection.
1712
+ // @todo RTL
1713
+ // var connectionX = connectionsXY.x + (this.RTL ? -cursorX : cursorX + 1);
1714
+ var connectionX = connectionsXY . x + Blockly . BlockSvg . CORNER_RADIUS * 2 + 8 ;
1715
+ var connectionY = connectionsXY . y + metrics . height - Blockly . BlockSvg . CORNER_RADIUS * 2 ;
1716
+ metrics . statement . connection . moveTo ( connectionX , connectionY ) ;
1717
+ if ( metrics . statement . connection . targetConnection ) {
1718
+ metrics . statement . connection . tighten_ ( ) ;
1719
+ }
1720
+
1683
1721
// // Nested statement.
1684
1722
// var input = row[0];
1685
1723
// if (y == 0) {
0 commit comments