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

RagioGroup miscalulates label widths in horizontal mode #3386

Closed
2 tasks done
grkuntzmd opened this issue Nov 7, 2022 · 2 comments
Closed
2 tasks done

RagioGroup miscalulates label widths in horizontal mode #3386

grkuntzmd opened this issue Nov 7, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@grkuntzmd
Copy link

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 long labels are used in the RagioGroup in horizontal mode, they overlap.

How to reproduce

go run .

Screenshots

image

Example code

package main

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

func main() {
	a := app.New()
	w := a.NewWindow("Radio Group Bug")

	rg := widget.NewRadioGroup([]string{"Easy", "Medium", "Hard", "Expert"}, func(s string) {})
	rg.Horizontal = true

	w.SetContent(rg)
	w.ShowAndRun()
}

Fyne version

2.2.3

Go compiler version

1.19.3

Operating system

Windows

Operating system version

Windows 11 Pro Version 22H2

Additional Information

No response

@grkuntzmd grkuntzmd added the unverified A bug that has been reported but not verified label Nov 7, 2022
@grkuntzmd grkuntzmd changed the title RagioGroup miscalulated label widths in horizontal mode RagioGroup miscalulates label widths in horizontal mode Nov 7, 2022
@grkuntzmd
Copy link
Author

grkuntzmd commented Nov 9, 2022

The RadioGroup Layout method is using the average minimum width of its items instead of the largest minimum width. If you have several small labels and one large label, the average minimum width will be smaller than the minimum width of the large label, causing it to overlap the next label.
This code is one possible fix:

// MinSize calculates the minimum size of a radio item.
// This is based on the contained text, the radio icon and a standard amount of padding
// between each item.
func (r *radioGroupRenderer) MinSize() fyne.Size {
	width := float32(0)
	height := float32(0)
	maxMinWidth := float32(0)
	if r.radio.Horizontal {
		for _, item := range r.items {
			itemMin := item.MinSize()
			maxMinWidth = fyne.Max(maxMinWidth, itemMin.Width)
		}
	}
	for _, item := range r.items {
		itemMin := item.MinSize()
		if r.radio.Horizontal {
			height = fyne.Max(height, itemMin.Height)
			width += maxMinWidth
			// width += itemMin.Width
		} else {
			width = fyne.Max(width, itemMin.Width)
			height += itemMin.Height
		}
	}

	return fyne.NewSize(width, height)
}

grkuntzmd added a commit to grkuntzmd/fyne that referenced this issue Nov 9, 2022
andydotxyz added a commit to andydotxyz/fyne that referenced this issue Mar 26, 2023
@andydotxyz
Copy link
Member

Fixed on develop

andydotxyz added a commit that referenced this issue Apr 28, 2023
@Jacalz Jacalz added bug Something isn't working and removed unverified A bug that has been reported but not verified labels Jun 2, 2023
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