laudaicat
Topic Author
Posts: 4
Joined: 19 Feb 2023, 08:07

Get screen rect of Hyperlink

18 Jul 2025, 12:14

Hi,
I working on tutorial for player. I want to highlight and spot to HyperLink in Run (RichText), assist player click to that. I try to get screen position but it always give me Empty Rect.

This is what i tried:
pThis->UpdateLayout();
        auto* hyperlink = Noesis::DynamicCast<Noesis::Hyperlink*>(args.source);
        //auto renderBounds = hyperlink->GetRenderBounds();
        float width = hyperlink->GetActualWidth();
        float height = hyperlink->GetActualHeight();
        auto* text =
          Noesis::DynamicCast<Noesis::TextBlock*>(hyperlink->GetParent());
        //auto* parent = g_noesis().findVisualParent<Noesis::TextBlock>(pThis);
        auto local = Noesis::VisualTreeHelper::GetContentBounds(hyperlink);
        // If bounds are still empty, try getting from parent TextBlock
        if (local.IsEmpty()) {
          local = Noesis::VisualTreeHelper::GetDescendantBounds(text);
        }

        auto tlInTb =
          hyperlink->TranslatePoint(Noesis::Point(local.x, local.y), text);
        auto transform = hyperlink->TransformToAncestor(text);

And, it great if we can get multiline rect.
 
User avatar
sfernandez
Site Admin
Posts: 3364
Joined: 22 Dec 2011, 19:20

Re: Get screen rect of Hyperlink

18 Jul 2025, 12:55

Hi,

There is no API to get the bounding box of a text Inline, but maybe you can achieve what you want just by using styles.

You can define a Style with triggers that can change the appearance of the Hyperlink to highlight it.

Could something like that work for you?
 
laudaicat
Topic Author
Posts: 4
Joined: 19 Feb 2023, 08:07

Re: Get screen rect of Hyperlink

18 Jul 2025, 13:28

In tutorial mode, i want make semi black screen except that hyperlink with arrow point to that link. For now, changed hyperlink style and spot rect to entire RichText area, but better if i can spot extractly that hyperlink i want user click to.
 
User avatar
sfernandez
Site Admin
Posts: 3364
Joined: 22 Dec 2011, 19:20

Re: Get screen rect of Hyperlink

24 Jul 2025, 11:15

The only thing that can be done with a TextBlock is obtaining its internal FormattedText and then ask the x,y position of a character index inside the text:
formattedText->GetGlyphPosition(index, false, x, y);
The FormattedText provides also info about the lines rendered by the TextBlock:
uint32_t numLines = formattedText->GetNumLines();
const LineInfo& line = formattedText->GetLineInfo(index);
Maybe you can use that to calculate the bounding box of the Hyperlink.
 
laudaicat
Topic Author
Posts: 4
Joined: 19 Feb 2023, 08:07

Re: Get screen rect of Hyperlink

26 Jul 2025, 10:49

Thanks for your suggest, i solved my issue.
 
User avatar
sfernandez
Site Admin
Posts: 3364
Joined: 22 Dec 2011, 19:20

Re: Get screen rect of Hyperlink

04 Aug 2025, 13:12

Great to hear that, did you use the FormattedText API to achieve it?

I'm marking this as solved.

Who is online

Users browsing this forum: Semrush [Bot] and 5 guests