RbxGui (Library)

From Legacy Roblox Wiki
Revision as of 04:37, 4 February 2012 by >JulienDethurens (Moved to RbxGui (Library).)
Jump to navigationJump to search

As with many of the current libraries, RbxGui is a Lua Asset designed to assist with the making of GUI widgets. This article will explain to you what RbxGui is, how to use it and how to keep up with its ever-changing API.

What is RbxGui?

RbxGui is (as stated above) an official Roblox-created library specifically for aiding with the creation of GUI programs. Its use is not mandatory, but is recommended for those who would like to make good looking GUI features in lesser amounts of time.

How do I use RbxGui?

RbxGui is used by simply loading the library in your code and storing it in a variable. After that, one can easily use the various API functions and methods that the library has to offer. Below is some sample code that demonstrates the use of this library.

Note: This library uses fields instead of methods, so don't use a colon. Use a period instead. The only exception is the GetApi method.

Example
{{{1}}}


How do you figure out what's in this library?

To find all of the values in a library, you have to use a method found in every library, called GetApi. This method allows you to see what exactly is in the library by returning a table of all of the function names in the library. To figure out all of the values in RbxGui, simply run this code in your command bar in Studio:

for _, funcname in pairs(LoadLibrary('RbxGui'):GetApi()) do print(funcname) end

This piece of code iterates through the table returned by GetApi and prints out the contents of the table.

Also, if it is an official library, there is often a Help function associated with it. To use it, just call the Help function from the library loaded into your code. Help has an argument, which is either the function, or the index of the function, for example, both of these will provide help for CreateDropDownMenu. local RbxGui = assert(LoadLibrary('RbxGui')) print(RbxGui.Help("CreateDropDownMenu")) print(RbxGui.Help(RbxGui.CreateDropDownMenu))

So, is that it?

That is all there is to it. Let's recap upon what we've learned today.

What is RbxGui?

RbxGui is an official Roblox-created library consisting of useful functions that are designed to help you make enticing GUIs.

How do I use it?

To use RbxGui, you must load it into your code and then call its members, which are designed to do things that would normally take more time to do.

How do I know what's in the library?

You can iterate through the table returned by GetApi and print out the values of it. You can also use the Help function in the library with the values of the table.

Concluding mumbo-jumbo

That's all there is to using the RbxGui library created by Roblox. I hope you'll have as much joy using the library as I've had writing this article to teach you to use it.

The API

CreateSlider( number steps, number width, UDim2 position )
Returns Frame sliderGui, IntValue sliderPosition
Description: Returns 2 objects, (sliderGui, sliderPosition). sliderGui is a Frame that contains the entire slider gui. sliderPosition is an IntValue whose current value specifies the specific step the slider is currently on (This value can be modified by a script, and the slider with adjust position). The steps argument specifies how many different positions the slider can hold along the bar. width specifies in pixels how wide the bar should be (modifiable afterwards if desired). position argument should be a UDim2 for slider gui positioning.


CreateScrollingFrame( table orderList, string style )
Returns Frame scrollFrame, ImageButton scrollUpButton, ImageButton scrollDownButton, function recalculateFunction
Description: Returns 4 objects, (scrollFrame, scrollUpButton, scrollDownButton, recalculateFunction). scrollFrame can be filled with GuiObjects. It will lay them out and allow scrollUpButton/scrollDownButton to interact with them. orderList is an optional argument (and specifies the order to layout the children. Without orderlist, it uses the children order) style is also optional, and allows for a 'grid' styling if style is passed 'grid' as a string. recalculateFunction can be called when a relayout is needed (when orderList changes, or when scrollFrame size changes).


AutoTruncateTextObject( TextLabel textLabelToAutoTruncate )
Returns TextLabel autoTruncatingTextLabel, Function changeText
Description: Returns 2 objects, (autoTruncatingTextLabel, changeText). The textLabelToAutoTruncate input is modified to automatically truncate text (with ellipsis), if it gets too small to fit. changeText is a function that can be used to change the text, it takes 1 string as an argument.
CreateScrollingFrame( table orderList, string style )
Returns Frame scrollFrame, ImageButton scrollUpButton, ImageButton scrollDownButton, function recalculateFunction
Description: Returns 4 objects, (scrollFrame, scrollUpButton, scrollDownButton, recalculateFunction). scrollFrame can be filled with GuiObjects. It will lay them out and allow scrollUpButton/scrollDownButton to interact with them. orderList is an optional argument (and specifies the order to layout the children. Without orderlist, it uses the children order) style is also optional, and allows for a 'grid' styling if style is passed 'grid' as a string. recalculateFunction can be called when a relayout is needed (when orderList changes, or when scrollFrame size changes).


GetFontHeight( Font font, FontSize fontSize )
Returns number pixelSize
Description: Returns the vertical size in pixels of the given font + fontSize.


CreateStyledMessageDialog( string title, string message, string style, table buttons )
Returns Instance messageContainer
Description: Returns a gui object of a message box with title and message as passed in. buttons input is an array of Tables contains a 'Text' and 'Function' field for the text/callback of each button, style is a string, either 'Error', 'Notify' or 'Confirm'.


CreateMessageDialog( string title, string message, table buttons )
Returns Instance messageContainer
Description: Returns a gui object of a message box with title and message as passed in. buttons input is an array of tables that contains a 'Text' and 'Function' field for the text/callback of each button.


CreateDropDownMenu( table items, function onItemSelected )
Returns Instance guiContainer, function updateSelection
Description: First argument should be a table full of strings that will populate menu. Second argument should be a function that takes one argument, and is called when a user selects a new object in the drop down menu. Returns 2 results, a gui container to the gui object and a updateSelection function for external updating. The container is a drop-down-box created around a list of items.


CreatePropertyDropDownMenu( Instance descendant, string propertyName, Enum enumType )
Returns Instance guiContainer
Description: returns a container with a drop-down-box that is linked to the propertyName field of instance which is of type enumType.


See Also