Skip to content

Commit 6f35056

Browse files
committed
Using c.Button instead of re creating the button code logic inside the dropdown code
1 parent 1f15744 commit 6f35056

1 file changed

Lines changed: 2 additions & 35 deletions

File tree

dropdown.go

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -60,46 +60,13 @@ func (c *Context) dropdown(selectedIndex *int, options []string, id widgetID) (E
6060

6161
for i, option := range options {
6262
c.IDScope(strconv.Itoa(i), func() {
63-
isSelected := i == *selectedIndex
64-
65-
var buttonColor int
66-
if isSelected {
67-
buttonColor = colorButtonFocus
68-
} else {
69-
buttonColor = colorButton
70-
}
71-
72-
pc := caller()
73-
buttonID := c.idFromCaller(pc)
74-
var wasPressed bool
75-
76-
_ = c.wrapEventHandlerAndError(func() (EventHandler, error) {
77-
e, err := c.widget(buttonID, optionAlignCenter, nil, func(bounds image.Rectangle, wasFocused bool) EventHandler {
78-
var e EventHandler
79-
80-
if c.pointing.justPressed() && c.focus == buttonID {
81-
wasPressed = true
82-
e = &eventHandler{}
83-
}
84-
85-
return e
86-
}, func(bounds image.Rectangle) {
87-
c.drawWidgetFrame(buttonID, bounds, buttonColor, optionAlignCenter)
88-
if len(option) > 0 {
89-
c.drawWidgetText(option, bounds, colorText, optionAlignCenter)
90-
}
91-
})
92-
return e, err
93-
})
94-
95-
// Handle option selection: update index and start close delay
96-
if wasPressed {
63+
c.Button(option).On(func() {
9764
*selectedIndex = i
9865
if cnt := c.container(dropdownID, 0); cnt != nil {
9966
// Start the close delay timer (0.1 seconds at TPS rate)
10067
cnt.dropdownCloseDelay = ebiten.TPS() / 10
10168
}
102-
}
69+
})
10370
})
10471
}
10572
}); err != nil {

0 commit comments

Comments
 (0)