close
The Wayback Machine - https://web.archive.org/web/20200928155234/https://github.com/libktx/ktx/issues/286
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

Actor onEnter and OnExit extension functions #286

Open
v79 opened this issue May 27, 2020 · 4 comments
Open

Actor onEnter and OnExit extension functions #286

v79 opened this issue May 27, 2020 · 4 comments
Assignees
Labels
Milestone

Comments

@v79
Copy link

@v79 v79 commented May 27, 2020

I wanted to change the style of a label on mouse hover. onEnter worked fine:

label("Load Game").cell(row = true).apply {
	onEnter {
		style = skin["mainMenuHover",Label.LabelStyle::class.java]
	}
}

But there's no corresponding onExit function. I've written one now, but wondered if there was documentation around which scene2d stage elements have actions, and which do not, and which actions they have?

For reference, here is my onEnter function. This is all new to me so hope I'm coding it correctly.

inline fun Label.onExit(crossinline listener: () -> Unit): InputListener {
	val eventListener = object : InputListener() {
		override fun exit(event: InputEvent?, x: Float, y: Float, pointer: Int, toActor: Actor?) {
			super.exit(event, x, y, pointer, toActor)
			return listener()
		}
	}
	this.addListener(eventListener)
	return eventListener
}```
@czyzby
Copy link
Member

@czyzby czyzby commented May 28, 2020

I'll be honest, I'm not sure where you got the onEnter extension from. I've searched the entire KTX project and I don't think it's ours. Can you go to the source of onEnter (CTRL + B) and post it here, @v79?

Now that you mention it, both of these functions could be pretty useful. They will be added to the ktx-actors module.

@czyzby czyzby added this to the 1.9.10 milestone May 28, 2020
@czyzby czyzby self-assigned this May 28, 2020
@czyzby czyzby added the actors label May 28, 2020
czyzby added a commit that referenced this issue May 28, 2020
@czyzby
Copy link
Member

@czyzby czyzby commented May 28, 2020

I also improved the API of the existing event listener methods, so that the apply is not necessary. Event listeners will now consume the actor as this. It will be a non-breaking change for most simple listeners.

czyzby added a commit that referenced this issue May 28, 2020
@v79
Copy link
Author

@v79 v79 commented May 28, 2020

I'll be honest, I'm not sure where you got the onEnter extension from. I've search the entire KTX project and I don't think it's ours. Can you go to the source of onEnter (CTRL + B) and post it here, @v79?

Perhaps I shouldn't raise defects after 10pm - apologies! I had written an onEnter extension function on Actor for debugging purposes and had long forgotten about it. My fault. But thank you for making KTX so easily extensible.

I suppose there is a wider question about what scene2d elements should support what actions. My inexperience with LibGDX meant I learned about Label long before TextButton. And I've a lot still to learn :).

@v79 v79 closed this May 28, 2020
@czyzby czyzby reopened this May 28, 2020
@czyzby
Copy link
Member

@czyzby czyzby commented May 28, 2020

I think onCursorEnter/onCursorExit/onCursorHover could be very useful extensions, so thank you for bringing it up. I'll leave the issue as open and implement similar official extensions. :)

@czyzby czyzby changed the title Scene2d label has onEnter but not OnExit extension function Actor onEnter and OnExit extension functions May 28, 2020
@czyzby czyzby modified the milestones: 1.9.10, 1.9.11 Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.