Skip to content

Add MarkdownRenderer.getLinkAtPosition() for clickable links on ScriptPanels - #1007

Open
weavermedia wants to merge 1 commit into
christophhart:developfrom
weavermedia:feature/markdown-getlinkatposition
Open

Add MarkdownRenderer.getLinkAtPosition() for clickable links on ScriptPanels#1007
weavermedia wants to merge 1 commit into
christophhart:developfrom
weavermedia:feature/markdown-getlinkatposition

Conversation

@weavermedia

Copy link
Copy Markdown
Contributor

Markdown text drawn on a ScriptPanel via Content.createMarkdownRenderer() and Graphics.drawMarkdownText() renders hyperlinks as underlined text, but there is no way for the script to detect clicks on them, so links are purely decorative.

This adds one scripting API method to the MarkdownRenderer object:

Panel1.setMouseCallback(function(event)
{
	var link = md.getLinkAtPosition([event.x, event.y]);

	if (event.clicked && link.length > 0)
		Engine.openWebsite(link);
	else
		this.setMouseCursor(link.length > 0 ? "PointingHandCursor" : "NormalCursor", Colours.white, [0, 0]);
});

It returns the URL of the hyperlink at the given panel-relative [x, y] position, or an empty string. The script decides what to do with the link, and the same call drives a hand cursor on hover.

Implementation notes:

  • The hit-test reuses the hyperlink rectangles the parser already stores: the body of MarkdownParser::getHyperLinkForEvent is extracted unchanged into a new point-based getHyperLinkForPoint, with the event version delegating to it, so all existing callers (doc browser etc.) behave identically.
  • The new method translates the panel-local position into document space using the area set by setTextBounds() and takes the same lock as the other MarkdownRenderer scripting methods.
  • Returns an empty string if setTextBounds() has not been called yet; a malformed position argument reports a script error via the existing ApiHelpers::getPointFromVar validation.

Tested in the IDE: clicking a rendered link opens the browser, clicks on plain text and empty space do nothing, hover cursor works, and internal and external links in the in-app documentation browser still work through the delegating code path.

Requested on the forum: https://forum.hise.audio/topic/14023/how-to-do-text-links-in-a-settings-panel

🤖 Generated with Claude Code

…tPanels

Markdown text drawn on a ScriptPanel via Content.createMarkdownRenderer()
and Graphics.drawMarkdownText() renders hyperlinks as underlined text,
but there was no way for the script to detect clicks on them.

This adds a getLinkAtPosition([x, y]) method to the scripting
MarkdownRenderer object that returns the URL of the hyperlink at the
given panel-relative position (or an empty string), so a panel mouse
callback can open links with Engine.openWebsite() and show a hand
cursor on hover.

The hit-test reuses the existing hyperlink rectangles: the body of
MarkdownParser::getHyperLinkForEvent is extracted unchanged into a new
point-based getHyperLinkForPoint, with the event version delegating
to it, so all existing callers behave identically.

Requested on the forum:
https://forum.hise.audio/topic/14023/how-to-do-text-links-in-a-settings-panel

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant