roblillack / spot

React-like desktop GUI toolkit for Go
MIT License
1.09k stars 15 forks source link

TextEditor: How to get a TextEditor's content ? #21

Closed zrcoder closed 2 months ago

zrcoder commented 2 months ago

It always be empty when I print the content of the TextEditor, test code is below:

package main

import (
    "fmt"

    "github.com/roblillack/spot"
    "github.com/roblillack/spot/ui"
)

func main() {
    ui.Init()

    spot.MountFn(func(ctx *spot.RenderContext) spot.Component {
        content, setContent := spot.UseState(ctx, "")

        return &ui.Window{
            Title: "Test",
            Width: 800, Height: 600,
            Children: []spot.Component{
                &ui.Button{
                    X: 10, Y: 10, Width: 780, Height: 20,
                    Title: "OK",
                    OnClick: func() {
                        fmt.Println("content of the textEditor is:", content) // content is always empty here
                    },
                },
                &ui.TextEditor{
                    X: 10, Y: 30, Width: 780, Height: 560,
                    Text:     content,
                    OnChange: setContent,
                },
            },
        }
    })

    ui.Run()
}
roblillack commented 2 months ago

Hi @zrcoder, you seem to be using Cocoa. This was a bug, which was just fixed with a contribution by @Suremeo in #20. What coincidence!

If you try again with the main branch, things should be working now. Can you confirm?

zrcoder commented 2 months ago

Hi @zrcoder, you seem to be using Cocoa. This was a bug, which was just fixed with a contribution by @Suremeo in #20. What coincidence!

If you try again with the main branch, things should be working now. Can you confirm?

Yes, I used spot on my mac, and the code works with the main branch. Thanks a lot, spot is very good, easy enouph to use.