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

Plot functions registering their ID change from 1.67 to 1.68 #3072

Closed
sonoro1234 opened this issue Mar 23, 2020 · 8 comments
Closed

Plot functions registering their ID change from 1.67 to 1.68 #3072

sonoro1234 opened this issue Mar 23, 2020 · 8 comments

Comments

@sonoro1234
Copy link

Hi,

There is some old code that was working on 1.67 but stopped to work in 1.68. Basically I draw a PlotLines widget and then some InvisibleButtons over it. What stopped to work was IsItemActive in this lines of code: Previously is_active was true when clicking over this item but in 1.68 stopped to work.

ig.SetCursorScreenPos(b_pos)
ig.PushIDStr(ID)
ig.InvisibleButton("",ig.ImVec2(r*2, r*2))
local is_active = ig.IsItemActive()
ig.PopID()

I looked in docs/CHANGELOG.txt for changes in 1.68 but I was not able to find any reference to IsItemActive. What could it be?

@ocornut ocornut changed the title Unknown change from 1.67 to 1.68 Plot functions registering hoverable change from 1.67 to 1.68 Mar 23, 2020
@ocornut
Copy link
Owner

ocornut commented Mar 23, 2020

Most likely it is
97ed97b

It was previously not registering its it.
If your button covers the same bounding box as the plot widget, you shouldn't need to submit the button at all, just use IsItemActive() after the plot.

@ocornut ocornut changed the title Plot functions registering hoverable change from 1.67 to 1.68 Plot functions registering their ID change from 1.67 to 1.68 Mar 23, 2020
@sonoro1234
Copy link
Author

sonoro1234 commented Mar 23, 2020

just use IsItemActive() after the plot.

I am not sure to understand. I was drawing several InvisibleButtons (for having control_points) over the PlotLines, so the code posted above was used several times, once for each InvisibleButton. Only one of them was active after mouse click.
If IsItemActive is only used after PlotLines, I wont be able to differentiate which InvisibleButton (or control_point) was clicked?

@ocornut
Copy link
Owner

ocornut commented Mar 23, 2020

No you won't but you can test the coordinate.
Otherwise maybe using SetItemAllowOverlap() after the Plot function can work.

@sonoro1234
Copy link
Author

No you won't but you can test the coordinate.

yes but this changes the logic behind Control_point (which was an independent widget that knows when it is activated) and makes everything less simple.

Otherwise maybe using SetItemAllowOverlap() after the Plot function can work.

I have tried this in 1.68 and does not solve the problem. perhaps in later versions?

@ocornut
Copy link
Owner

ocornut commented Mar 23, 2020

I don't know, you can investigate.

@sonoro1234
Copy link
Author

sonoro1234 commented Mar 23, 2020

No, it does not work

This was the self contained ControlPoint

function ControlPoint(ID,graph,pos,r)
	r = r or 5
	local origin = graph.origin
	local size = graph.size
	local x,y = pos.x,pos.y
	local xpos = size.x*(x - graph.xmin)/(graph.xmax-graph.xmin)
	local ypos = size.y*(y - graph.ymin)/(graph.ymax-graph.ymin)
	local b_pos = ig.ImVec2(origin.x + xpos - r,origin.y - ypos - r)
	ig.SetCursorScreenPos(b_pos)
	ig.PushIDStr(ID)
	ig.InvisibleButton("pp",ig.ImVec2(r*2, r*2))
	local is_active = ig.IsItemActive()
	ig.PopID()
	local draw_list = ig.GetWindowDrawList()
	draw_list:AddCircleFilled(ig.ImVec2(origin.x + xpos,origin.y - ypos), r, ig.U32(1,0,0,1))
	if is_active then
		local m = ig.GetIO().MousePos
		local xval = graph.xmin + (graph.xmax-graph.xmin)*(m.x - origin.x)/size.x
		local yval = graph.ymin + (graph.ymax-graph.ymin)*(-m.y + origin.y)/size.y
		pos.x = xval
		pos.y = yval
	end
end

where graph is PlotLines plus some info about its size ,position and internal coordinate limits. It is a pitty loosing this behaviour.

@sonoro1234
Copy link
Author

sonoro1234 commented Mar 23, 2020

Trying to change the ControlPoint logic I am now using isItemActive just after PlotLines but it never returns true!!

ig.IsItemHovered() and ig.IsMouseDown(0) does the trick

if ig.IsItemHovered() and ig.IsMouseDown(0) then
    local b_pos2 = b_pos + ig.ImVec2(r*2,r*2)
    local m = ig.GetIO().MousePos
    if m.x > b_pos.x and m.x < b_pos2.x and m.y > b_pos.y and m.y < b_pos2.y then
	 is_active = true
    end
end

But if mouse is moved too fast the coordinate test fails.

Solved with

if ig.IsItemHovered() and ig.IsMouseDown(0) then
    local b_pos2 = b_pos + ig.ImVec2(r*2,r*2)
    local m = ig.GetIO().MousePos - ig.GetIO().MouseDelta
    if m.x > b_pos.x and m.x < b_pos2.x and m.y > b_pos.y and m.y < b_pos2.y then
	 is_active = true
    end
end

@ocornut
Copy link
Owner

ocornut commented Sep 3, 2024

Just use IsItemActive() after the plot.

Actually this would have never worked, see #7935 and the fact that PlotEx() doesn't call InvisibleButton().

I made changes today (since #if IMGUI_VERSION_NUM > 19105) to make PlotEx() call ButtonBehavior() like practically every other items, so you can use IsItemActive() and other functions.

You probably solved this anyhow already, especially since overlap support was improved in 1.89.7.
It is possible that certain type of old code attempting to overlap stuff before or after Plot functions may now be broken.
The new solution is going to be simpler.

Let me know if this is still relevant for you and if you don't have a satisfying answer for it!

@ocornut ocornut closed this as completed Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants