hoffstadt / hoffstadt/DearPyGui
Some widgets remain focused when they shouldn't be
- Dominant language
- C++
- Stars
- 15.6k
- Forks
- 783
- PR merge metrics
- No merged PRs in 30d
Description
I've found that some widgets - when configured in a certain way - can remain focused, even after you click away from them.
## `add_input_int(step=0)`
Consider `dpg.add_input_int` with `step=0`, I expected `is_item_focused()` to only be true if the widget is selected (i.e. the mouse cursor is flashing in the widget), but actually if you click away then the last widget clicked remains in focus. It is only when you click away from the window that it loses focus.
```python
import dearpygui.dearpygui as dpg
dpg.create_context()
def on_enter():
if dpg.is_item_focused('foo'):
print("foo is focused")
elif dpg.is_item_focused('bar'):
print("bar is focused")
else:
print("nothing is focused")
with dpg.handler_registry() as keypress_handler:
dpg.add_key_press_handler(key=dpg.mvKey_Return, callback=on_enter)
with dpg.window():
dpg.add_text("Press enter to check who is focused (when step=0)")
dpg.add_input_int(label="foo", tag="foo", step=0)
dpg.add_input_int(label="bar", tag="bar", step=0)
dpg.create_viewport(width=500, height=500)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
```
## `add_input_int(step=1)`
However, if you set `step=1`, then the widget seems to work perfectly. It loses focus when clicked away, and `is_item_focused()` will only return true when the cursor is active inside the widget.
```python
import dearpygui.dearpygui as dpg
dpg.create_context()
def on_enter():
if dpg.is_item_focused('foo'):
print("foo is focused")
elif dpg.is_item_focused('bar'):
print("bar is focused")
else:
print("nothing is focused")
with dpg.handler_registry() as keypress_handler:
dpg.add_key_press_handler(key=dpg.mvKey_Return, callback=on_enter)
with dpg.window():
dpg.add_text("Press enter to check who is focused (when step=1)")
dpg.add_input_int(label="foo", tag="foo", step=1)
dpg.add_input_int(label="bar", tag="bar", step=1)
dpg.create_viewport(width=500, height=500)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
```
This is the same for `add_input_float` and `add_input_double`. I've also tried `add_input_text` and it also seems to have a similar focused bug.
Windows 10, Python 3.10, DPG 1.8
Contributor guide
Assessment
This issue has not been assessed yet.