Formspec: add scrollbar and minor fixes
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
---@class Formspec
|
---@class Formspec
|
||||||
---@field params string
|
---@field params string
|
||||||
---@field elements string
|
---@field elements string
|
||||||
local Formspec = {}
|
local Formspec = {
|
||||||
|
elements = ''
|
||||||
|
}
|
||||||
|
|
||||||
---@class FormspecDef
|
---@class FormspecDef
|
||||||
---Set the formspec version to a certain number. If not specified, version `10` is assumed.
|
---Set the formspec version to a certain number. If not specified, version `10` is assumed.
|
||||||
@@ -76,7 +78,7 @@ function Formspec:new(def)
|
|||||||
|
|
||||||
---@type Formspec
|
---@type Formspec
|
||||||
local instance = setmetatable({
|
local instance = setmetatable({
|
||||||
formspecParams = version..size..position..anchor..padding..noPrepend..realCoordinates..allowClose,
|
params = version..size..position..anchor..padding..noPrepend..realCoordinates..allowClose,
|
||||||
}, {__index = self})
|
}, {__index = self})
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
@@ -91,7 +93,7 @@ end
|
|||||||
---TODO: описание
|
---TODO: описание
|
||||||
---@return string
|
---@return string
|
||||||
function Formspec:getElements()
|
function Formspec:getElements()
|
||||||
return self.params
|
return self.elements
|
||||||
end
|
end
|
||||||
|
|
||||||
---TODO: описание
|
---TODO: описание
|
||||||
@@ -108,10 +110,10 @@ end
|
|||||||
|
|
||||||
---Start of a container block, moves all physical elements in the container by (X, Y).
|
---Start of a container block, moves all physical elements in the container by (X, Y).
|
||||||
---Containers can be nested, in which case the offsets are added (child containers are relative to parent containers).
|
---Containers can be nested, in which case the offsets are added (child containers are relative to parent containers).
|
||||||
|
---@param container Formspec
|
||||||
---@param x number
|
---@param x number
|
||||||
---@param y number
|
---@param y number
|
||||||
---@param container Formspec
|
function Formspec:container(container, x, y)
|
||||||
function Formspec:container(x, y, container)
|
|
||||||
local element = ('container[%s,%s]'):format(x, y)..container:getElements()..'container_end[]'
|
local element = ('container[%s,%s]'):format(x, y)..container:getElements()..'container_end[]'
|
||||||
|
|
||||||
self:addElement(element)
|
self:addElement(element)
|
||||||
@@ -122,6 +124,7 @@ end
|
|||||||
---be additionally moved by the current value of the scrollbar with
|
---be additionally moved by the current value of the scrollbar with
|
||||||
---the name `scrollbar name` times `scroll factor` along the orientation `orientation` and
|
---the name `scrollbar name` times `scroll factor` along the orientation `orientation` and
|
||||||
---be clipped to the rectangle defined by `X`, `Y`, `W` and `H`.
|
---be clipped to the rectangle defined by `X`, `Y`, `W` and `H`.
|
||||||
|
---@param container Formspec
|
||||||
---@param x number
|
---@param x number
|
||||||
---@param y number
|
---@param y number
|
||||||
---@param w number
|
---@param w number
|
||||||
@@ -130,8 +133,7 @@ end
|
|||||||
---@param orientation 'vertical'|'horizontal'
|
---@param orientation 'vertical'|'horizontal'
|
||||||
---@param scrollFactor number? Defaults to 0.1.
|
---@param scrollFactor number? Defaults to 0.1.
|
||||||
---@param contentPadding string? TODO: разобраться, что тут
|
---@param contentPadding string? TODO: разобраться, что тут
|
||||||
---@param container Formspec
|
function Formspec:scrollContainer(container, x, y, w, h, scrollbarName, orientation, scrollFactor, contentPadding)
|
||||||
function Formspec:scrollContainer(x, y, w, h, scrollbarName, orientation, scrollFactor, contentPadding, container)
|
|
||||||
local element = ('scroll_container[%s,%s;%s,%s;%s;%s;%s;%s]'):format(
|
local element = ('scroll_container[%s,%s;%s,%s;%s;%s;%s;%s]'):format(
|
||||||
x, y, w, h, scrollbarName, orientation, scrollFactor or '', contentPadding or '')..
|
x, y, w, h, scrollbarName, orientation, scrollFactor or '', contentPadding or '')..
|
||||||
container:getElements()..'scroll_container_end[]'
|
container:getElements()..'scroll_container_end[]'
|
||||||
@@ -436,9 +438,19 @@ function Formspec:checkbox()
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---TODO
|
---Show a scrollbar using options defined by the previous `scrollbaroptions[]`
|
||||||
function Formspec:scrollbar()
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param w number
|
||||||
|
---@param h number
|
||||||
|
---@param orientation 'vertical'|'horizontal'
|
||||||
|
---@param name string
|
||||||
|
---@param value number?
|
||||||
|
function Formspec:scrollbar(x, y, w, h, orientation, name, value)
|
||||||
|
local element = ('scrollbar[%s,%s;%s,%s;%s;%s;%s]'):format(
|
||||||
|
x, y, w, h, orientation, name, value or '')
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
end
|
end
|
||||||
|
|
||||||
---TODO
|
---TODO
|
||||||
|
|||||||
Reference in New Issue
Block a user