core icon indicating copy to clipboard operation
core copied to clipboard

Toggling Text Widget Visibility Causes Parent Frame Size Change

Open MongooseStudios opened this issue 6 months ago • 1 comments

Describe the bug

If you have two frames in a parent frame that are both set to grow, and you toggle the visibility of a text widget in the first frame, the first frame will grow even though there is plenty of space for the text widget to display.

This creates a "wiggly" UI, which is not desirable

How to reproduce

Run example code Observe that the two child frames take up roughly 50% of the parent space, as expected. Click the button Observe that despite the abundance of space, the first frame will wiggle over

Example code

package main

import (
	"cogentcore.org/core/core"
	"cogentcore.org/core/events"
	"cogentcore.org/core/styles"
	"cogentcore.org/core/styles/states"
	"cogentcore.org/core/styles/units"
)

func main() {
	b := core.NewBody("x-axis-wiggle-repro")

	centerFrame := core.NewFrame(b)
	centerFrame.Styler(func(s *styles.Style) {
		s.Grow.Set(1, 1)
		s.Max.X = units.Dp(1000)
		s.Max.Y = units.Dp(500)
		s.Border.Width.Set(units.Dp(1))
	})

	firstHalf := core.NewFrame(centerFrame)
	firstHalf.Styler(func(s *styles.Style) {
		s.Grow.Set(1, 1)
		s.Align.Content = styles.Center
		s.Border.Width.Set(units.Dp(1))
	})

	showText := false
	toggleButton := core.NewButton(firstHalf).SetText("toggle")

	saveStateText := core.NewText(firstHalf).SetText("unsaved changes")
	saveStateText.Styler(func(s *styles.Style) {
		s.Font.Size.Dp(20)
		s.SetState(!showText, states.Invisible)
	})

	toggleButton.OnClick(func(e events.Event) {
		showText = !showText
		saveStateText.Update()
	})

	secondHalf := core.NewFrame(centerFrame)
	secondHalf.Styler(func(s *styles.Style) {
		s.Grow.Set(1, 1)
		s.Align.Content = styles.Center
		s.Border.Width.Set(units.Dp(1))
	})

	core.NewText(secondHalf).SetText("Example Text")

	b.RunMainWindow()
}

Relevant output


Platform

Linux

MongooseStudios avatar Jun 09 '25 20:06 MongooseStudios

Thanks for reporting this. I can reproduce this and we will work on fixing it when we have the time.

In the meantime, if you set a fixed size for the child frames, that will presumably avoid the issue, although that is certainly somewhat unideal.

kkoreilly avatar Jun 22 '25 19:06 kkoreilly