Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dragging an item hides hover functionality #1479

Closed
123tris opened this issue Dec 5, 2017 · 4 comments
Closed

Dragging an item hides hover functionality #1479

123tris opened this issue Dec 5, 2017 · 4 comments
Labels
drag drop drag and drop

Comments

@123tris
Copy link

123tris commented Dec 5, 2017

I'm still new to the library so forgive me for my lack of knowledge of the API

As I've tried to implement dragging I've realized that dropping is a bit of a pain. This is because the frame where the mouse released is, the hover detection still doesn't work. This only happens if you drag a UI item like a treenode or a button. I believe this has to do with ImGui::IsItemActive()

For example:
if (ImGui::IsWindowHovered() && ImGui::IsMouseReleased(0)) std::cout << "test\n"; will not be called if you dragged an item and then released it over the window, it will only be called if you dragged nothing and then released the mouse. Is this intended?
This is needed for my drop and drag system, considering that this pretty much is my drop condition.

@123tris 123tris changed the title Dragging hides hover functionality Dragging an item hides hover functionality Dec 5, 2017
@ocornut
Copy link
Owner

ocornut commented Dec 5, 2017

Hello,

Two things:

Feel free to detail your usage of drag and drop and post feedback. This API is fairly stable but I want to test more patterns of drag-to-move-objects before locking it.

@123tris
Copy link
Author

123tris commented Dec 11, 2017

Ah I just had to update ImGui, thanks for the hover flags they really help a lot!
My implementation of drag and drop is by simply using dragable interfaces.

/**
* Base class for all the editor items that can be dragged
* eg. a prefab gets dragged into a inspector property field.
*/
class Draggable
{
public:
	virtual ~Draggable() = default;
};

And then I have a static class to set the dragging of an item.

class EditorDragging
{
public:
	/**
	* \return Returns the current draggingItem. Any draggable object can be selected
	*/
	static Draggable* getDragableItem() { return draggingItem; }
	/**
	* \param draggingItem The item to be set as the dragable item
	*/
	static void setDragableItem(Draggable* draggingItem)
	{
		EditorDragging::draggingItem = draggingItem;
	}
	/**
	 * \brief sets the currently dragging item to equal nullptr
	 */
	static void reset()
	{
		draggingItem = nullptr;
	}

private:
	static Draggable* draggingItem;
};

I then downcast it and check in the editor code if it is the object it's looking for:

EditorNode* draggingNode = dynamic_cast<EditorNode*>(EditorDragging::getDragableItem());
if (draggingNode != nullptr && ImGui::IsWindowHovered())
{
	draggingNode->move(nullptr);
	EditorDragging::reset();
}

That's pretty much it, I believe most people have a similar setup?

@ocornut
Copy link
Owner

ocornut commented Dec 11, 2017

I don't really know how any of that code connects to your imgui calls. Surely you must be calling something else that just ImGui::IsWindowHovered() to get the whole functionality to work?

I believe most people have a similar setup?

Unfortunately the answer to that question for many programming problems is often "no" :)

Anyway, if you have time to look into the drag_and_drop git branch to see is that may help you, I'm happy to get feedback on it. That branch will probably be merged in a few weeks.

@ocornut
Copy link
Owner

ocornut commented Feb 28, 2018

Closing as solved afaik? @123tris
(The drag and drop branch was merged into master shortly after you posted this, and hopefully it can be of use to you.!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
drag drop drag and drop
Projects
None yet
Development

No branches or pull requests

2 participants