Skip to content

Add RowWrap layout #5612

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

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

ErikKalkoken
Copy link
Contributor

@ErikKalkoken ErikKalkoken commented Mar 17, 2025

Description:

Adds a new layout for dynamically arranging objects with same height in rows with wrapping.

In my opinion this layout solves a common layout problem and would be a good addition the Fyne toolkit. For example it would allow to dynamically arranging a set of filter chips in multiple rows:

image

I went with "RowWrap", because it arranges objects in rows and wraps them. This layout is similar to the existing GridWrap layout, so a similar name makes sense (i.e. it arranges in rows instead of a grid). But I am of course open to other suggestions.

Demo

Here is an example render:

Screencast.from.17.03.2025.15.39.08.webm

Code to reproduce the example:

package main

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

func main() {
	a := app.New()
	w := a.NewWindow("RowWrap layout")
	c := container.New(
		layout.NewRowWrapLayout(),
		widget.NewButton("Alpha", nil),
		widget.NewButton("Bravo Charlie", nil),
		widget.NewButton("Delta", nil),
		widget.NewButton("Echo Foxtrott Golf Hotel", nil),
		widget.NewButton("India Juliet", nil),
		widget.NewButton("Kilo Limo Mike November", nil),
	)
	w.SetContent(c)
	w.Resize(fyne.NewSize(50, 50))
	w.ShowAndRun()
}

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

Where applicable:

  • Public APIs match existing style and have Since: line.

Open

  • Add tests for custom padding variant

@coveralls
Copy link

coveralls commented Mar 17, 2025

Coverage Status

coverage: 62.378% (+0.02%) from 62.357%
when pulling 48e3034 on ErikKalkoken:add-rowwrap-layout
into b66cb98 on fyne-io:develop.

@ErikKalkoken ErikKalkoken changed the title Add RowWrap layout WIP: Add RowWrap layout Mar 17, 2025
@ErikKalkoken ErikKalkoken marked this pull request as draft April 9, 2025 14:11
@ErikKalkoken ErikKalkoken changed the title WIP: Add RowWrap layout Add RowWrap layout Apr 9, 2025
Copy link
Member

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the idea of this. Just left a few minor suggestions inline before I noticed it was a draft PR but I'm attaching them anyway :)

Comment on lines 60 to 61
s := fyne.NewSize(width, rowHeight*float32(rows)+l.verticalPadding*float32(rows-1))
return s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaner to just return directly:

Suggested change
s := fyne.NewSize(width, rowHeight*float32(rows)+l.verticalPadding*float32(rows-1))
return s
return fyne.NewSize(width, rowHeight*float32(rows)+l.verticalPadding*float32(rows-1))

Comment on lines 56 to 58
if size.Width > width {
width = size.Width
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a fyne.Max() function you can use here instead.

@andydotxyz
Copy link
Member

Do try not to force-push after reviews, it means that every review has to be from scratch not incremental.

@Jacalz
Copy link
Member

Jacalz commented Jun 11, 2025

Generally yes, though I'd say that it makes sense to force push for changes in a PR that is still in draft. I only submitted my review because I didn't realise it being drafted at the time

@ErikKalkoken ErikKalkoken marked this pull request as ready for review June 12, 2025 14:13
@ErikKalkoken
Copy link
Contributor Author

This PR is now finally ready for review.

All review comments so far have been addressed. I am expecting the reviewers to resolve their issues if they agree.

Copy link
Member

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Just a few minor suggestions inline.

Copy link
Member

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one. Thanks 👍

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

Successfully merging this pull request may close these issues.

5 participants