mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-23 21:09:01 +08:00
Updated Tips (markdown)
parent
5beb62dae6
commit
a5913f2a92
19
Tips.md
19
Tips.md
@ -7,7 +7,24 @@ Also see [[Debug Tools]].
|
||||
|
||||
### Visual debugging
|
||||
|
||||
You can use ImDrawList primitives on the foreground drawlist, e.g. `GetForegroundDrawList()->AddRectFilled(...)` to bypass clipping of the current window. Whenever you are working with coordinates, consider displaying it on screen using `AddRect()`, `AddCircle()`, etc.
|
||||
- `ImGui::DebugDrawCursorPos()`, `ImGui::DebugDrawItemRect()` are a convenient way to easily display the current layout position or previous item geometry.
|
||||
|
||||
- You can use ImDrawList primitives on the foreground drawlist, e.g. `GetForegroundDrawList()->AddRectFilled(...)` to bypass clipping of the current window. Whenever you are working with coordinates and unsure of their values, consider displaying them on screen using `AddRect()`, `AddCircle()`, etc.
|
||||
|
||||
- Using keyboard modifiers is a convenient way to easily enable/disable something.
|
||||
|
||||
```cpp
|
||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
||||
ImVec2 my_pos= ImGui::GetCursorScreenPos();
|
||||
|
||||
if (ImGui::GetIO().KeyShift)
|
||||
{
|
||||
ImGui::DebugDrawItemRect(); // Helper to draw a rectangle between GetItemRectMin() and GetItemRectMax()
|
||||
ImGui::GetForegroundDrawList()->AddCircleFilled(my_pos, 3, IM_COL32(255, 0, 0, 255)); // Draw red circle at position
|
||||
}
|
||||
ImGui::Text("Shift held: %d", ImGui::GetIO().KeyShift);
|
||||
```
|
||||
![debug_draw](https://github.com/ocornut/imgui/assets/8225057/67ceafc6-cdb0-48ae-9559-8f176871d361)
|
||||
|
||||
----
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user