diff --git a/GUI-API.md b/GUI-API.md index f5298c8..14dbe13 100644 --- a/GUI-API.md +++ b/GUI-API.md @@ -39,6 +39,7 @@ Let the abundance of text below not frighten you: this documentation has many il | [  GUI.brailleCanvas](#guibraillecanvasx-y-width-height-extends-guiobject) | | [  GUI.scrollBar](#guiscrollbarx-y-width-height-backgroundcolor-foregroundcolor-minimumvalue-maximumvalue-value-shownvaluecount-onscrollvalueincrement-thinmode-extends-guiobject) | | [  GUI.textBox](#guitextboxx-y-width-height-backgroundcolor-textcolor-lines-currentline-horizontaloffset-verticaloffset-autowrap-autoheight-extends-guiobject) | +| [  GUI.progressIndicator](#guiprogressindicatorx-y-passivecolor-primarycolor-secondarycolor-extends-guiobject) | | [Ready-to-use containers](#ready-to-use-containers) | | [  GUI.layout](#guilayoutx-y-width-height-columncount-rowcount-extends-guicontainer) | | [  GUI.window](#guiwindowx-y-width-height-extends-guicontainer) | @@ -1576,6 +1577,87 @@ Result: ![](http://i89.fastpic.ru/big/2017/0402/ad/01cdcf7aec919051f64ac2b7d9daf0ad.png) +### GUI.**progressIndicator**(x, y, passiveColor, primaryColor, secondaryColor) extends GUI.**object** +| Type | Parameter | Description | +| ------ | ------ | ------ | +| *int* | x | Indicator coordinate by x-axis | +| *int* | y | Indicator coordinate by y-axis | +| *int* | passiveColor | Initial indicator color in passive state | +| *int* | primaryColor | Primary indicator color in active state | +| *int* | secondaryColor | Secondary indicator color in active state| + +Progress indicator is a simple widget for giving users information when **something is happening**. It just nicely rolls around it's circle shape. + +This object has following properties: + +| Type | Property | Description | +| ------ | ------ | ------ | +| *boolean* | .**active** | Enables or disables progress indicator **active** state | +| *function* | :**roll**() | Performs a roll operation when indicator circle will be turned to a next iteration. It's visible only in **active** state | + +Example of implementation: +```lua + +local GUI = require("GUI") +local internet = require("Internet") + +------------------------------------------------------------------------------------------ + +local workspace = GUI.workspace() +workspace:addChild(GUI.panel(1, 1, workspace.width, workspace.height, 0x1E1E1E)) + +-- Adding progress indicator to display data downloading +local progressIndicator = workspace:addChild(GUI.progressIndicator(3, 2, 0x3C3C3C, 0x00B640, 0x99FF80)) + +-- Adding button that performs internet-request to download *something* +workspace:addChild(GUI.adaptiveButton(3, 6, 2, 1, 0x2D2D2D, 0xD2D2D2, 0x5A5A5A, 0xE1E1E1, "Download")).onTouch = function() + -- Switching indicator to active state + progressIndicator.active = true + workspace:draw() + + -- Sending a GET-request to download data as string + local downloadedData = "" + local result, reason = internet.rawRequest( + -- Url (will return server IP-address) + "http://httpbin.org/ip", + -- POST data + nil, + -- Headers + nil, + -- Downloaded chunk hanlder + function(chunk) + downloadedData = downloadedData .. chunk + + -- Rolling indicator to a next state + progressIndicator:roll() + workspace:draw() + end, + -- Count of bytes to download per chunk (2 will simulate slow download) + 2 + ) + + -- Switching indicator to passive state when download is finished + progressIndicator.active = false + workspace:draw() + + -- Displaying result on screen if request was successfull + if result then + GUI.alert("Download complete: " .. downloadedData) + end +end + + +------------------------------------------------------------------------------------------ + +workspace:draw() +workspace:start() + +``` + +Result: + +![](https://i.imgur.com/JNqzBza.gif) + # Ready-to-use containers There are various containers listed below that support all features of GUI.**container**, however they have a special functional and methods