From 2931a95c208a196cf68acda9a2abb9d8d125a583 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Sat, 6 May 2023 18:32:33 +0200 Subject: [PATCH] - Docs Update - Updated List & ScrollbarFrame Docs - Added setOptions for the List Object --- Basalt/objects/List.lua | 18 ++++++++++ docs/objects/List.md | 3 +- docs/objects/List/getOptions.md | 22 ++++++++++++ docs/objects/List/setOptions.md | 35 +++++++++++++++++++ docs/objects/List/setSelectedItem.md | 28 --------------- docs/objects/List/setSelectionColor.md | 2 +- .../ScrollableFrame/setScrollAmount.md | 26 ++++++++++++++ 7 files changed, 104 insertions(+), 30 deletions(-) create mode 100644 docs/objects/List/getOptions.md create mode 100644 docs/objects/List/setOptions.md delete mode 100644 docs/objects/List/setSelectedItem.md create mode 100644 docs/objects/ScrollableFrame/setScrollAmount.md diff --git a/Basalt/objects/List.lua b/Basalt/objects/List.lua index 1204e70..7e06d9d 100644 --- a/Basalt/objects/List.lua +++ b/Basalt/objects/List.lua @@ -59,6 +59,20 @@ return function(name, basalt) return self end, + setOptions = function(self, ...) + list = {} + for k,v in pairs(...)do + if(type(v)=="string")then + table.insert(list, { text = v, bgCol = self:getBackground(), fgCol = self:getForeground(), args = {} }) + else + table.insert(list, { text = v[1], bgCol = v[2] or self:getBackground(), fgCol = v[3] or self:getForeground(), args = v[4] or {} }) + end + end + self:setValue(list[1], false) + self:updateDraw() + return self + end, + setOffset = function(self, yOff) yOffset = yOff self:updateDraw() @@ -83,6 +97,10 @@ return function(name, basalt) return list end, + getOptions = function(self) + return list + end, + getItemIndex = function(self) local selected = self:getValue() for key, value in pairs(list) do diff --git a/docs/objects/List.md b/docs/objects/List.md index 2333997..27a5188 100644 --- a/docs/objects/List.md +++ b/docs/objects/List.md @@ -9,7 +9,8 @@ In addition to the Object and VisualObject methods, lists also have the followin |[editItem](objects/List/editItem.md)|Changes an already existing item in the list |[getItem](objects/List/getItem.md)|Returns an item by its index |[getItemCount](objects/List/getItemCount.md)|Returns the item count -|[getAll](objects/List/getAll.md)|Returns the entire list as a table +|[setOptions](objects/List/setOptions.md)|Updates the list options +|[getOptions](objects/List/getOptions.md)|Returns the entire list as a table |[selectItem](objects/List/selectItem.md)|Selects an item |[clear](objects/List/clear.md)|Makes the entire list empty |[getItemIndex](objects/List/getItemIndex.md)|Returns the currently active item index diff --git a/docs/objects/List/getOptions.md b/docs/objects/List/getOptions.md new file mode 100644 index 0000000..fece4af --- /dev/null +++ b/docs/objects/List/getOptions.md @@ -0,0 +1,22 @@ +## getOptions + +### Description + +Returns all items as a table. + +#### Returns + +1. `table` All items + +### Usage + +* Creates a default list with 3 entries and prints a table. + +```lua +local mainFrame = basalt.createFrame() +local aList = mainFrame:addList() +aList:addItem("1. Entry") +aList:addItem("2. Entry", colors.yellow) +aList:addItem("3. Entry", colors.yellow, colors.green) +basalt.debug(aList:getOptions()) +``` diff --git a/docs/objects/List/setOptions.md b/docs/objects/List/setOptions.md new file mode 100644 index 0000000..326d339 --- /dev/null +++ b/docs/objects/List/setOptions.md @@ -0,0 +1,35 @@ +## setOptions + +### Description + +The `setOptions` method allows you to change the options of a List object. This method accepts a table containing the new options you want to set for the List object. + +### Parameters + +1. `table` A table containing the new options to set for the List object. + +#### Returns + +1. `object` The object in use + +### Usage + +* Creates a default list with 3 entries, then changes the background color and selection color of the list. + +```lua +local mainFrame = basalt.createFrame() +local aList = mainFrame:addList() +aList:setOptions("Entry 1", "Entry 2", "Entry 3") + +basalt.autoUpdate() +``` + +or + +```lua +local mainFrame = basalt.createFrame() +local aList = mainFrame:addList() +aList:setOptions("Entry 1", {"Entry 2", colors.yellow}, {"Entry 3", colors.yellow, colors.green}) + +basalt.autoUpdate() +``` diff --git a/docs/objects/List/setSelectedItem.md b/docs/objects/List/setSelectedItem.md deleted file mode 100644 index b60a71b..0000000 --- a/docs/objects/List/setSelectedItem.md +++ /dev/null @@ -1,28 +0,0 @@ -## setSelectedItem -Sets the background and the foreground of the item which is currently selected - -#### Parameters: -1. `number|color` The background color which should be used -2. `number|color` The text color which should be used - -#### Returns: -1. `object` The object in use - -#### Usage: -* Creates a default list with 4 entries and sets the selection background color to green. -```lua -local mainFrame = basalt.createFrame() -local aList = mainFrame:addList() -aList:addItem("1. Entry") -aList:addItem("2. Entry",colors.yellow) -aList:addItem("3. Entry",colors.yellow,colors.green) -aList:addItem("4. Entry") -aList:setSelectedItem(colors.green, colors.red) -``` -```xml - - 1. Entry - 2. Entryyellow - 2. Entryyellowgreen - -``` \ No newline at end of file diff --git a/docs/objects/List/setSelectionColor.md b/docs/objects/List/setSelectionColor.md index 6b6f096..7e25cd9 100644 --- a/docs/objects/List/setSelectionColor.md +++ b/docs/objects/List/setSelectionColor.md @@ -24,7 +24,7 @@ aList:addItem("1. Entry") aList:addItem("2. Entry",colors.yellow) aList:addItem("3. Entry",colors.yellow,colors.green) aList:addItem("4. Entry") -aList:setSelectedItem(colors.green, colors.red) +aList:setSelectionColor(colors.green, colors.red) ``` ```xml diff --git a/docs/objects/ScrollableFrame/setScrollAmount.md b/docs/objects/ScrollableFrame/setScrollAmount.md new file mode 100644 index 0000000..1f693b2 --- /dev/null +++ b/docs/objects/ScrollableFrame/setScrollAmount.md @@ -0,0 +1,26 @@ +## setScrollAmount + +### Description + +The setScrollAmount method allows you to set the maximum allowed scroll value. This value determines how far the content of the ScrollableFrame can be scrolled. + +### Parameters + +1. `number` The maximum scroll value + +### Returns + +1. `object` The object in use + +### Usage + +* Set the scrolling direction for a ScrollableFrame + +```lua +local mainFrame = basalt.createFrame() +local scrollableFrame = mainFrame:addScrollableFrame() + +scrollableFrame:setScrollAmount(10) +``` + +By setting the scroll amount, you can control how much the content of the ScrollableFrame can be scrolled, ensuring that the user can only view a specific range of content at a time.