Class WidgetQuery
java.lang.Object
privbot.query.WidgetQuery
Fluent query over
Widget instances, similar to NPCQuery / ObjectQuery.
Prefer Widgets.queryAt(int) for inspector ids (group.child packed):
it seeds the subtree and expands one child layer (IF3 item rows).
Use root(int) with expandDescendants(int) and withAction(String...) to locate
a component by menu action inside a deep interface (e.g. ToA rewards Bank-all).-
Constructor Summary
ConstructorsConstructorDescriptionWidgetQuery(List<net.runelite.api.widgets.Widget> raw, net.runelite.api.Client client) Wraps a copy ofraw. -
Method Summary
Modifier and TypeMethodDescriptionbooleanempty()True when no widget is left.expandDescendants(int maxRounds) RepeatsexpandImmediateChildren()maxRoundstimes, accumulating all widgets up to that many levels below the current set (deduplicated by identity).For each current widget, appends all immediate children (same child discovery as the dialogue hook's tree walks: dynamic, static, nested, andWidget.getChildren()), preserving order and deduplicating by identity.Narrows this query in place and returns it.net.runelite.api.widgets.Widgetfirst()The first remaining widget, or null when the query is empty.net.runelite.api.widgets.WidgetNarrows bypredicate(in place) and returns the first match, or null.static WidgetQueryfromPacked(net.runelite.api.Client client, int packedId) Single root via inspector-style lookup.List<net.runelite.api.widgets.Widget> list()An unmodifiable view of the remaining widgets.root(int packedId) Add a widget resolved from an inspector packed id (group.child).roots()Adds all current top-level widget roots.intsize()The number of widgets left.static WidgetQuerystart(net.runelite.api.Client client) visible()Keeps widgets that are not hidden (Widget.isHidden()).Alias offilter(Predicate).withAction(String... options) Keeps widgets whoseWidget.getActions()list matches any of the given options (normalized text, same rules as component menu interaction: exact normalized match or substring contains).withExactText(String... texts) Keeps widgets whose normalizedWidget.getText()orWidget.getName()exactly matches any requested value (case-insensitive, colour tags stripped).Inventory-style slot:withNonEmptyName()logic or positiveWidget.getItemId()when the client omits the label but sets an item.Non-blankWidget.getName()or meaningful text after stripping colour tags (the same normalisation the dialogue hook uses).Keeps widgets whoseWidget.getText()orWidget.getName()contains any of the given substrings (case-insensitive, colour tags stripped).withWidget(net.runelite.api.widgets.Widget w) Addswto the working set; null is ignored.
-
Constructor Details
-
WidgetQuery
Wraps a copy ofraw. Widget reads in this class are not marshalled: build and run the chain on the client thread (thectx.widgetshook does this for its own verbs).
-
-
Method Details
-
start
-
fromPacked
Single root via inspector-style lookup. -
root
Add a widget resolved from an inspector packed id (group.child). -
roots
Adds all current top-level widget roots. Use withexpandDescendants(int)when querying globally for visible text or actions. -
withWidget
Addswto the working set; null is ignored. -
visible
Keeps widgets that are not hidden (Widget.isHidden()).On Impact, Elorin and SpawnPK a closed interface's widgets can still report not-hidden, so "visible" here does not prove the interface is drawn; prefer the hook's open/drawn checks.
-
withText
Keeps widgets whoseWidget.getText()orWidget.getName()contains any of the given substrings (case-insensitive, colour tags stripped).Usage:
widgets.queryAt(219_01).withText("Give me a task").first() -
withExactText
Keeps widgets whose normalizedWidget.getText()orWidget.getName()exactly matches any requested value (case-insensitive, colour tags stripped). -
withNonEmptyName
Non-blankWidget.getName()or meaningful text after stripping colour tags (the same normalisation the dialogue hook uses). Does not useWidget.getItemId()— empty name with a stale item id still fails (e.g. CoX reward line after the label clears). -
withItemOrName
Inventory-style slot:withNonEmptyName()logic or positiveWidget.getItemId()when the client omits the label but sets an item. -
expandImmediateChildren
For each current widget, appends all immediate children (same child discovery as the dialogue hook's tree walks: dynamic, static, nested, andWidget.getChildren()), preserving order and deduplicating by identity. -
expandDescendants
RepeatsexpandImmediateChildren()maxRoundstimes, accumulating all widgets up to that many levels below the current set (deduplicated by identity). -
withAction
Keeps widgets whoseWidget.getActions()list matches any of the given options (normalized text, same rules as component menu interaction: exact normalized match or substring contains). -
filter
Narrows this query in place and returns it. Queries are mutable and single-use; the predicate runs on the calling thread. A null predicate is ignored. -
where
Alias offilter(Predicate). -
first
public net.runelite.api.widgets.Widget first()The first remaining widget, or null when the query is empty. -
first
Narrows bypredicate(in place) and returns the first match, or null. -
list
An unmodifiable view of the remaining widgets. -
empty
public boolean empty()True when no widget is left. -
size
public int size()The number of widgets left.
-