Widgets

The Nuklear widgets (and the nk API presenting them) should in many ways be familiar. Sensible naming allows for many of these features to be discovered while programming in your favorite IDE, but let's explore the main widgets and how they function:

Widget name Description
NkButtonLabel A standard push button widget, the API reports when it has been clicked. See NkButtonImage also (to use an image instead of a text label) and NkButtonImageLabel to include both.
NkCheckboxLabel A checkbox displays a familiar box next to the label that's either checked or not. The API reports when its value has changed.
NkColorPicker This is a special button that opens a color picker. This form returns the currently selected color, or you can use NkColorPick, which reports when the value changes.
NkComboBox This is a combobox container for dropping down a selection. Each item within it can contain text, an image, or both (see the APIs beginning with NkComboItem).
NkGroup(Begin/End) This adds a grouping for widgets in an interface. A group has a title and a scrollbar, if required. To manually control the scroll behavior, you can instead use NkGroupScrolledBegin. The widgets declared between begin and end will be included. The begin function returns > 0 if the contents should be drawn. 
NkImage This displays a simple image in the interface.
NkMenubar(Begin/End) For add a menu bar to the user interface, this requires the use of the various APIs beginning with NkMenu and NkMenuItem as well. The begin function returns > 0 if the contents should be drawn.
NkPopup(Begin/End) This displays a popup over the current content; the widgets declared between begin and end will be included. The begin function returns > 0 if the contents should be drawn.
NkRadioLabel A radio selection is like a combobox but offers multiple possible values, each added using this function. The return value indicates whether the specified item has been selected.
NkSlider(Int/Float) The NkSlider functions add a slide bar with specified minimum, maximum, and current values. The API reports when the value has changed. An alternative format, NkSlide(Int/Float), returns the current value.
NkTexteditString This is a text entry widget. This function requires a buffer to edit; this can more easily be set through NkEditStringZeroTerminated(). There are also many helpful APIs starting with NkTextedit that can be used to manage the text content.
NkTree(Push/Pop) Tree widgets can be used to allow sections of the user interface to be expanded and collapsed or to present tree-based data on the screen. Functions beginning with NkTreePush mark the start of a new tree section and NkTreePop ends that section (or the root of the tree). The TreeType named TreeNode marks a user interface style tree and TreeTab is for data style tree.
Window (NkBegin, NkEnd) A window is required to contain all widgets within Nuklear (anything declared outside this scope will be ignored or cause an error). A window is declared with NkBegin or NkBeginTitled and marked as complete with NkEnd. Various window management functions are available and they start with NkWindow.

 

As you can see, many of these widgets are straightforward. The more complex ones have semantics for opening and closing their definition that become familiar over time. This is due to the immediate mode nature of the API and its design to not retain any state. Common semantics are for containers to return a value greater than 0 when they need to be drawn. Similarly, items that respond to user events will return a non-zero value when they have been activated or changed.

Now that we've explored the widgets available, let's look at how we can arrange elements in our GUI.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.171.153