Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static jsonui.layout.properties.Length.*; // px(), fr(), auto(), etc.
- public class Example {
- public static void main(String[] args) {
- UIBuilder bd = new UIBuilder();
- UIScreen ui = bd
- .begWindow("PrimaryWindow")
- // Window child widget handling is different from panels
- // all widgets are positioned by coordinate
- .addChild(bd.builder(GridPanel.BUILDER)
- // Conventinally we put a widget that covers the whole window as the "root"
- .fillWindow()
- .columns(auto(), px(200))
- .rows(auto())
- .gridGap(px(4))
- .areas(
- "Editor", "Toolbox"
- )
- // Using custom widget implementation
- // #child(String, IWidget)
- .child("Editor", new CADEditor())
- // Using widget builder provided by lib
- // #child(String, WidgetBuilder)
- .child("Toolbox", bd.builder(StrictTablePanel.BUILDER)
- .growDirection(Side.DOWN)
- .overflowDirection(Side.RIGHT)
- .gap(px(4))
- // Native builder helper to execute a code block on stage
- // Stage.INIT executes the code right after build; note that the widget is invalid which means changing subtree is not allowed here
- // Stage.ATTACH executes the code after the widget became valid
- // Stage.INITIAL_ATTACH executes the code after the widget became valid; this is conventionally used for modifying subtree based on data
- // Stage.UPDATE executes the code on each clientTick
- // Stage.RENDER executes the code on each render call
- .exec(Stage.INITIAL_ATTACH, self -> {
- // 'self' is the widget
- for(ToolboxOption option : ToolboxOption.OPTIONS.values()) {
- self.child(option.getName(), option);
- }
- })
- )
- )
- // Window doesn't support length units (yet)
- .size(
- w -> (int) (screenWidth() * (2F / 3F)),
- w -> (int) (screenHeight() * (3F / 5F))
- )
- .position(
- w -> Alignment.xForCenter(screenWidth(), w.getWidth()),
- w -> Alignment.yForCenter(screenHeight(), w.getHeight())
- )
- .endWindow("PrimaryWindow")
- .start("PrimaryWindow")
- .allowJEI()
- .allowFTBCoreSidebarButtons()
- // Finishes building and return a GUI object
- .finish();
- Minecraft.getInstance().displayScreen(ui);
- }
- }
- public class CADEditor extends GridPanel<CADNode> {
- // ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement