| 12345678910111213141516171819202122232425262728 |
- <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 1.5.4"><title>Nifty GUI - Best Practices</title><link rel="stylesheet" href="./asciidoctor.css">
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
- <link rel="stylesheet" href="./coderay-asciidoctor.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css"><link rel="stylesheet" href="/home/travis/build/jMonkeyEngine/wiki/build/asciidoc/html5/jme3/advanced/twemoji-awesome.css"></head><body class="article toc2 toc-left"><div id="header"><div id="toolbar"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc/jme3/advanced/nifty_gui_best_practices.adoc"><i class="fa fa-pencil-square" aria-hidden="true"></i></a><a href="https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc/jme3/advanced/"><i class="fa fa-plus-square" aria-hidden="true"></i></a><input dir="auto" style="position: relative; vertical-align: top;" spellcheck="false" autocomplete="off" class="searchbox__input aa-input" id="doc-search" name="search" placeholder="Search in the doc" required="required" type="search"></div><h1>Nifty GUI - Best Practices</h1><div class="details"><span class="author" id="author"></span><br><span id="revnumber">version ,</span> <span id="revdate">2016/03/17 20:48</span></div><div id="toc" class="toc2"><div id="toctitle">Table of Contents</div><ul class="sectlevel1"><li><a href="#xml-or-java">XML or Java?</a></li><li><a href="#validate-the-xml-before-loading">Validate the XML before loading</a></li><li><a href="#use-code-completion">Use Code Completion</a></li><li><a href="#use-the-id-string-right">Use the ID String Right</a></li><li><a href="#sizing-layers-and-panels">Sizing Layers and Panels</a></li><li><a href="#colorcode-for-clarity">Colorcode for Clarity</a></li></ul></div></div><div id="content"><div id="preamble"><div class="sectionbody"><div class="paragraph"><p>This page is a short list of best practices that you should know of when starting to use Nifty <abbr title="Graphical User Interface">GUI</abbr>. The JME3 tutorials focus on JME3-Nifty integration related details. You will find more features in the <a href="https://github.com/nifty-gui/nifty-gui/raw/1.4/nifty-core/manual/nifty-gui-the-manual-1.3.2.pdf">Nifty GUI Manual</a>.</p></div>
- <div class="olist arabic"><ol class="arabic"><li><p><a href="../../jme3/advanced/nifty_gui.html">Nifty GUI Concepts</a></p></li><li><p><strong>Nifty <abbr title="Graphical User Interface">GUI</abbr> Best Practices</strong></p></li><li><p><a href="../../jme3/advanced/nifty_gui_xml_layout.html">Nifty GUI XML Layout</a> or <a href="../../jme3/advanced/nifty_gui_java_layout.html">Nifty GUI Java Layout</a></p></li><li><p><a href="../../jme3/advanced/nifty_gui_overlay.html">Nifty GUI Overlay</a> or <a href="../../jme3/advanced/nifty_gui_projection.html">Nifty GUI Projection</a></p></li><li><p><a href="../../jme3/advanced/nifty_gui_java_interaction.html">Nifty GUI Java Interaction</a></p></li></ol></div></div></div>
- <div class="sect1"><h2 id="xml-or-java">XML or Java?</h2><div class="sectionbody"><div class="paragraph"><p>You can build Nifty GUIs using XML or Java syntax. Which one should you choose? The XML and Java syntax are equivalent, so is it an either-or choice? Not quite. You typically use XML and Java together.</p></div>
- <div class="ulist"><ul><li><p>Build your basic static UI layout using XML - it’s cleaner to write and read.</p></li><li><p>Use Java syntax to control the dynamic parts of the <abbr title="Graphical User Interface">GUI</abbr> at runtime - it’s easier to interact with object-oriented code.</p></li><li><p><strong>Example:</strong> You design two UIs with slightly different XML layouts for mobile and desktop. If you use the same IDs for equivalent elements, your dynamic Java code works the same no matter which of the two base XML layout you use it on. This allows you to switch between a phone and a desktop UI by simply swapping one base XML file.</p></li></ul></div>
- <div class="ulist"><ul><li><p>When you open an XML file, you can switch between XML Editor and <abbr title="Graphical User Interface">GUI</abbr> Preview mode.</p></li></ul></div></div></div>
- <div class="sect1"><h2 id="validate-the-xml-before-loading">Validate the XML before loading</h2><div class="sectionbody"><div class="paragraph"><p>The <a href="http://nifty-gui.sourceforge.net/projects/1.4.2/nifty/nifty/apidocs/index.html?de/lessvoid/nifty/Nifty.html">Nifty class</a> has <em>validateXml()</em> method that takes the same input XML argument as <em>fromXml()</em>. Nifty does not validate the Xml by default, and will blow up in surprising ways if your XML does not conform to the schema. Adding the validation step will save you debugging time. You can validate right before loading, or in your unit tests.</p></div></div></div>
- <div class="sect1"><h2 id="use-code-completion">Use Code Completion</h2><div class="sectionbody"><div class="ulist"><ul><li><p>Include the following XML schema in the first line of your NiftyGUI XML files</p></li></ul></div>
- <div class="listingblock"><div class="content"><pre><?xml version="1.0" encoding="UTF-8"?>
- <nifty xmlns="http://nifty-gui.lessvoid.com/nifty-gui" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd">
- <!-- Your IDE now tells you that one <screen></screen> element is expected here, etc. -->
- </nifty></pre></div></div>
- <div class="ulist"><ul><li><p>Now your IDE (including the jMonkeyEngine SDK) will display extra info and do code completion for the Nifty <abbr title="Graphical User Interface">GUI</abbr> <abbr title="Application Programming Interface">API</abbr>.</p></li></ul></div></div></div>
- <div class="sect1"><h2 id="use-the-id-string-right">Use the ID String Right</h2><div class="sectionbody"><div class="ulist"><ul><li><p>If you want to interact with an element, give it an ID (String).</p></li><li><p>Use transparent ID-less panels as anonymous spacers.</p></li></ul></div></div></div>
- <div class="sect1"><h2 id="sizing-layers-and-panels">Sizing Layers and Panels</h2><div class="sectionbody"><div class="ulist"><ul><li><p>Specify widths and heights in percent to allow the <abbr title="Graphical User Interface">GUI</abbr> to scale.</p></li><li><p>Use <code>*</code> instead of a fixed value to make the element fill the remaining space automatically.</p></li><li><p>Be cautious when specifying fixed sizes, and test the outcome in various resolutions.</p></li></ul></div></div></div>
- <div class="sect1"><h2 id="colorcode-for-clarity">Colorcode for Clarity</h2><div class="sectionbody"><div class="paragraph"><p>Screens, layers, and panels…</p></div>
- <div class="ulist"><ul><li><p>… can have an RGBA background color.<br>
- You can use temporary colors during the design phase to highlight which container is which.</p></li><li><p>… can be transparent.<br>
- In the finished <abbr title="Graphical User Interface">GUI</abbr>, screens, layers, and panels are typically transparent; the visible elements are the images, text fields, and controls, inside the panels.</p></li></ul></div>
- <div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>During development (and during a tutorial), the following debug code makes all panels visible. This helps you arrange them and find errors.</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">nifty.setDebugOptionPanelColors(<span class="predefined-constant">true</span>);</code></pre></div></div>
- <div class="paragraph"><p>Before the release, and during testing, set the debug view to false again.</p></div></td></tr></table></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2019-12-20 23:30:51 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
- apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
- indexName: 'jmonkeyengine',
- inputSelector: '#doc-search',
- debug: false // Set debug to true if you want to inspect the dropdown
- });</script></body></html>
|