Skip to content

LockButtonWidgetHelper ​

com.jsmacrosce.jsmacros.client.api.helper.screen.LockButtonWidgetHelper

Since1.8.4

A lock button toggles between locked and unlocked when pressed. Its Minecraft widget is fixed at 20 by 20 pixels; its builder's size settings do not change that.

IScreen.lockButtonBuilder() starts unlocked; its boolean overload sets the initial state.

js
const screen = Hud.createScreen("a screen", true);  
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
 const lock = self.lockButtonBuilder()
    .pos(10, 20)
    .action(JavaWrapper.methodToJava(function (btn) {
      Chat.log(`locked: ${btn.isLocked()}`);  
    }))
    .build();  

 // the state can be set outright, without going through a press
 lock.setLocked(true);  
 Chat.log(`locked: ${lock.isLocked()}`);  
}));  
Hud.openScreen(screen);

Available in scripts as Widgets.LockButton.

Nested types ​

Constructors ​

new LockButtonWidgetHelper ​

new LockButtonWidgetHelper(LockIconButton btn)#
Wraps the supplied lock button with the default z-index of zero.

Parameters:

  • btn: the lock button to wrap
new LockButtonWidgetHelper(LockIconButton btn, int zIndex)#
Wraps the supplied lock button with the given drawing-order z-index.

Parameters:

  • btn: the lock button to wrap
  • zIndex: the helper's z-index for screen drawing order

Methods ​

isLocked ​

isLocked(): booleanSince1.8.4#
Returns the button's current locked state.
Returns: true if the button is locked, false otherwise.

setLocked ​

setLocked(boolean locked): LockButtonWidgetHelperSince1.8.4#
Sets the locked state directly without pressing the button or invoking its action. The visual state is used on the next render.

Parameters:

  • locked: whether to lock the button or not
Returns: self for chaining.

toString ​

toString(): String#
Returns a diagnostic string containing the current message and locked state. The message text is inserted without JSON escaping.
Returns: a formatted diagnostic in the form LockButtonWidgetHelper:{"message": "%s", "locked": %b}