fix(omnibox): top-align omnibox when a top margin percentage is configured
- commit
- 0d6e4937ff2b49821ea97d473b76c98e58991488
- author
- brice · · 2026-10-10 01:28 UTC
- parent
- cdd2182
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email - refs
- fix/omnibox-layout
2 files · +6 -6
M internal/ui/component/modal_sizing_test.go +2 -0
| @@ -176,6 +176,8 @@ func TestOmniboxSizeDefaults_Values(t *testing.T) { | |||
| 176 | 176 | func TestOmniboxValign(t *testing.T) { | |
| 177 | 177 | assert.Equal(t, gtk.AlignCenterValue, omniboxValign(OmniboxSizeDefaults)) | |
| 178 | 178 | assert.Equal(t, gtk.AlignStartValue, omniboxValign(ModalSizeConfig{UseFixedTopMargin: true})) | |
| 179 | + | assert.Equal(t, gtk.AlignStartValue, omniboxValign(ResolveModalSizeConfig( | |
| 180 | + | ModalSizeConfig{TopMarginPct: 0.2}, OmniboxSizeDefaults))) | |
| 179 | 181 | } | |
| 180 | 182 | ||
| 181 | 183 | func TestOmniboxListDefaults_ScrollableResults(t *testing.T) { | |
| @@ -176,6 +176,8 @@ func TestOmniboxSizeDefaults_Values(t *testing.T) { | |||||
| 176 | func TestOmniboxValign(t *testing.T) { | 176 | func TestOmniboxValign(t *testing.T) { | ||
| 177 | assert.Equal(t, gtk.AlignCenterValue, omniboxValign(OmniboxSizeDefaults)) | 177 | assert.Equal(t, gtk.AlignCenterValue, omniboxValign(OmniboxSizeDefaults)) | ||
| 178 | assert.Equal(t, gtk.AlignStartValue, omniboxValign(ModalSizeConfig{UseFixedTopMargin: true})) | 178 | assert.Equal(t, gtk.AlignStartValue, omniboxValign(ModalSizeConfig{UseFixedTopMargin: true})) | ||
| 179 | + | assert.Equal(t, gtk.AlignStartValue, omniboxValign(ResolveModalSizeConfig( | |||
| 180 | + | ModalSizeConfig{TopMarginPct: 0.2}, OmniboxSizeDefaults))) | |||
| 179 | } | 181 | } | ||
| 180 | 182 | ||||
| 181 | func TestOmniboxListDefaults_ScrollableResults(t *testing.T) { | 183 | func TestOmniboxListDefaults_ScrollableResults(t *testing.T) { | ||
M internal/ui/component/omnibox.go +4 -6
| @@ -782,10 +782,11 @@ func (o *Omnibox) initOuterBox() error { | |||
| 782 | 782 | return nil | |
| 783 | 783 | } | |
| 784 | 784 | ||
| 785 | - | // omniboxValign centers the in-pane omnibox vertically; a fixed top margin | |
| 786 | - | // (standalone window sized by its content) keeps it top-aligned. | |
| 785 | + | // omniboxValign centers the omnibox vertically by default. Any configured top | |
| 786 | + | // margin (fixed for the content-sized standalone window, or a percentage | |
| 787 | + | // override) keeps it top-aligned so the margin is applied as requested. | |
| 787 | 788 | func omniboxValign(cfg ModalSizeConfig) gtk.Align { | |
| 788 | - | if cfg.UseFixedTopMargin { | |
| 789 | + | if cfg.UseFixedTopMargin || cfg.TopMarginPct > 0 { | |
| 789 | 790 | return gtk.AlignStartValue | |
| 790 | 791 | } | |
| 791 | 792 | return gtk.AlignCenterValue | |
| @@ -2814,9 +2815,6 @@ func (o *Omnibox) Show(ctx context.Context, query string) { | |||
| 2814 | 2815 | parentHeight = o.parentOverlay.GetAllocatedHeight() | |
| 2815 | 2816 | } | |
| 2816 | 2817 | width, marginTop := o.requestedDimensions() | |
| 2817 | - | if omniboxValign(o.sizeCfg) == gtk.AlignCenterValue { | |
| 2818 | - | marginTop = 0 // centered by GTK; a margin would push it off-center | |
| 2819 | - | } | |
| 2820 | 2818 | log.Debug(). | |
| 2821 | 2819 | Int("parentWidth", parentWidth). | |
| 2822 | 2820 | Int("parentHeight", parentHeight). | |
| @@ -782,10 +782,11 @@ func (o *Omnibox) initOuterBox() error { | |||||
| 782 | return nil | 782 | return nil | ||
| 783 | } | 783 | } | ||
| 784 | 784 | ||||
| 785 | - | // omniboxValign centers the in-pane omnibox vertically; a fixed top margin | 785 | + | // omniboxValign centers the omnibox vertically by default. Any configured top |
| 786 | - | // (standalone window sized by its content) keeps it top-aligned. | 786 | + | // margin (fixed for the content-sized standalone window, or a percentage |
| 787 | + | // override) keeps it top-aligned so the margin is applied as requested. | |||
| 787 | func omniboxValign(cfg ModalSizeConfig) gtk.Align { | 788 | func omniboxValign(cfg ModalSizeConfig) gtk.Align { | ||
| 788 | - | if cfg.UseFixedTopMargin { | 789 | + | if cfg.UseFixedTopMargin || cfg.TopMarginPct > 0 { |
| 789 | return gtk.AlignStartValue | 790 | return gtk.AlignStartValue | ||
| 790 | } | 791 | } | ||
| 791 | return gtk.AlignCenterValue | 792 | return gtk.AlignCenterValue | ||
| @@ -2814,9 +2815,6 @@ func (o *Omnibox) Show(ctx context.Context, query string) { | |||||
| 2814 | parentHeight = o.parentOverlay.GetAllocatedHeight() | 2815 | parentHeight = o.parentOverlay.GetAllocatedHeight() | ||
| 2815 | } | 2816 | } | ||
| 2816 | width, marginTop := o.requestedDimensions() | 2817 | width, marginTop := o.requestedDimensions() | ||
| 2817 | - | if omniboxValign(o.sizeCfg) == gtk.AlignCenterValue { | |||
| 2818 | - | marginTop = 0 // centered by GTK; a margin would push it off-center | |||
| 2819 | - | } | |||
| 2820 | log.Debug(). | 2818 | log.Debug(). | ||
| 2821 | Int("parentWidth", parentWidth). | 2819 | Int("parentWidth", parentWidth). | ||
| 2822 | Int("parentHeight", parentHeight). | 2820 | Int("parentHeight", parentHeight). | ||