Skip to content

Commit d1e6939

Browse files
committed
Fixing wrong math
1 parent 148503c commit d1e6939

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

dropdown.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,18 @@ func (c *Context) dropdown(selectedIndex *int, options []string, id widgetID) (E
159159
dropdownContainer.open = true
160160
dropdownContainer.closeDelay = 0
161161

162-
// Position dropdown directly below button with proper width
163162
if wasClosedBefore {
164163
dropdownPos := image.Pt(bounds.Min.X, bounds.Max.Y)
165164
buttonWidth := bounds.Dx()
166-
optionHeight := c.style().defaultHeight + c.style().padding
167-
estimatedHeight := len(options) * optionHeight
165+
optionHeight := c.style().defaultHeight + c.style().padding + 1
166+
totalHeight := len(options) * optionHeight
167+
168+
maxDropdownHeight := c.style().defaultHeight * 12 // around 10 items visible?
169+
actualHeight := min(totalHeight, maxDropdownHeight)
170+
168171
dropdownContainer.layout.Bounds = image.Rectangle{
169172
Min: dropdownPos,
170-
Max: dropdownPos.Add(image.Pt(buttonWidth, estimatedHeight)),
173+
Max: dropdownPos.Add(image.Pt(buttonWidth, actualHeight)),
171174
}
172175
}
173176
}

0 commit comments

Comments
 (0)