Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example of (*InputTextWidget).Callback usage #461

Closed
gucio321 opened this issue Feb 16, 2022 · 9 comments
Closed

example of (*InputTextWidget).Callback usage #461

gucio321 opened this issue Feb 16, 2022 · 9 comments

Comments

@gucio321
Copy link
Collaborator

I can't see any example of using imgui.InputTextCallback.
is it possible to add one to examples/?

@AllenDang
Copy link
Owner

Sure, I'll add one later today.

@AllenDang
Copy link
Owner

AllenDang commented Feb 18, 2022

Oh, I cannot add it into this repo cause using imgui.InputTextCallback will add reference of imgui into the go.mod.
The usage should be very straight forward, define a callback function and pass it to InputText(..).Callback() and check the document of imgui.

@gucio321
Copy link
Collaborator Author

Oh, I cannot add it into this repo cause using imgui.InputTextCallback will add reference of imgui into the go.mod

Hmm but the referencje to your imguigo already is present in gomod

The usage should be very straight forward, define a callback function and pass it to InputText(..).Callback() and check the document of imgui..

That's the problem. I cannot figurę out how to use this callback xd

@AllenDang
Copy link
Owner

@gucio321 Can you explain more detail about the use case you are trying to archive?

@gucio321
Copy link
Collaborator Author

@AllenDang generally, I was trying to solve #460 and wondering, why the following code doesn't work as I expect

package main

import (
	"fmt"

	"github.com/AllenDang/giu"
	"github.com/AllenDang/imgui-go"
)

var container string

func loop() {
	giu.SingleWindow().Layout(
		giu.InputText(&container).Callback(func(i imgui.InputTextCallbackData) int32 {
			fmt.Println("input text callback for ", i)
			return 1
		}),
	)
}

func main() {
	wnd := giu.NewMasterWindow("issue 461 [Demo]", 640, 480, 0)
	wnd.Run(loop)
}

what imgui.InputTextCallback is supposed to do exactly?

@AllenDang
Copy link
Owner

@gucio321 Generally speaking, InputTextCallback is used to filter the input string. Here is the reference from C++.

                // Return 0 (pass) if the character is 'i' or 'm' or 'g' or 'u' or 'i'
                static int FilterImGuiLetters(ImGuiInputTextCallbackData* data)
                {
                    if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar))
                        return 0;
                    return 1;
                }

@gucio321
Copy link
Collaborator Author

gucio321 commented Feb 28, 2022

yah @AllenDang but my code from previous post isn't caled at any time (I dont recieve log at all)

@gucio321
Copy link
Collaborator Author

gucio321 commented Mar 6, 2022

hmm @AllenDang I've implemented your code and it doesn't work

code
package main

import (
	"strings"

	"github.com/AllenDang/giu"
	"github.com/AllenDang/imgui-go"
)

var container string

func loop() {
	giu.SingleWindow().Layout(
		giu.InputText(&container).Callback(func(i imgui.InputTextCallbackData) int32 {
			if strings.Contains("imgui", string(i.EventChar())) {
				return 0
			}
			return 1
		}),
	)
}

func main() {
	wnd := giu.NewMasterWindow("issue 461 [Demo]", 640, 480, 0)
	wnd.Run(loop)
}

what am I doing wrong?

@gucio321
Copy link
Collaborator Author

gucio321 commented May 8, 2023

Need to specify (one or more of) InputTextFlagsCallback* flags (see #660 #460 #434)

@gucio321 gucio321 closed this as completed May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants