Giter Club home page Giter Club logo

Comments (4)

v-ein avatar v-ein commented on May 28, 2024

Why would you expect a (0, 0) there? get_mouse_pos returns mouse coordinates relative to the viewport (local=False) or to the active window (local=True). Since you're binding the click handler to that red square, the "origin" I presume is the top left corner of that square, which is located at (window padding X, window paddingY) in window's local coordinates. The default padding is (8, 8) - exactly what you're seeing.

You can try to print that origin position like this:

print(f"Origin: {dpg.get_item_rect_min(sender)}")

from dearpygui.

atinfinity avatar atinfinity commented on May 28, 2024

@v-ein Thank you for your comment.

Why would you expect a (0, 0) there?

image

You can try to print that origin position like this:

I tried this. But, the following error occurs.

Mouse clicked at: [201.0, 175.0]
Traceback (most recent call last):
  File "/home/user/dpg_example.py", line 8, in mouse_callback
    print(f"Origin: {dpg.get_item_rect_min(sender)}")
  File "/home/user/dpg-venv/lib/python3.10/site-packages/dearpygui/dearpygui.py", line 840, in get_item_rect_min
    return internal_dpg.get_item_state(item)["rect_min"]
KeyError: 'rect_min'

from dearpygui.

v-ein avatar v-ein commented on May 28, 2024

My bad - it should have been dpg.get_item_rect_min(app_data[1]) since sender is the click handler itself, and the clicked widget is passed via app_data.

You'll also notice that get_item_rect_min returns global coordinates. To get local ones, you can try get_item_pos, but these will be relative to the window's outer rectangle, i.e. (0, 0) will be the top-left corner of the title bar, not of the window's client area. You can offset that by computing title bar height from font size and paddings, but it might be easier to use get_item_rect_min and get_mouse_pos(local=False) - from these, you can directly calculate mouse position within the image.

Yes, coordinate systems in DPG are a bit of a mess.

from dearpygui.

atinfinity avatar atinfinity commented on May 28, 2024

@v-ein Thank you for your help. I understood coordinate system.

from dearpygui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.