Skip to content

Conversation

@gui-fkb
Copy link

@gui-fkb gui-fkb commented Feb 6, 2025

This PR adds MinSize and MaxSize to AnchorLayoutData, making it easier to define size constraints directly within the layout data.

Why?
I was discussing this with a friend, and we both found the current way a bit unintuitive to set the minSize in the widget options. When trying to set min/max sizes, we instinctively looked for those properties in AnchorLayoutData, not in WidgetOpts. Having to set MinSize separately on the widget felt disconnected from the layout itself.

With this change, you can now define MinSize and MaxSize directly in AnchorLayoutData, making it more natural to work with:

Before (current way, still works):

innerContainer := widget.NewContainer(
	widget.ContainerOpts.BackgroundImage(image.NewNineSliceColor(color.NRGBA{255, 0, 0, 255})),
	widget.ContainerOpts.WidgetOpts(
		widget.WidgetOpts.LayoutData(widget.AnchorLayoutData{
			HorizontalPosition: widget.AnchorLayoutPositionCenter,
			VerticalPosition:   widget.AnchorLayoutPositionCenter,
			StretchHorizontal:  true,
			StretchVertical:    false,
		}),
		widget.WidgetOpts.MinSize(100, 100), 
	),
)

After (my change, I think is look more intuitive):

innerContainer := widget.NewContainer(
	widget.ContainerOpts.BackgroundImage(image.NewNineSliceColor(color.NRGBA{255, 0, 0, 255})),
	widget.ContainerOpts.WidgetOpts(
		widget.WidgetOpts.LayoutData(widget.AnchorLayoutData{
			HorizontalPosition: widget.AnchorLayoutPositionCenter,
			VerticalPosition:   widget.AnchorLayoutPositionCenter,
			StretchHorizontal:  true,
			StretchVertical:    false,
			MinSize:            widget.AnchorLayoutDataOpts.AnchorLayoutMinSize(100, 100),
			MaxSize:            widget.AnchorLayoutDataOpts.AnchorLayoutMaxSize(300, 300),
		}),
	),
)

With min size:
image

With min and max size:
image

Important:

The old way still works—this just adds an alternative way to set size constraints directly in the layout.

MaxSize didn’t exist before, so this also introduces a way to cap widget sizes inside AnchorLayout.

This should make it easier to reason about layout constraints while keeping everything backward-compatible.

@CLAassistant
Copy link

CLAassistant commented Feb 6, 2025

CLA assistant check
All committers have signed the CLA.

@mcarpenter622
Copy link
Collaborator

Sorry it's taken a while to get to this. But I do have a few concerns / questions with the PR.

  1. The name of the parameters doesn't need to include AnchorLayout in it, if we were to do this, I'd want just MinSize, MaxSize.
  2. Why is there a new var AnchorLayoutDataOpts AnchorLayoutDataOptions, and why are we storing a function pointer?
  3. This PR is only adding this to AnchorLayout. If we are going to be changing the Layouts to have min/max size for the widgets we should do it to all the layouts instead of just the one.
  4. And this is the big one, I think having multiple ways to set a widget's min/max size can be problematic. Honestly, I'd prefer if we just added MaxSize to the widgetOptions.

I'm not saying no here, but I do need some convincing that this is a good route to go. Perhaps start a thread on discord to discuss with others?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants