Skip to content

CategoryTreeContainer ​

com.jsmacrosce.jsmacros.client.gui.settings.CategoryTreeContainer

Builds a settings-category tree whose nodes request category selection through a supplied parent.
The public constructor makes a head node. Add paths before calling init() on the head; the parent host registers the controls.
Paths added afterward are not initialized automatically, and repeated initialization does not remove earlier registered controls.

js
function makeCategoryTree(parent, font) {
  const CategoryTree = Java.type('com.jsmacrosce.jsmacros.client.gui.settings.CategoryTreeContainer');  
  const tree = new CategoryTree(10, 10, 160, 120, font, parent);  
  tree.addCategory(Java.to(['settings', 'general'], 'java.lang.String[]'));  
  tree.init();  
  return tree;  
}

Here, parent and font are supplied by the caller.

Constructors ​

new CategoryTreeContainer ​

new CategoryTreeContainer(int x, int y, int width, int height, Font textRenderer, ICategoryTreeParent parent)#
Stores geometry, font and parent for an initially expanded, empty head with category "HEAD" and zero row height. Does not initialize or register controls; call init() on this head after adding paths.

Parameters:

  • x: left coordinate in GUI space
  • y: top coordinate in GUI space
  • width: tree width in GUI units
  • height: tree height in GUI units
  • textRenderer: non-null font used to size child rows
  • parent: non-null parent used for widget registration and category-selection requests

Fields ​

btnHeight ​

btnHeight: int#
Stored row height in GUI units; the head starts at zero and new child nodes use the font line height plus three. Direct writes do not resize existing controls or update offsets automatically.

category ​

category: Stringread-only#
Path segment for this node; the public head uses the "HEAD" sentinel, which is not forwarded as a path segment.

children ​

Initially empty mutable map from immediate path segments to child nodes, reused by addCategory. External mutations do not initialize or register controls or establish parent links; layout sorts keys separately.

expandBtn ​

expandBtn: Button#
Expand/collapse control created during head initialization for a non-head node with children; null before initialization and normally on heads and leaves. Field reassignment alone does not replace the registered control.

isHead ​

isHead: boolean#
Whether this node is the tree head: true for the public constructor and false for nodes created by addCategory. Changing this routing, layout and initialization discriminator does not rebuild controls or establish a different parent.

scroll ​

scroll: Scrollbar#
Head scrollbar used for page-count updates; null before head initialization and normally null on child nodes. Head initialization assigns a newly registered scrollbar; field reassignment alone does not replace the registered control.

showBtn ​

showBtn: Button#
Selection control created during head initialization for a non-head node; null beforehand and normally on the head. Its label uses the category as a translation key; field reassignment alone does not replace the registered control.

topScroll ​

topScroll: int#
Head vertical scroll offset in GUI units, initially zero and reset by head initialization. Direct writes do not relayout; onScrollbar stores the integer part of height times its page argument and updates offsets.

Methods ​

addCategory ​

addCategory(String... category): CategoryTreeContainer#
Adds or reuses nodes along an ordered path relative to this node. New nodes are not initialized or registered. A nonempty path added through the head updates offsets and any existing scrollbar page count; adding through a non-head does not. An empty path returns immediately without layout updates. This operation does not select or expand nodes.

Parameters:

  • category: ordered non-null path segments relative to this node
Returns: the terminal node, or this node for an empty path

extractRenderState ​

extractRenderState(GuiGraphicsExtractor drawContext, int mouseX, int mouseY, float delta): void#
This rendering hook submits no content; the host renders registered widgets separately.

Parameters:

  • drawContext: graphics context, unused
  • mouseX: mouse x-coordinate in GUI space, unused
  • mouseY: mouse y-coordinate in GUI space, unused
  • delta: caller-supplied frame value, unused

init ​

init(): void#
Initializes the tree from its head, registering a scrollbar and controls for the existing descendants with the parent. Resets the head scroll offset and lays out the controls. Calling this again registers additional controls without clearing tracking or removing previously registered ones. Existing node expansion flags are retained and no category-selection request is made. A non-head call throws a runtime exception before doing any work.

onScrollbar ​

onScrollbar(double page): void#
Stores (int) (height * page) as this node's scroll offset and relayouts only when that offset changes. Intended for the head scrollbar: a non-head call changes that node's offset but delegates relayout to the head without changing the head offset. This does not set the thumb to the requested page. Relayout updates the scrollbar page count, which can reset the thumb and notify this callback again with a zero offset when the content occupies less than one page.

Parameters:

  • page: scroll amount in viewport-height units; for example, 0.5 is half the viewport height. The argument is not clamped directly; a scrollbar page-count reset during relayout can replace the resulting head offset with zero.

selectCategory ​

selectCategory(String... category): void#
Forwards a selection request to the parent; non-head nodes prepend their own segment, while the head forwards the supplied array unchanged. An empty path requests the current non-head node's full path, without the head sentinel. No local selection state, path validation, node creation or expansion is performed; the receiving parent decides how to handle the request.

Parameters:

  • category: ordered relative path segments to append after this node; the head forwards this path unchanged

updateOffsets ​

updateOffsets(): void#
Recomputes node layout and existing button positions and visibility from the head. Child rows are laid out in sorted path-key order; collapsed subtrees do not advance the visible layout. Buttons are visible only when their full row is within the head viewport and every ancestor is expanded. This does not create controls, resize node buttons or change their active flags, or consult the container visibility flag. Child rows begin at the head y-coordinate minus its scroll offset; child-node heights are recomputed while the head keeps its viewport height. If present, the head scrollbar's page count is updated from the computed layout height. This can change the scrollbar's size, active and visible states; a page count below one resets it and notifies its callback, which can reset the head offset and relayout again.