Class WidgetQuery

    • Constructor Detail

      • WidgetQuery

        public WidgetQuery​(Context ctx)
    • Method Detail

      • withId

        public WidgetQuery withId​(int packedId)
        Filters for a widget with the exact packed ID. Useful if you know the full ID (e.g., WidgetInfo.INVENTORY.getId()).
        Overrides:
        withId in class AbstractQuery<WidgetEntity,​WidgetQuery,​net.runelite.api.widgets.Widget>
        Parameters:
        packedId - The packed widget id to search for. Packed ID's encapsulate both the group and child id into a single integer value.
        Returns:
        WidgetQuery
      • get

        public WidgetEntity get​(int packedId)
        Retrieves the first WidgetEntity matching the specified packed ID.

        This method filters widgets by their packed ID, which is a composite of the group ID and child ID. It is useful when the exact packed ID of a widget is known.

        Parameters:
        packedId - The packed ID of the widget to retrieve. This ID encapsulates both the group and child ID into a single integer value.
        Returns:
        The WidgetEntity corresponding to the specified packed ID, or null if no matching widget is found.
      • get

        public WidgetEntity get​(net.runelite.api.widgets.WidgetInfo widgetInfo)
        Retrieves the first WidgetEntity that matches the specified WidgetInfo.

        This method filters widgets based on the packed ID retrieved from the WidgetInfo instance.

        Parameters:
        widgetInfo - The WidgetInfo instance containing the packed ID to search for. The packed ID incorporates both the group and child ID.
        Returns:
        The corresponding WidgetEntity, or null if no match is found.
      • get

        public WidgetEntity get​(int groupId,
                                int childId)
        Retrieves a WidgetEntity based on the specified group ID and child ID.

        This method accesses a widget using its hierarchical identifiers:

        • groupId: Represents the interface group to which the widget belongs.
        • childId: Identifies the specific widget within the group.

        The widget is created and returned as a WidgetEntity instance, allowing for further interaction or queries.

        Parameters:
        groupId - The group ID of the widget to retrieve. Represents the top-level container or interface.
        childId - The child ID of the widget to retrieve. Represents the specific item within the group.
        Returns:
        A WidgetEntity representing the widget with the provided group ID and child ID, or null if no matching widget is found.
      • withGroupChild

        public WidgetQuery withGroupChild​(int group,
                                          int child)
        Filters for a widget with a specific group ID and child ID.

        This method evaluates the group and child ID of each widget by decomposing its packed ID. The packed ID is a combination where the group ID occupies the higher 16 bits, and the child ID occupies the lower 16 bits.

        For example, in the packed id format:
        packedId = (groupId << 16) | childId
        The group ID and child ID are derived as follows:

        • groupId = packedId >>> 16
        • childId = packedId & 0xFFFF

        Only the widgets that match the specified group and child ID will be included in the resulting query.

        Parameters:
        group - The group identifier of the widget.
        child - The child identifier of the widget.
        Returns:
        WidgetQuery A new query filtered for widgets with the specified group and child IDs.
      • inGroup

        public WidgetQuery inGroup​(int groupId)
        Filters for widgets belonging to a specific Interface Group. Example: 149 is the Inventory group.
        Parameters:
        groupId - The group id of the widget to search for
        Returns:
        WidgetQuery
      • withChildId

        public WidgetQuery withChildId​(int childId)
        Filters for a specific child component ID within a group. Note: This checks the lower bits of the packed ID.
        Parameters:
        childId - The child widget id to search for
        Returns:
        WidgetQuery
      • withIndex

        public WidgetQuery withIndex​(int index)
        Filters by the widget's index in its parent's array. Crucial for dynamic lists (chatbox messages, bank slots) where every item has the same ID but a different index.
        Parameters:
        index - The index in the widgets parent array to search for
        Returns:
        WidgetQuery
      • visible

        public WidgetQuery visible()
        Filters for widgets which are currently visible on the canvas.
        Returns:
        WidgetQuery
      • withSprite

        public WidgetQuery withSprite​(int spriteId)
        Finds widgets by their Sprite ID (images).
        Parameters:
        spriteId - The integer id of the sprite
        Returns:
        WidgetQuery
      • withListener

        public WidgetQuery withListener()
        Finds widgets that have a specific listener (e.g., "Continue" buttons).
        Returns:
        WidgetQuery
      • withAction

        public WidgetQuery withAction​(java.lang.String action)
        Filters for widgets with a specific action.
        Parameters:
        action - The action string to filter widgets for
        Returns:
        WidgetQuery
      • withText

        public WidgetQuery withText​(java.lang.String text)
        Filters for widgets containing the specified text in name, text, or actions.
        Parameters:
        text - The text to search for
        Returns:
        WidgetQuery
      • withText

        public WidgetQuery withText​(java.lang.String text,
                                    boolean exact)
        Filters for widgets containing the specified text in name, text, or actions.
        Parameters:
        text - The text to search for
        exact - True if the text should match exactly otherwise a substring is used.
        Returns:
        WidgetQuery