Skip to content

⌨️ Keyboard Navigation & Accessibility

ParameterSpecification
Component ClassCollapsibleCategoryRuleEntry
Accessibility Interfacenet.minecraft.client.gui.narration.NarratableEntry
Narration PriorityNarrationPriority.HOVERED
Narration Element TypeNarratedElementType.TITLE
Toggle KeysGLFW_KEY_SPACE, GLFW_KEY_ENTER, GLFW_KEY_KP_ENTER
Collapse KeyGLFW_KEY_LEFT (Only active when expanded)
Expand KeyGLFW_KEY_RIGHT (Only active when collapsed)
Audio FeedbackSoundEvents.UI_BUTTON_CLICK (1.0F)

📖 Overview

Collapsible Game Rules includes full keyboard navigation and screen narration compliance, enabling players to manage complex game rule menus using keyboard inputs, controllers, or assistive screen readers without touching the mouse.


⌨️ Key Event Mapping Table

When a category header is focused in the RuleList, the following keyboard events are processed by keyPressed(KeyEvent event):

Key BindingGLFW ConstantAction TriggeredConditionAudio Feedback
SpaceGLFW_KEY_SPACEToggle ExpansionAlwaysUI_BUTTON_CLICK
Enter (Return)GLFW_KEY_ENTERToggle ExpansionAlwaysUI_BUTTON_CLICK
Numpad EnterGLFW_KEY_KP_ENTERToggle ExpansionAlwaysUI_BUTTON_CLICK
Left Arrow (←)GLFW_KEY_LEFTCollapse CategoryOnly if expanded == trueUI_BUTTON_CLICK
Right Arrow (→)GLFW_KEY_RIGHTExpand CategoryOnly if expanded == falseUI_BUTTON_CLICK

⚙️ Technical Implementation

1. Directional Key Processing

The implementation follows standard OS hierarchical tree-view navigation conventions:

java
@Override
public boolean keyPressed(KeyEvent event) {
    int keyCode = event.key();
    if (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER || keyCode == GLFW.GLFW_KEY_SPACE) {
        this.toggleAction.run();
        Minecraft.getInstance().getSoundManager()
                .play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
        return true;
    } else if (keyCode == GLFW.GLFW_KEY_LEFT && this.expanded) {
        this.toggleAction.run();
        Minecraft.getInstance().getSoundManager()
                .play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
        return true;
    } else if (keyCode == GLFW.GLFW_KEY_RIGHT && !this.expanded) {
        this.toggleAction.run();
        Minecraft.getInstance().getSoundManager()
                .play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
        return true;
    }
    return super.keyPressed(event);
}

2. Screen Reader Narration (updateNarration)

To ensure full accessibility for visually impaired players, the widget implements Minecraft's narration protocol:

java
@Override
public NarrationPriority narrationPriority() {
    return NarrationPriority.HOVERED;
}

@Override
public void updateNarration(NarrationElementOutput output) {
    output.add(NarratedElementType.TITLE, this.label);
}

Official documentation & web portal for Dasik Igaijinn mods.