@@ -1,13 +1,37 @@
|
||||
import Godot from "godot"
|
||||
import Godot, { Vector2 } from "godot"
|
||||
import { useEffect } from "react"
|
||||
import { Component } from "react-godot-renderer"
|
||||
|
||||
|
||||
const Control = Component.make(Godot.Control)
|
||||
const HFlowContainer = Component.make(Godot.HFlowContainer)
|
||||
const Label = Component.make(Godot.Label)
|
||||
const TextEdit = Component.make(Godot.TextEdit)
|
||||
const Button = Component.make(Godot.Button)
|
||||
|
||||
export function TestUi1Component() {
|
||||
const textEditRef = TextEdit.useUnsafeRef()
|
||||
const buttonRef = Button.useUnsafeRef()
|
||||
|
||||
useEffect(() => {
|
||||
const onTextChanged = Godot.Callable.create(() => {
|
||||
console.log(textEditRef.current.text)
|
||||
})
|
||||
|
||||
textEditRef.current.text_changed.connect(onTextChanged)
|
||||
return () => { textEditRef.current.text_changed.disconnect(onTextChanged) }
|
||||
}, [textEditRef.current])
|
||||
|
||||
useEffect(() => {
|
||||
const onPressed = Godot.Callable.create(() => {
|
||||
console.log("Pressed!")
|
||||
})
|
||||
|
||||
buttonRef.current.pressed.connect(onPressed)
|
||||
return () => { buttonRef.current.pressed.disconnect(onPressed) }
|
||||
}, [buttonRef.current])
|
||||
|
||||
return (
|
||||
<Control
|
||||
<HFlowContainer
|
||||
name="Root"
|
||||
anchor_left={0}
|
||||
anchor_top={0}
|
||||
@@ -19,7 +43,18 @@ export function TestUi1Component() {
|
||||
text="This is a label"
|
||||
/>
|
||||
|
||||
<Control name="Control" />
|
||||
</Control>
|
||||
<TextEdit
|
||||
ref={textEditRef}
|
||||
name="TextEdit"
|
||||
text=""
|
||||
custom_minimum_size={new Vector2(200, 35)}
|
||||
/>
|
||||
|
||||
<Button
|
||||
ref={buttonRef}
|
||||
name="Button"
|
||||
text="Ok"
|
||||
/>
|
||||
</HFlowContainer>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user