@@ -132,18 +132,6 @@ object ImGuiBuilder {
132132 val isWindowAppearing: Boolean get() = ImGui .isWindowAppearing()
133133 val isWindowCollapsed: Boolean get() = ImGui .isWindowCollapsed()
134134
135- /* *
136- * Returns whether the current window is focused.
137- */
138- val isWindowFocused: Boolean get() = ImGui .isWindowFocused()
139- fun isWindowFocused (flags : Int = ImGuiWindowFlags .None ) = ImGui .isWindowHovered(flags)
140-
141- /* *
142- * Returns whether the current window is hovered and not blocked by a popup/modal
143- */
144- val isWindowHovered: Boolean get() = ImGui .isWindowHovered()
145- fun isWindowHovered (flags : Int = ImGuiWindowFlags .None ) = ImGui .isWindowHovered(flags)
146-
147135 /* *
148136 * Returns the current window position in screen space
149137 *
@@ -167,41 +155,71 @@ object ImGuiBuilder {
167155 val windowViewport: ImGuiViewport get() = ImGui .getWindowViewport()
168156
169157 /* *
170- * Returns whether the last item hovered and usable (not blocked by a popup, etc.).
158+ * Returns whether any item hovered and usable (not blocked by a popup, etc.).
171159 */
172- val isItemHovered: Boolean get() = ImGui .isItemHovered()
173- fun isItemHovered (flags : Int = ImGuiHoveredFlags .None ) = ImGui .isItemHovered(flags)
160+ val isAnyItemHovered: Boolean get() = ImGui .isAnyItemHovered()
174161
175162 /* *
176163 * Returns whether:
177- * - A button is being held
178- * - A text field being is edited
179- * - The last item is being held and allows interaction
164+ * - Any button is being held
165+ * - Any text field is being edited
166+ * - Any item is being held and allows interaction
180167 */
181- val isItemActive : Boolean get() = ImGui .isItemActive ()
168+ val isAnyItemActive : Boolean get() = ImGui .isAnyItemActive ()
182169
183170 /* *
184- * Returns whether the last item is focused via keyboard/gamepad navigation
171+ * Returns whether any item is focused via keyboard/gamepad navigation
185172 */
186- val isItemFocused : Boolean get() = ImGui .isItemFocused ()
173+ val isAnyItemFocused : Boolean get() = ImGui .isAnyItemFocused ()
187174
188175 /* *
189- * Returns whether any item hovered and usable (not blocked by a popup, etc.).
176+ * Executes the specified block if the current window is hovered, based on the provided flags.
177+ *
178+ * @param flags Optional flags to control the behavior of the hover state. The default value is `ImGuiWindowFlags.None`.
179+ * @param block A lambda block of code to be executed when the window is hovered.
190180 */
191- val isAnyItemHovered: Boolean get() = ImGui .isAnyItemHovered()
181+ @ImGuiDsl
182+ fun onWindowFocus (flags : Int = ImGuiWindowFlags .None , block : ProcedureBlock ) =
183+ if (ImGui .isWindowHovered(flags)) block() else Unit
192184
193185 /* *
194- * Returns whether:
195- * - Any button is being held
196- * - Any text field is being edited
197- * - Any item is being held and allows interaction
186+ * Executes a given block of code when the current ImGui window is being hovered.
187+ *
188+ * @param flags Optional flag settings for specifying conditions under which the window hover is detected.
189+ * Defaults to `ImGuiWindowFlags.None`.
190+ * @param block The block of code to execute when the hover condition is met.
198191 */
199- val isAnyItemActive: Boolean get() = ImGui .isAnyItemActive()
192+ @ImGuiDsl
193+ fun onWindowHover (flags : Int = ImGuiWindowFlags .None , block : ProcedureBlock ) =
194+ if (ImGui .isWindowHovered(flags)) block() else Unit
200195
201196 /* *
202- * Returns whether any item is focused via keyboard/gamepad navigation
197+ * Executes the given block of code if the current ImGui item is hovered.
198+ *
199+ * @param flags Customization flags for determining hover behavior. Defaults to `ImGuiHoveredFlags.None`.
200+ * @param block The block of code to execute when the item is hovered.
203201 */
204- val isAnyItemFocused: Boolean get() = ImGui .isAnyItemFocused()
202+ @ImGuiDsl
203+ fun onItemHover (flags : Int = ImGuiHoveredFlags .None , block : ProcedureBlock ) =
204+ if (ImGui .isItemHovered(flags)) block() else Unit
205+
206+ /* *
207+ * Executes the provided block of code if the current item is active in the ImGui context.
208+ *
209+ * @param block The block of code to be executed when the item is active.
210+ */
211+ @ImGuiDsl
212+ fun onItemActive (block : ProcedureBlock ) =
213+ if (ImGui .isItemActive()) block() else Unit
214+
215+ /* *
216+ * Executes the given [block] when the currently active item in the ImGui interface gains focus.
217+ *
218+ * @param block The block of code to execute if the current item is focused.
219+ */
220+ @ImGuiDsl
221+ fun onItemFocus (block : ProcedureBlock ) =
222+ if (ImGui .isItemFocused()) block() else Unit
205223
206224 /* *
207225 * Returns whether the last hovered item is clicked on
@@ -210,8 +228,9 @@ object ImGuiBuilder {
210228 *
211229 * this is NOT equivalent to the behavior of e.g. Button(). Read comments in function definition.
212230 */
213- val isItemClicked: Boolean get() = ImGui .isItemClicked()
214- fun isItemClicked (button : Int = ImGuiMouseButton .Right ) = ImGui .isItemClicked(button)
231+ @ImGuiDsl
232+ fun onItemClick (button : Int = ImGuiMouseButton .Right , block : ProcedureBlock ) =
233+ if (ImGui .isItemClicked(button)) block() else Unit
215234
216235 /* *
217236 * Returns whether:
@@ -353,7 +372,7 @@ object ImGuiBuilder {
353372 @ImGuiDsl
354373 fun textCopyable (text : String ) {
355374 text(text)
356- if (isItemHovered()) {
375+ onItemHover {
357376 if (isMouseClicked(ImGuiMouseButton .Left )) {
358377 setClipboardText(text)
359378 }
@@ -1401,6 +1420,22 @@ object ImGuiBuilder {
14011420 endTooltip()
14021421 }
14031422
1423+ /* *
1424+ * Displays a tooltip with the specified description when the current ImGui item is hovered.
1425+ *
1426+ * @param description The text content to display in the tooltip.
1427+ */
1428+ @ImGuiDsl
1429+ fun lambdaTooltip (description : String ) {
1430+ onItemHover {
1431+ tooltip {
1432+ withTextWrapPos(fontSize * 35f ) {
1433+ textUnformatted(description)
1434+ }
1435+ }
1436+ }
1437+ }
1438+
14041439 /* *
14051440 * Creates a help marker with a tooltip.
14061441 *
@@ -1409,11 +1444,11 @@ object ImGuiBuilder {
14091444 @ImGuiDsl
14101445 fun helpMarker (description : String , text : String = "(? )") {
14111446 textDisabled(text)
1412- if (isItemHovered()) {
1447+ onItemHover {
14131448 tooltip {
1414- pushTextWrapPos (fontSize * 35f )
1415- textUnformatted(description)
1416- popTextWrapPos()
1449+ withTextWrapPos (fontSize * 35f ) {
1450+ textUnformatted(description)
1451+ }
14171452 }
14181453 }
14191454 }
0 commit comments