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

[bug] TabItem Events don't work (properly) #953

Closed
tg-- opened this issue Mar 22, 2025 · 1 comment · Fixed by #956
Closed

[bug] TabItem Events don't work (properly) #953

tg-- opened this issue Mar 22, 2025 · 1 comment · Fixed by #956
Labels
bug Something isn't working

Comments

@tg--
Copy link

tg-- commented Mar 22, 2025

What happend?

Im trying to use Events on TabItems.
Since they don't support events directly, I'm using the Event() inside the Layout.
I've basically tried all possible events, but I can't get it to fire reliably at all.

As you may be able to see when running the attached example, the OnActivate event doesn't fire at all when a TabItem is activated.
However, if I Double Click on a TabItem it will fire exactly once.
To fire another time, another Event type has to be triggered first (see Tab 4).

I've also tried using a Custom() function and the EventHandler() and the behavior is the same.

Am I using it wrong, or is it broken?

giu version: v0.12.0
golang: 1.24.0

Code example

main.go
package main

import (
	g "github.com/AllenDang/giu"
)

func loop() {
	g.SingleWindow().Layout(
		g.TabBar().TabItems(
			g.TabItem("Tab 1").Layout(
				g.Event().OnActivate(func() { println("Tab1") }),
				g.Label("Test 1"),
			),
			g.TabItem("Tab 2").Layout(
				g.Event().OnActivate(func() { println("Tab2") }),
				g.Label("Test 2"),
			),
			g.TabItem("Tab 3").Layout(
				g.Event().OnActivate(func() { println("Tab3") }),
				g.Label("Test 3"),
			),
			g.TabItem("Tab 4").Layout(
				g.Event().OnDeactivate(func() { println("Tab4") }),
				g.Label("Test 4"),
			),
		),
	)
}

func main() {
	w := g.NewMasterWindow("Tab Test", 1000, 900, 0)
	w.Run(loop)
}

To Reproduce

  1. Run my demo
  2. Switch between tabs
  3. Try double clicking on a tab
  4. Switch between Tab 1-3 and 4 (other Event type).

Version

(latest, which?)

OS

Gentoo

@tg-- tg-- added the bug Something isn't working label Mar 22, 2025
@gucio321
Copy link
Collaborator

This(most likely) is because layout is built only when the tab is advice. Therefore, a similar mechanism to the TreeNodeWidget should be added (TabItem should have Event method to set EventHandler)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants