Giter Site home page Giter Site logo

Comments (7)

rjx-ray avatar rjx-ray commented on August 17, 2024 1

Now I have this code

		if (ImGui::IsItemHovered() && ImGui::GetIO().MouseClicked[1]) {
			ImGui::OpenPopupEx("Context menu", false);

Breaking on the second line
when I click the left button the MouseClicked array is [false,true,true,true,true]
when I click the right button the MouseClicked array is [false,true,false, false, false]

I believe the problem is here in line 147 of gui.cpp

			// Update for next frame; set to false only if the mouse has been released
			engine->mousePressed[i] = !engine->mouseReleased;

The state of buttons that were not pressed is inverted, so they go to true

changing line 147 to

if (engine->mousePressed[i]) engine->mousePressed[i] = !engine->mouseReleased;

fixes it and my original code now works.

I can make a pull request if you like.

from ofximgui.

jvcleave avatar jvcleave commented on August 17, 2024

Assuming you are building a Desktop app here is where we are passing the button info

https://github.com/jvcleave/ofxImGui/blob/master/src/EngineGLFW.cpp#L113

You should then check which button like this

if (ImGui::GetIO().MouseClicked[1])
{
    //do something
}

from ofximgui.

rjx-ray avatar rjx-ray commented on August 17, 2024

I'm building and running on Windows 10.
I can see onMousePressed gets the right click event with button number 2, then translates it to 1 and it sets mousepressed[1] true;
So I need to check button 1 for the right click
But then my code is like this

		bool gotInput = (ImGui::InputText("", urlText, 1024, EnterForTrue));
		if (ImGui::BeginPopupContextItem("item context menu", 1)) 	{
			(ImGui::Selectable("Copy")) ;
			(ImGui::Selectable("Paste")) ;
			ImGui::EndPopup();
		}

and I get the popup for any mouse button.

Following the thread through, as soon as the field is hovered BeginPopupContextItem calls isMouseClicked which looks at IO.MouseDownDuration.
With no mouse clicks all 5 values are minus 1.
isMouseClicked only returns true if the requested button duration has a value of zero.

I put a break on the true return and then I see

If the left mouse button is clicked, the value for button[0] is a small positive number and all the others are zero so I get a true return for button[1] == 0

If the right mouse button is clicked, the value for button[1] is zero and all the others remain at minus 1 and I also get a true return button[1] == 0

I can see the code setting the MouseDownDurations at lines 2086 to 2089 of ImGui.cpp but I can't see why button 0 should work differently from button 1- maybe timing on when the break happens.

Anyway, I think I will make my own version of BeginPopupContextItem checking just MouseClicked

from ofximgui.

jvcleave avatar jvcleave commented on August 17, 2024

@rjx-ray rjx-ray@81c54a1 seems reasonable. A PR would be appreciated

from ofximgui.

rjx-ray avatar rjx-ray commented on August 17, 2024

from ofximgui.

jvcleave avatar jvcleave commented on August 17, 2024

no rush here. it seems like a simple tweak if someone needs it in the meantime

as for the clipboard changes that seems to be more complicated so it would probably be best at it's own PR

from ofximgui.

rjx-ray avatar rjx-ray commented on August 17, 2024

Fixed in current master (1.65 imgui)

from ofximgui.

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.