NkGenie

From Riftui Wiki

Jump to: navigation, search

nkGenie is a library providing support for user interface widgets. Also it aims at allowing for easier building of UI elements with less lines of code. Some of the included widgets are rather simple others offer a complete new user interface widget with a lot of functionality. See each individually widget on what it advantages you get by using the nkGenie widget.

The nkGenie library is used in all nkAddons and has been created in September 2011. Since then it has evolved and included more and more functionality. It's very stable and easy to use.

The overall concept of nkGenie is that it offers an object oriented approach at creating and using ui widgets. On top of this it needs very few lines of codes to create an UI object using nkGenie. Through the use of templates the number of parameters can be reduced to an absolute minimum.

Contents

Creating a new widget

A widget is created using the standard Rift Lua command UI.CreateFrame(). The first three parameters are the same as for the standard Lua command:

Parameter Description
widget type The type of widget. See below for a list of supported nkGenie widgets
name The name of the new widget
parent The parent element of the new widget. Any previously created UI frame, context or UIParent.

The library adds a fourth parameter to the list: Settings. While the standard Lua command only let's you create the widget, nkGenie allows you to set up the widget at creation time. This saves a lot of lines of code vs. the standard Rift API approach. The setting parameter has to be supplied as a Lua table in the format: { parameter = value, parameter = value, ... }

Let's take a look at an example on how the widget creation process looks like. First a piece of example code using the standard Rift API commands:

local frame = UI.CreateFrame('frame', 'testFrame', UIParent)
frame:SetWidth(200)
frame:SetHeight(200)
frame:SetPoint('CENTER', UIParent, 'CENTER')

Now with nkGenie you'd do the same like this:

local frame = UI.CreateFrame('nkExtFrame', 'testFrame', UIParent, { width = 200, height = 200, anchors = {{ from = "CENTER", object = UIParent, to = "CENTER" }} })

As you can see the same is achieved using a lot less code. The only difference is that you create a nkGenie Widget so some (and for some widget most) standard Lua commands will not work. So for example frame:SetPoint() will not work on the frame created using nkGenie. However that's not a problem as nkGenie provides all necessary tools for manipulating the widgets it created.

Updating a widget

Creating a widget is one thing, updating it is another. But not with nkGenie! Each widget you create with nkGenie supports a method 'update' using this method you can change widget as easy as you created it. The method has one parameter using the same format as the fourth parameter at creationg time.

frame:update ({ width = 200, height = 200, anchors = {{ from = "CENTER", object = UIParent, to = "CENTER" }} })

All updating is normally done through the update method. It handles all necessary steps to update the widget according to it's structure. Some updates are simpler, others leads to a lot of internal updates. The goal for the developer is that he does not need to care what happens internally.

There are some exceptions where additional methods are available for specific tasks. See the document for the specific widgets as to what they support individually.

Accessing widget parameters

All the parameters you supply while creating or updating an nkGenie widget can be accessed directly afterwards. Some examples:

Parameter Example
widget name frame.name
widget parent frame.parent
fontsize of a text widget frame.fontsize
color of a frame body frame.color.body

Widget list

Further concepts

Personal tools
Namespaces
Variants
Actions
Menu
Wiki
Toolbox