Link to reagent ingredients on the same Guidebook page (#36700)
* Add in-page links for guidebook reagent recipes * Add links to microwave recipes * This function is too specific to be in Control extensions * Better naming * Wrap RichTextLabel instead of subclassing * "Activate" is ambiguous
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Numerics;
|
||||
using Content.Client.Guidebook.Controls;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
@@ -68,6 +70,52 @@ public static class ControlExtension
|
||||
return controlList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Search the control’s tree for a parent node of type T
|
||||
/// E.g. to find the control implementing some event handling interface.
|
||||
/// </summary>
|
||||
public static bool TryGetParentHandler<T>(this Control child, [NotNullWhen(true)] out T? result)
|
||||
{
|
||||
for (var control = child; control is not null; control = control.Parent)
|
||||
{
|
||||
if (control is not T handler)
|
||||
continue;
|
||||
|
||||
result = handler;
|
||||
return true;
|
||||
}
|
||||
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find the control’s offset relative to its closest ScrollContainer
|
||||
/// Returns null if the control is not in the tree or not visible.
|
||||
/// </summary>
|
||||
public static Vector2? GetControlScrollPosition(this Control child)
|
||||
{
|
||||
if (!child.VisibleInTree)
|
||||
return null;
|
||||
|
||||
var position = new Vector2();
|
||||
var control = child;
|
||||
|
||||
while (control is not null)
|
||||
{
|
||||
// The scroll container's direct child is re-positioned while scrolling,
|
||||
// so we need to ignore its position.
|
||||
if (control.Parent is ScrollContainer)
|
||||
break;
|
||||
|
||||
position += control.Position;
|
||||
|
||||
control = control.Parent;
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
public static bool ChildrenContainText(this Control parent, string search)
|
||||
{
|
||||
var labels = parent.GetControlOfType<Label>();
|
||||
|
||||
Reference in New Issue
Block a user