調査アンケート: Blockly のご利用体験についてお聞かせください
アンケートを開始
グリッド
Blockly のメイン ワークスペースには、必要に応じてグリッドを表示できます。ブロックを作成してグリッドに配置することで、よりすっきりとしたレイアウトにすることができます。これは、複数のコード グループが広範囲に分散している大規模なアプリケーションで特に役立ちます。
グリッドの設定は、Blockly の構成の一部であるオブジェクトによって定義されます。次に例を示します。
var workspace = Blockly.inject('blocklyDiv',
{toolbox: document.getElementById('toolbox'),
grid:
{spacing: 20,
length: 3,
colour: '#ccc',
snap: true},
trashcan: true});
スペース
最も重要なグリッド プロパティは、グリッドのポイント間の距離を定義する spacing
です。デフォルト値は 0 で、グリッドは存在しません。以下に、spacing
を 10、20、40 に設定する例を示します。

期間
length
プロパティは、グリッド ポイントの形状を定義する数値です。長さを 0 にするとグリッドは非表示になり(ただしスナップ可能なグリッド)、長さが 1 の場合(デフォルト値)、ドットがドットに、より長いとクロスになります。間隔より大きいとグラフ用紙になります。以下に、length
を 1、5、20 に設定する例を示します。

色
colour
プロパティは、ポイントの色を設定する文字列です。イギリスのスペルに注意してください。#f00
、#ff0000
、rgb(255, 0, 0)
など、任意の CSS 互換形式を使用します。デフォルト値は #888
です。colour
を #000
、#ccc
、#f00
に設定する例を次に示します。

Snap
snap
プロパティは、ワークスペースに配置されたときにブロックを最も近いグリッド ポイントにスナップするかどうかを設定するブール値です。デフォルト値は false
です。

特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2023-12-01 UTC。
[null,null,["最終更新日 2023-12-01 UTC。"],[[["Blockly workspaces can have an optional grid to help organize blocks, especially in larger projects."],["The grid is customizable with properties like spacing, length, color, and snap, which are configured within Blockly's options."],["Grid spacing controls the distance between grid points, length determines the visual shape of grid points, color sets the color of the grid, and snap enables or disables block snapping to the grid."]]],["Blockly's workspace grid is configured via `spacing`, `length`, `colour`, and `snap` properties within the workspace configuration. `Spacing` defines the distance between grid points, with a default of 0 (no grid). `Length` shapes the grid points (dots, crosses, or graph paper). `Colour` sets the grid's color using CSS formats. `Snap` determines if blocks align to the grid, defaulting to `false`. Activating snap enables a more organized layout.\n"]]