@@ -1,5 +1,5 @@
|
||||
import Godot, { Vector2 } from "godot"
|
||||
import { useEffect, useState } from "react"
|
||||
import { useState } from "react"
|
||||
import { Component } from "react-godot-renderer"
|
||||
|
||||
|
||||
@@ -11,26 +11,16 @@ const Button = Component.make(Godot.Button)
|
||||
export function TestUi1Component() {
|
||||
const [text, setText] = useState("Default text")
|
||||
|
||||
const textEditRef = TextEdit.useUnsafeRef()
|
||||
const buttonRef = Button.useUnsafeRef()
|
||||
const textEditRef = TextEdit.useRef()
|
||||
Component.useSignal(textEditRef, "text_changed", function(this) {
|
||||
setText(this.text)
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
const onTextChanged = Godot.Callable.create(() => {
|
||||
setText(textEditRef.current.text)
|
||||
})
|
||||
const buttonRef = Button.useRef()
|
||||
Component.useSignal(buttonRef, "pressed", () => {
|
||||
console.log("Pressed!")
|
||||
})
|
||||
|
||||
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 (
|
||||
<HFlowContainer
|
||||
|
||||
Reference in New Issue
Block a user