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

Hand Mouse Cursor Flag #1913

Closed
aiekick opened this issue Jun 28, 2018 · 8 comments
Closed

Hand Mouse Cursor Flag #1913

aiekick opened this issue Jun 28, 2018 · 8 comments

Comments

@aiekick
Copy link
Contributor

aiekick commented Jun 28, 2018

Hello,

can we have a flag for the mouse cursor hand : ImGuiMouseCursor_Hand

like that i can use by example in glfw the system cursor :
g_MouseCursors[ImGuiMouseCursor_Hand] = glfwCreateStandardCursor(GLFW_HAND_CURSOR);

i have modifed the imgui code due to that, because i made a spetial control for the hyperlink
and i wanted to have a hand cursor on this control.

bool ImGui::ImGui_ClickableTextUrl(const char* label, const char* url, ImVec4 vColor, ImVec4 vHoveredColor, ImVec4 vClickColor)
{
	ImGuiWindow* window = ImGui::GetCurrentWindow();
	if (window->SkipItems)
		return;
	ImGuiContext& g = *GImGui;
	const ImGuiStyle& style = g.Style;
	const ImGuiID id = window->GetID(label);
	const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
	ImVec2 pos = window->DC.CursorPos;
	ImVec2 size = ImGui::CalcItemSize(ImVec2(0.0f, 0.0f), label_size.x + style.FramePadding.x * 1.0f, label_size.y);
	const ImRect bb(pos, pos + size);
	ImGui::ItemSize(bb, 0.0f);
	if (!ImGui::ItemAdd(bb, id))
		return;
	ImGuiButtonFlags flags = 0;
	bool hovered, held;
	bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held, flags);
	//ImGuiMouseCursor_Hand
	if (held || (g.HoveredId == id && g.HoveredIdPreviousFrame == id))
		ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
	// Render
	ImGui::RenderNavHighlight(bb, id);
	ImVec4 col = (hovered && held) ? vClickColor : hovered ? vHoveredColor : vColor;
	ImVec2 p0 = bb.Min;
	ImVec2 p1 = bb.Max;
	if (hovered && held)
	{
		p0 += ImVec2(1, 1);
		p1 += ImVec2(1, 1);
	}
	window->DrawList->AddLine(ImVec2(p0.x + style.FramePadding.x, p1.y), ImVec2(p1.x - style.FramePadding.x, p1.y), ImGui::GetColorU32(col));
	ImGui::PushStyleColor(ImGuiCol_Text, col);
	ImGui::RenderTextClipped(p0, p1, label, NULL, &label_size, style.ButtonTextAlign, &bb);
	ImGui::PopStyleColor(1);

	if (pressed)
	{
		OpenSystemFile::OpenUrl(url);
	}

	return pressed;
}

who do that :

2018-06-28_21-02-19

@ocornut
Copy link
Owner

ocornut commented Jun 29, 2018

Will do.
Need to add the cursor in the embedded cursor block FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS for software rendering support when io.MouseDrawCursor = true.

I changed the bindings a few months ago to not crash if they get an unknown cursor type (for people using old bindings) but since this cursor won't be used by imgui for a while it won't be a problem even with the old code.

@aiekick
Copy link
Contributor Author

aiekick commented Jun 29, 2018

ok i must propose a PR ?

@ocornut
Copy link
Owner

ocornut commented Jun 29, 2018

That would be helpful yes.. need support in all 3 framework bindings + software cursor.

@aiekick
Copy link
Contributor Author

aiekick commented Jun 29, 2018

ok i can also propose this hyperlink control. simplifeid to me more in the imgui style. and modify the demo to have a hyperlink who point here on the github page. i can inlcude in the demo the windows code for call the url in windows to open in the default browser. it will be helpfull if someone ca do same for ios and linux :)

@aiekick
Copy link
Contributor Author

aiekick commented Jun 29, 2018

i have done the modifications, and it work (software also) but for the hyperlink control i dont have normal, hovered and active color for text. maybe we need :
ImGuiCol_Text,
ImGuiCol_TextHovered,
ImGuiCol_TextActive,

@ocornut
Copy link
Owner

ocornut commented Jun 29, 2018

This is off-topic we'll talk about that separately. There's a TextURL() function here https://gist.github.com/dougbinks/ef0962ef6ebe2cadae76c4e9f0586c69#file-imguiutils-h-L228-L262
The platform api created for the viewport branch could want to include a handler to open url and/or files.
For now adding new colors in the Style structure is on hold until we refactor the style system, but I would like to add those colors eventually but this is frozen right now.

EDIT To clarify, the PR would be to add the new mouse cursor, not anything to do with the TextUrl function.

@aiekick
Copy link
Contributor Author

aiekick commented Jun 29, 2018

ah ok :)

@aiekick
Copy link
Contributor Author

aiekick commented Jun 29, 2018

the pr is sent :) ,we can close this topic i thinck

@ocornut ocornut closed this as completed Jun 29, 2018
ocornut added a commit that referenced this issue Jun 29, 2018
… crashing. Fixed typo and extraneous trailing space. Added Changelogs. (#1913, #1914)
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