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

Entry cursor is not visible with animations off #4508

Closed
2 tasks done
easycat opened this issue Jan 3, 2024 · 8 comments
Closed
2 tasks done

Entry cursor is not visible with animations off #4508

easycat opened this issue Jan 3, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@easycat
Copy link

easycat commented Jan 3, 2024

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

When the Entry box receives focus, CPU usage will increase slightly. When there are many controls on a poorly configured machine, the window CPU usage can be high, even reaching up to 50%. This can make it difficult or impossible to input text properly.

How to reproduce

in the centos8 or other linux.

The code you provided compiles and runs on Linux.

When there are no operations performed, the CPU usage can be observed to range from approximately 1% to 3% using top comma.
When the mouse clicks on an Entry control widget, the CPU usage will increase to around 7-8%.
After clicking a button (focus is move out form Entry), the CPU usage will decrease to approximately 3% left or right.

I tried disabling the animation of the Entry widget, but despite the above operations, there was no significant increase in CPU usage. However, the cursor did not show up.

image

Screenshots

The focus is not on the Entry.
image
The focus on the Entry.
image
The focus move out Entry.
image

Example code

package main

import (
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("Hello")

	hello := widget.NewEntry()
	w.SetContent(container.NewVBox(
		hello,
		widget.NewButton("Hi!", func() {
			hello.SetText("Welcome :)")
		}),
	))

	w.ShowAndRun()
}

Fyne version

2.4.3, 2.4.2, 2.4.1, 2.3.5

Go compiler version

1.18.10

Operating system and version

centos8 or other linux

Additional Information

No response

@easycat easycat added the unverified A bug that has been reported but not verified label Jan 3, 2024
@andydotxyz
Copy link
Member

You could disable animations using the build tag no_animations https://docs.fyne.io/explore/compiling

@easycat
Copy link
Author

easycat commented Jan 4, 2024

You could disable animations using the build tag no_animations https://docs.fyne.io/explore/compiling

This operation is similar to my commented code. It does not require any changes to the underlying fyne library. It solves the problem of high CPU usage, but there is no input cursor for this operation.

I see that the above code actually has cursor.Show(). Show() in the code above, but for some reason it doesn't show it.

@easycat
Copy link
Author

easycat commented Jan 4, 2024

You could disable animations using the build tag no_animations https://docs.fyne.io/explore/compiling

With animation disabled. The cursor doesn't have a color. I don't know if this is the original design intent. The following code change adds a new line and I added a comment. This solves the problem of the cursor not showing up when there is no animation.

I'm not very familiar with fyne's own code. Please help me to see the right place to add this line and the right parameters.

func (r *entryContentRenderer) Refresh() {
	r.content.entry.propertyLock.RLock()
	provider := r.content.entry.textProvider()
	placeholder := r.content.entry.placeholderProvider()
	focusedAppearance := r.content.entry.focused && !r.content.entry.disabled
	selections := r.selection
	r.updateScrollDirections()
	r.content.entry.propertyLock.RUnlock()

	if provider.len() == 0 {
		placeholder.Show()
	} else if placeholder.Visible() {
		placeholder.Hide()
	}

	if focusedAppearance {
		r.cursor.Show()
		if fyne.CurrentApp().Settings().ShowAnimations() {
			r.content.entry.cursorAnim.start()
		} else {
			r.cursor.FillColor = theme.PrimaryColor() // set a color on no_animations mode
		}
	} else {
		r.content.entry.cursorAnim.stop()
		r.cursor.Hide()
	}
	r.moveCursor()

	for _, selection := range selections {
		selection.(*canvas.Rectangle).Hidden = !r.content.entry.focused
		selection.(*canvas.Rectangle).FillColor = theme.SelectionColor()
	}

	canvas.Refresh(r.content)
}

@andydotxyz
Copy link
Member

With animation disabled. The cursor doesn't have a color. I don't know if this is the original design intent. The following code change adds a new line and I added a comment. This solves the problem of the cursor not showing up when there is no animation.

Thanks for this, that is indeed a bug.

Your proposed solution looks great, you can probably edit the file in GitHub to propose the change.
If the Show is moved to after that animation if block then it should ensure the colour is set without causing an additional refresh.

Thanks for the help.

@dweymouth
Copy link
Contributor

dweymouth commented Jan 4, 2024

This is a duplicate of #1946 which still needs to be addressed in some way. (EG making the animation faster so there is a short rest period between blink-in and blink-out, or on desktop disabling the cursor animation entirely as it's not standard on desktops - at least GTK and Cocoa)

@dweymouth dweymouth added duplicate This issue or pull request already exists and removed unverified A bug that has been reported but not verified labels Jan 4, 2024
@andydotxyz
Copy link
Member

It is still tracking a separate bug whereby with animations off the cursor will not be visible - so let's not close as duplicate.
Though the original problem should be addressed too. Though with various optimisations the issue is much less impactful.

@dweymouth dweymouth changed the title When the Entry box receives focus, CPU usage will increase slightly. Entry cursor is not visible with animations off Jan 7, 2024
@dweymouth
Copy link
Contributor

Changing title to reflect the bug this will be tracking

@dweymouth dweymouth added bug Something isn't working and removed duplicate This issue or pull request already exists labels Jan 7, 2024
@dweymouth
Copy link
Contributor

Though with various optimisations the issue is much less impactful.

It's still pretty impactful though. In Supersonic, if it's sitting idle but with the search bar focused, it uses 2x-3x the CPU load than if it's playing music but without any Entry widget focused

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

No branches or pull requests

3 participants