無料・軽快な 2D / 3D 用のゲームエンジン Godot Engine 4 で、ラベルやボタンなどの Control 派生ノードを配置する際に指示するフラグとして用いられる size_flags_horizontal / vertical / stretch_ratio メンバ変数を有効にするため、Container 派生ノードをコントロールの上位ノードに追加します。

※ GodotEngine 4.3 を使用しています。.NET 版ではありません。
※スクリプトは自己責任でご使用ください
size_flags 3変数はコンテナ直下でないと表示されない
以下の構成でシーンを作成しました。
※メニュー「シーン」→「新規シーン」の後、シーンドックで「ユーザーインターフェース」を選ぶと Control クラスがルートノードのシーンが作成されます。
※見やすさのために、Label, Button には、フォントサイズと背景色( normal )を定義した共通のテーマファイルを割り当てています。
- Control
- Label (Control 派生)
- Button (Control 派生)
コントロール群(例:Label, Button)を選択して、インスペクタードックの Control クラスの Layout セクションを広げると「このノードは通常のコントロールの子です。」というメッセージが表示されています。
そして、 size_flags_horizontal / vertical / stretch_ratio メンバ変数を編集する UI は表示されません。

size_flags は上位コンテナに配置の指示を与える変数群
Control のメンバ変数 size_flags_horizontal, size_flags_vertical, size_flags_stretch_ratio は、上位のコンテナがコントロールの配置を決めるためのフラグです。
そのため、インスペクタードックでは上位ノードがコンテナ派生ではない場合は表示されません。
引用の説明でも「上位のコンテナに指示する」という説明があるので、おそらく、スクリプトで設定したとしても、上位ノードがコンテナではない場合は、効果がありません。
BitField[SizeFlags] size_flags_horizontal =
1Tells the parent Container nodes how they should resize and place the node on the X axis. Use a combination of the SizeFlags constants to change the flags. See the constants to learn what each does.
親コンテナ ノードに、ノードのサイズ変更と X 軸上での配置方法を指示します。フラグを変更するには、SizeFlags 定数を組み合わせて使用します。それぞれの機能については定数を参照してください。
Control — Godot Engine (4.3) documentation in English #size_flags_horizontal と Google 翻訳
BitField[SizeFlags] size_flags_vertical =
1Tells the parent Container nodes how they should resize and place the node on the Y axis. Use a combination of the SizeFlags constants to change the flags. See the constants to learn what each does.
親コンテナ ノードに、ノードのサイズ変更と Y 軸上での配置方法を指示します。フラグを変更するには、SizeFlags 定数を組み合わせて使用します。それぞれの機能については定数を参照してください。
Control — Godot Engine (4.3) documentation in English #size_flags_vertical と Google 翻訳
float size_flags_stretch_ratio =
1.0If the node and at least one of its neighbors uses the SIZE_EXPAND size flag, the parent Container will let it take more or less space depending on this property. If this node has a stretch ratio of 2 and its neighbor a ratio of 1, this node will take two thirds of the available space.
ノードとその隣接ノードの少なくとも 1 つが SIZE_EXPAND サイズ フラグを使用する場合、親コンテナは、このプロパティに応じて、そのノードに必要なスペースを増減させます。このノードの伸縮率が 2 で、隣接するノードの伸縮率が 1 の場合、このノードは利用可能なスペースの 3 分の 2 を占有します。
Control — Godot Engine (4.3) documentation in English#size_flags_stretch_ratio と Google 翻訳
コントロールをコンテナの配下にして size_flags 変数群を有効にする
コントロールの上位にコンテナの派生クラス HBoxContainer ノードを追加して、size_flags_horizontal / vertical / stretch_ratio メンバ変数を有効にして、インスペクタードックに表示します。
※他の Container 派生ノードでも同様です。
HBoxContainer ノードをシーンに追加した後、既存のコントロール群(例: Label, Button)を複数選択してから HBoxContainer ノードの下位に移動するようにドラッグ&ドロップします。

Container 派生ノードの配下になったラベルやボタンなどの Control 派生ノードをシーンドックで選択して、インスペクタードックの Control クラスの Layout セクションを開くと、size_flags_horizontal / vertical / stretch_ratio メンバ変数を編集する Container Sizing セクションが表示されました。

テーマファイルについて
テーマファイルによる背景色などの設定については以下の記事を参照してください。
まとめ
- Control 派生ノードの配置方法を指示するフラグを持つ size_flags_horizontal / vertical / stretch_ratio メンバ変数は、Container 派生ノードの配下でないとインスペクタードックに表示されません。
- size_flags_horizontal / vertical / stretch_ratio メンバ変数は、インスペクタードックの Control クラスの Layout → Container Sizing セクションで編集できます。
参照サイト Thank You!
- Godot Engine – Free and open source 2D and 3D game engine
- サイズとアンカー — Godot Engine (4.x)の日本語のドキュメント
- Container — Godot Engine (4.3) documentation in English
- HBoxContainer — Godot Engine (4.3) documentation in English
- Control — Godot Engine (4.3) documentation in English
- Control — Godot Engine (4.3) documentation in English #size_flags_horizontal
- Control — Godot Engine (4.3) documentation in English #size_flags_vertical
- Control — Godot Engine (4.3) documentation in English#size_flags_stretch_ratio
記事一覧 → Compota-Soft-Press



コメント