fix: improve omnibox width calculation for unallocated parents
- commit
- c7a267600186ac8bb91e3daad3c658509a680342
- author
- brice · · 2026-01-26 05:18 UTC
- parent
- c7a34e5
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +10 -8
M internal/ui/component/modal_sizing.go +4 -2
| @@ -90,10 +90,12 @@ func CalculateModalDimensions(parent layout.OverlayWidget, cfg ModalSizeConfig) | |||
| 90 | 90 | parentHeight = parent.GetAllocatedHeight() | |
| 91 | 91 | } | |
| 92 | 92 | ||
| 93 | - | if parentWidth <= 0 { | |
| 93 | + | // Use fallback if parent not allocated or too small to be useful | |
| 94 | + | // A width < 100 is too small for any meaningful modal | |
| 95 | + | if parentWidth < 100 { | |
| 94 | 96 | parentWidth = cfg.FallbackWidth | |
| 95 | 97 | } | |
| 96 | - | if parentHeight <= 0 { | |
| 98 | + | if parentHeight < 100 { | |
| 97 | 99 | parentHeight = cfg.FallbackHeight | |
| 98 | 100 | } | |
| 99 | 101 | ||
| @@ -90,10 +90,12 @@ func CalculateModalDimensions(parent layout.OverlayWidget, cfg ModalSizeConfig) | |||||
| 90 | parentHeight = parent.GetAllocatedHeight() | 90 | parentHeight = parent.GetAllocatedHeight() | ||
| 91 | } | 91 | } | ||
| 92 | 92 | ||||
| 93 | - | if parentWidth <= 0 { | 93 | + | // Use fallback if parent not allocated or too small to be useful |
| 94 | + | // A width < 100 is too small for any meaningful modal | |||
| 95 | + | if parentWidth < 100 { | |||
| 94 | parentWidth = cfg.FallbackWidth | 96 | parentWidth = cfg.FallbackWidth | ||
| 95 | } | 97 | } | ||
| 96 | - | if parentHeight <= 0 { | 98 | + | if parentHeight < 100 { |
| 97 | parentHeight = cfg.FallbackHeight | 99 | parentHeight = cfg.FallbackHeight | ||
| 98 | } | 100 | } | ||
| 99 | 101 | ||||
M internal/ui/component/omnibox.go +6 -6
| @@ -307,24 +307,21 @@ func (o *Omnibox) resizeAndCenter(rowCount int) { | |||
| 307 | 307 | return | |
| 308 | 308 | } | |
| 309 | 309 | ||
| 310 | - | // Calculate width using shared helper | |
| 311 | - | width, _ := CalculateModalDimensions(o.parentOverlay, OmniboxSizeDefaults) | |
| 312 | - | ||
| 313 | 310 | // Cap at max results | |
| 314 | 311 | if rowCount > OmniboxListDefaults.MaxVisibleRows { | |
| 315 | 312 | rowCount = OmniboxListDefaults.MaxVisibleRows | |
| 316 | 313 | } | |
| 317 | 314 | ||
| 318 | 315 | // Schedule measurement after GTK has laid out widgets | |
| 319 | - | // This ensures we get accurate heights from actual rendered content | |
| 320 | 316 | var cb glib.SourceFunc = func(uintptr) bool { | |
| 317 | + | width, _ := CalculateModalDimensions(o.parentOverlay, OmniboxSizeDefaults) | |
| 321 | 318 | o.measureAndResize(width, rowCount) | |
| 322 | - | return false // One-shot | |
| 319 | + | return false | |
| 323 | 320 | } | |
| 324 | 321 | glib.IdleAdd(&cb, 0) | |
| 325 | 322 | } | |
| 326 | 323 | ||
| 327 | - | // measureAndResize calculates and sets the omnibox height based on row count. | |
| 324 | + | // measureAndResize calculates and sets the omnibox size based on content. | |
| 328 | 325 | // Uses measured widget heights when available, falls back to estimates. | |
| 329 | 326 | func (o *Omnibox) measureAndResize(width, rowCount int) { | |
| 330 | 327 | if o.outerBox == nil || o.mainBox == nil { | |
| @@ -333,6 +330,9 @@ func (o *Omnibox) measureAndResize(width, rowCount int) { | |||
| 333 | 330 | ||
| 334 | 331 | log := logging.FromContext(o.ctx) | |
| 335 | 332 | ||
| 333 | + | // Apply width to mainBox - this allows the omnibox to adapt when parent resizes | |
| 334 | + | o.mainBox.SetSizeRequest(width, -1) | |
| 335 | + | ||
| 336 | 336 | var rowHeight int | |
| 337 | 337 | ||
| 338 | 338 | if o.measuredHeights.valid && o.measuredHeights.singleRow > 0 { | |
| @@ -307,24 +307,21 @@ func (o *Omnibox) resizeAndCenter(rowCount int) { | |||||
| 307 | return | 307 | return | ||
| 308 | } | 308 | } | ||
| 309 | 309 | ||||
| 310 | - | // Calculate width using shared helper | |||
| 311 | - | width, _ := CalculateModalDimensions(o.parentOverlay, OmniboxSizeDefaults) | |||
| 312 | - | ||||
| 313 | // Cap at max results | 310 | // Cap at max results | ||
| 314 | if rowCount > OmniboxListDefaults.MaxVisibleRows { | 311 | if rowCount > OmniboxListDefaults.MaxVisibleRows { | ||
| 315 | rowCount = OmniboxListDefaults.MaxVisibleRows | 312 | rowCount = OmniboxListDefaults.MaxVisibleRows | ||
| 316 | } | 313 | } | ||
| 317 | 314 | ||||
| 318 | // Schedule measurement after GTK has laid out widgets | 315 | // Schedule measurement after GTK has laid out widgets | ||
| 319 | - | // This ensures we get accurate heights from actual rendered content | |||
| 320 | var cb glib.SourceFunc = func(uintptr) bool { | 316 | var cb glib.SourceFunc = func(uintptr) bool { | ||
| 317 | + | width, _ := CalculateModalDimensions(o.parentOverlay, OmniboxSizeDefaults) | |||
| 321 | o.measureAndResize(width, rowCount) | 318 | o.measureAndResize(width, rowCount) | ||
| 322 | - | return false // One-shot | 319 | + | return false |
| 323 | } | 320 | } | ||
| 324 | glib.IdleAdd(&cb, 0) | 321 | glib.IdleAdd(&cb, 0) | ||
| 325 | } | 322 | } | ||
| 326 | 323 | ||||
| 327 | - | // measureAndResize calculates and sets the omnibox height based on row count. | 324 | + | // measureAndResize calculates and sets the omnibox size based on content. |
| 328 | // Uses measured widget heights when available, falls back to estimates. | 325 | // Uses measured widget heights when available, falls back to estimates. | ||
| 329 | func (o *Omnibox) measureAndResize(width, rowCount int) { | 326 | func (o *Omnibox) measureAndResize(width, rowCount int) { | ||
| 330 | if o.outerBox == nil || o.mainBox == nil { | 327 | if o.outerBox == nil || o.mainBox == nil { | ||
| @@ -333,6 +330,9 @@ func (o *Omnibox) measureAndResize(width, rowCount int) { | |||||
| 333 | 330 | ||||
| 334 | log := logging.FromContext(o.ctx) | 331 | log := logging.FromContext(o.ctx) | ||
| 335 | 332 | ||||
| 333 | + | // Apply width to mainBox - this allows the omnibox to adapt when parent resizes | |||
| 334 | + | o.mainBox.SetSizeRequest(width, -1) | |||
| 335 | + | ||||
| 336 | var rowHeight int | 336 | var rowHeight int | ||
| 337 | 337 | ||||
| 338 | if o.measuredHeights.valid && o.measuredHeights.singleRow > 0 { | 338 | if o.measuredHeights.valid && o.measuredHeights.singleRow > 0 { | ||