Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(imgui): add dropdown widget, update hover behaviors
- Loading branch information
1 parent
6446e6e
commit b9d725a
Showing
7 changed files
with
73 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Key } from "../api"; | ||
import { IMGUI } from "../gui"; | ||
import { button } from "./button"; | ||
|
||
export const dropdown = ( | ||
gui: IMGUI, | ||
id: string, | ||
x: number, | ||
y: number, | ||
w: number, | ||
h: number, | ||
items: string[], | ||
state: [number, boolean] | ||
) => { | ||
let res = false; | ||
const sel = state[0]; | ||
if (state[1]) { | ||
for (let i = 0, n = items.length; i < n; i++) { | ||
if (button(gui, id + "-" + i, x, y, w, h, items[i])) { | ||
if (i !== sel) { | ||
state[0] = i; | ||
res = true; | ||
} | ||
state[1] = false; | ||
} | ||
y += h + 2; | ||
} | ||
const fID = gui.focusID; | ||
if (fID.startsWith(`${id}-`)) { | ||
switch (gui.key) { | ||
case Key.UP: { | ||
const next = Math.max(0, state[0] - 1); | ||
gui.focusID = id + "-" + next; | ||
state[0] = next; | ||
res = true; | ||
break; | ||
} | ||
case Key.DOWN: { | ||
const next = Math.min(items.length - 1, state[0] + 1); | ||
gui.focusID = id + "-" + next; | ||
state[0] = next; | ||
res = true; | ||
break; | ||
} | ||
default: | ||
} | ||
} | ||
} else { | ||
if (button(gui, id + "-" + sel, x, y, w, h, items[sel])) { | ||
state[1] = true; | ||
} | ||
} | ||
return res; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters