From 01a21f3d4ff1c2779acd5827279779d3d41927f2 Mon Sep 17 00:00:00 2001 From: Pierce Brooks Date: Mon, 25 May 2026 23:45:01 -0400 Subject: [PATCH 1/2] render a tooltip of the url for any links that your cursor hovers on --- .gitignore | 3 ++- imhtml.cpp | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 96e46c4..9798a03 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build .cache -imgui.ini \ No newline at end of file +imgui.ini +.DS_Store diff --git a/imhtml.cpp b/imhtml.cpp index 72e107b..6537542 100644 --- a/imhtml.cpp +++ b/imhtml.cpp @@ -143,6 +143,7 @@ class BrowserContainer : public litehtml::document_container { private: ImVec2 bottomRight = ImVec2(0, 0); std::string title = "Browser"; + std::string attr = ""; std::string loadUrl = ""; std::string currentUrl = ""; std::vector history = {}; @@ -158,6 +159,7 @@ class BrowserContainer : public litehtml::document_container { bottomRight.x = std::max(bottomRight.x, point.x); bottomRight.y = std::max(bottomRight.y, point.y); } + std::string get_attr() { return attr; } std::string get_title() { return title; } std::string pop_load_url() { if (loadUrl.empty()) { @@ -895,7 +897,15 @@ class BrowserContainer : public litehtml::document_container { } virtual void on_mouse_event(const litehtml::element::ptr& el, litehtml::mouse_event event) override { - // TODO + if (el != nullptr && ImGui::IsWindowHovered()) { + const char* tag = el->get_tagName(); + const char* href = el->get_attr("href"); + if (tag != nullptr && href != nullptr && std::string(tag) == "a" && event == litehtml::mouse_event_enter) { + attr = std::string(href); + } else if (event == litehtml::mouse_event_leave) { + attr = ""; + } + } } virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, @@ -1135,6 +1145,10 @@ bool Canvas(const char* id, const char* html, float width, std::string* clickedU ImGui::ItemSize(bb.GetSize()); ImGui::ItemAdd(bb, ImGui::GetID(id)); + if (!state.container->get_attr().empty()) { + ImGui::SetTooltip("%s", state.container->get_attr().c_str()); + } + if (std::string url = state.container->pop_load_url(); !url.empty()) { if (clickedURL) { *clickedURL = url; From a9948a8ab640cf2bc75f4def44181d40f73ce8fc Mon Sep 17 00:00:00 2001 From: Pierce Brooks Date: Sun, 31 May 2026 18:10:16 -0400 Subject: [PATCH 2/2] address upstream author's recommendations surrounding tooltip purpose flexibility --- build_example.sh | 4 ++-- examples/hello_world.html | 8 ++++---- fonts/JetBrainsMono-Bold.ttf | Bin 0 -> 251456 bytes fonts/NotoSans-Bold.ttf | Bin 0 -> 779384 bytes imhtml.cpp | 35 ++++++++++++++++++++++++++--------- imhtml.hpp | 3 +++ main.cpp | 14 +++++++++++--- 7 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 fonts/JetBrainsMono-Bold.ttf create mode 100644 fonts/NotoSans-Bold.ttf diff --git a/build_example.sh b/build_example.sh index 4ffdcb2..d976cc4 100755 --- a/build_example.sh +++ b/build_example.sh @@ -1,4 +1,4 @@ #!/bin/bash -cmake -B build -DCMAKE_BUILD_TYPE=Release -cmake --build build \ No newline at end of file +cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_VERSION_MINIMUM=3.5 +cmake --build build diff --git a/examples/hello_world.html b/examples/hello_world.html index be955a7..8183bcd 100644 --- a/examples/hello_world.html +++ b/examples/hello_world.html @@ -26,8 +26,8 @@

ImHTML Example ({clicks} clicks)

Text

-

- Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam +

+ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet @@ -36,7 +36,7 @@

Text

Background Color & Border

Box Test

Links

- GitHub + GitHub

Flexbox

1
@@ -46,7 +46,7 @@

Flexbox

Image

- + ./images/example.jpg

Lists