Skip to content

Commit 3ce6dc6

Browse files
committed
Cleanup
1 parent 44fe4e8 commit 3ce6dc6

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/main/kotlin/com/lambda/gui/components/QuickSearch.kt

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import com.lambda.util.KeyCode
3434
import com.lambda.util.StringUtils.capitalize
3535
import com.lambda.util.StringUtils.findSimilarStrings
3636
import imgui.ImGui
37-
import imgui.flag.ImGuiHoveredFlags
3837
import imgui.flag.ImGuiInputTextFlags
3938
import imgui.flag.ImGuiStyleVar
4039
import imgui.flag.ImGuiWindowFlags
@@ -53,6 +52,13 @@ object QuickSearch {
5352
private const val MAX_RESULTS = 50
5453
private const val SIMILARITY_THRESHOLD = 3
5554

55+
private const val WINDOW_FLAGS = ImGuiWindowFlags.AlwaysAutoResize or
56+
ImGuiWindowFlags.NoTitleBar or
57+
ImGuiWindowFlags.NoMove or
58+
ImGuiWindowFlags.NoResize or
59+
ImGuiWindowFlags.NoScrollbar or
60+
ImGuiWindowFlags.NoScrollWithMouse
61+
5662
init {
5763
listenUnsafe<KeyboardEvent.Press> { event ->
5864
handleKeyPress(event)
@@ -158,26 +164,18 @@ object QuickSearch {
158164
if (!isOpen) return
159165
ImGui.openPopup("QuickSearch")
160166

161-
val windowFlags = ImGuiWindowFlags.AlwaysAutoResize or
162-
ImGuiWindowFlags.NoTitleBar or
163-
ImGuiWindowFlags.NoMove or
164-
ImGuiWindowFlags.NoResize or
165-
ImGuiWindowFlags.NoScrollbar or
166-
ImGuiWindowFlags.NoScrollWithMouse
167-
168167
ImGui.setNextFrameWantCaptureKeyboard(true)
169168

170-
val display = ImGui.getIO().displaySize
171-
val maxW = display.x * 0.5f
172-
val maxH = display.y * 0.5f
169+
val maxW = io.displaySize.x * 0.5f
170+
val maxH = io.displaySize.y * 0.5f
173171

174-
val popupX = (display.x - maxW) * 0.5f
175-
val popupY = display.y * 0.3f
172+
val popupX = (io.displaySize.x - maxW) * 0.5f
173+
val popupY = io.displaySize.y * 0.3f
176174
ImGui.setNextWindowPos(popupX, popupY)
177175
ImGui.setNextWindowSize(maxW, 0f)
178176
ImGui.setNextWindowSizeConstraints(0f, 0f, maxW, maxH)
179177

180-
popupModal("QuickSearch", windowFlags) {
178+
popupModal("QuickSearch", WINDOW_FLAGS) {
181179
// ToDo: Fix close with background click and escape
182180
if (ImGui.isKeyPressed(256)) { // ESC key
183181
close()
@@ -198,8 +196,8 @@ object QuickSearch {
198196
shouldFocus = false
199197
}
200198

201-
withItemWidth(ImGui.getContentRegionAvailX() * 0.98f) {
202-
withStyleVar(ImGuiStyleVar.FramePadding, style.framePadding.x, style.framePadding.y * 1.35f) {
199+
withItemWidth(ImGui.getContentRegionAvailX()) {
200+
withStyleVar(ImGuiStyleVar.FramePadding, style.framePadding.x, style.framePadding.y) {
203201
ImGui.inputTextWithHint(
204202
"##qs-input",
205203
"Type to search modules, settings, and commands...",
@@ -219,7 +217,7 @@ object QuickSearch {
219217
}
220218

221219
val rowH = frameHeightWithSpacing
222-
val topArea = ImGui.getCursorPosY() + style.windowPadding.y
220+
val topArea = cursorPosY + style.windowPadding.y
223221
val listH = (results.size * rowH).coerceAtMost(maxH - topArea).coerceAtLeast(rowH)
224222

225223
child("qs_rows", 0f, listH, false) {

0 commit comments

Comments
 (0)