Get screen rect of Hyperlink
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:
And, it great if we can get multiline rect.
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:
Code: Select all
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);
-
-
sfernandez
Site Admin
- Posts: 3364
- Joined:
Re: Get screen rect of Hyperlink
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?
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?
Re: Get screen rect of Hyperlink
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.
-
-
sfernandez
Site Admin
- Posts: 3364
- Joined:
Re: Get screen rect of Hyperlink
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:
The FormattedText provides also info about the lines rendered by the TextBlock:
Maybe you can use that to calculate the bounding box of the Hyperlink.
Code: Select all
formattedText->GetGlyphPosition(index, false, x, y);Code: Select all
uint32_t numLines = formattedText->GetNumLines();
const LineInfo& line = formattedText->GetLineInfo(index);Re: Get screen rect of Hyperlink
Thanks for your suggest, i solved my issue.
-
-
sfernandez
Site Admin
- Posts: 3364
- Joined:
Re: Get screen rect of Hyperlink
Great to hear that, did you use the FormattedText API to achieve it?
I'm marking this as solved.
I'm marking this as solved.
Who is online
Users browsing this forum: Semrush [Bot] and 5 guests