@@ -1,24 +1,47 @@
|
|||||||
import Godot from "godot"
|
import Godot, { Vector2 } from "godot"
|
||||||
import { Component } from "react-godot-renderer"
|
import { Component } from "react-godot-renderer"
|
||||||
|
|
||||||
|
|
||||||
const CenterContainer = Component.fromClass(Godot.CenterContainer)
|
const CenterContainer = Component.fromClass(Godot.CenterContainer)
|
||||||
const VFlowContainer = Component.fromClass(Godot.VFlowContainer)
|
const PanelContainer = Component.fromClass(Godot.PanelContainer)
|
||||||
|
const MarginContainer = Component.fromClass(Godot.MarginContainer)
|
||||||
|
const VBoxContainer = Component.fromClass(Godot.VBoxContainer)
|
||||||
const Label = Component.fromClass(Godot.Label)
|
const Label = Component.fromClass(Godot.Label)
|
||||||
|
const TextEdit = Component.fromClass(Godot.TextEdit)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A form UI where React controls the state
|
* A form UI where React controls the state
|
||||||
*/
|
*/
|
||||||
export function ControlledFormRoot() {
|
export function ControlledFormRoot() {
|
||||||
|
const rootRef = CenterContainer.useRef()
|
||||||
|
Component.useSignal(rootRef, "ready", () => {
|
||||||
|
console.log("ready")
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CenterContainer
|
<CenterContainer
|
||||||
anchors_preset={1}
|
ref={rootRef}
|
||||||
|
anchors_preset={Godot.Control.LayoutPreset.PRESET_FULL_RECT}
|
||||||
|
>
|
||||||
|
<PanelContainer>
|
||||||
|
<MarginContainer>
|
||||||
|
<VBoxContainer>
|
||||||
|
<CenterContainer
|
||||||
|
anchors_preset={Godot.Control.LayoutPreset.PRESET_FULL_RECT}
|
||||||
>
|
>
|
||||||
<VFlowContainer>
|
|
||||||
<CenterContainer>
|
|
||||||
<Label text="Register" />
|
<Label text="Register" />
|
||||||
</CenterContainer>
|
</CenterContainer>
|
||||||
</VFlowContainer>
|
|
||||||
|
<TextEdit
|
||||||
|
custom_minimum_size={new Vector2(250, 40)}
|
||||||
|
/>
|
||||||
|
<TextEdit
|
||||||
|
custom_minimum_size={new Vector2(250, 40)}
|
||||||
|
/>
|
||||||
|
</VBoxContainer>
|
||||||
|
</MarginContainer>
|
||||||
|
</PanelContainer>
|
||||||
</CenterContainer>
|
</CenterContainer>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Node, type NodePathMap, PackedScene, ResourceLoader } from "godot"
|
import { Control, Node, type NodePathMap, PackedScene, ResourceLoader } from "godot"
|
||||||
import ReactReconciler, { type HostConfig } from "react-reconciler"
|
import ReactReconciler, { type HostConfig } from "react-reconciler"
|
||||||
import { hasProperty } from "./utils.js"
|
import { hasProperty } from "./utils.js"
|
||||||
|
|
||||||
@@ -233,4 +233,12 @@ const applyNextProps = (instance: Node<NodePathMap>, nextProps: Record<string, u
|
|||||||
throw new Error("Prop 'name' should be a string")
|
throw new Error("Prop 'name' should be a string")
|
||||||
instance.set_name(nextProps.name)
|
instance.set_name(nextProps.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (instance instanceof Control) {
|
||||||
|
if (hasProperty(nextProps, "anchors_preset")) {
|
||||||
|
if (typeof nextProps.anchors_preset !== "number")
|
||||||
|
throw new Error("Prop 'anchors_preset' should be a number")
|
||||||
|
instance.set_anchors_preset(nextProps.anchors_preset)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user