Add align_left, align_top params to gallery
This commit is contained in:
parent
e79efcb370
commit
43356a7bae
4
API.md
4
API.md
@ -468,7 +468,7 @@ beginning with `doc_widget_text` to avoid naming collisions, as this function
|
||||
makes use of such identifiers internally.
|
||||
|
||||
|
||||
### `doc.widgets.gallery(imagedata, playername, x, y, aspect_ratio, width, rows)`
|
||||
### `doc.widgets.gallery(imagedata, playername, x, y, aspect_ratio, width, rows, align_left, align_top)`
|
||||
This function creates an image gallery which allows you to display an
|
||||
arbitrary amount of images aligned horizontally. It is possible to add more
|
||||
images than the space of an entry would normally held, this is done by adding
|
||||
@ -499,6 +499,8 @@ adding more galleries is not supported and will lead to bugs.
|
||||
* `aspect_ratio`: Aspect ratio of all the images (width/height)
|
||||
* `width`: Total gallery width in formspec units (optional)
|
||||
* `rows`: Number of images which can be seen at once (optional)
|
||||
* `align_left`: If `false`, gallery is aligned to the left instead of the right (optional)
|
||||
* `align_right`: If `false`, gallery is aligned to the bottom instead of the top (optional)
|
||||
|
||||
The default values for the optional parameters result in a gallery with
|
||||
3 rows which is placed at the top left corner and spans the width of the
|
||||
|
17
init.lua
17
init.lua
@ -487,7 +487,7 @@ doc.entry_builders.text_and_gallery = function(data, playername)
|
||||
-- Only add the gallery if images are in the data, otherwise, the text widget gets all of the space
|
||||
if data.images ~= nil then
|
||||
local gallery
|
||||
gallery, stolen_height = doc.widgets.gallery(data.images, playername)
|
||||
gallery, stolen_height = doc.widgets.gallery(data.images, playername, nil, nil, nil, nil, nil, nil, false)
|
||||
formstring = formstring .. gallery
|
||||
end
|
||||
formstring = formstring .. doc.widgets.text(data.text,
|
||||
@ -532,7 +532,7 @@ end
|
||||
|
||||
-- Image gallery
|
||||
-- Currently, only one gallery per entry is supported. TODO: Add support for multiple galleries in an entry (low priority)
|
||||
doc.widgets.gallery = function(imagedata, playername, x, y, aspect_ratio, width, rows)
|
||||
doc.widgets.gallery = function(imagedata, playername, x, y, aspect_ratio, width, rows, align_left, align_top)
|
||||
if playername == nil then return nil end -- emergency exit
|
||||
|
||||
local formstring = ""
|
||||
@ -543,6 +543,10 @@ doc.widgets.gallery = function(imagedata, playername, x, y, aspect_ratio, width,
|
||||
if width == nil then width = doc.FORMSPEC.ENTRY_WIDTH end
|
||||
if rows == nil then rows = 3 end
|
||||
|
||||
if align_left == false then
|
||||
x = x - width
|
||||
end
|
||||
|
||||
local imageindex = doc.data.players[playername].galidx
|
||||
doc.data.players[playername].maxgalidx = #imagedata
|
||||
doc.data.players[playername].galrows = rows
|
||||
@ -556,9 +560,13 @@ doc.widgets.gallery = function(imagedata, playername, x, y, aspect_ratio, width,
|
||||
totalimagewidth = width - bw*2
|
||||
iw = totalimagewidth / rows
|
||||
ih = iw * aspect_ratio
|
||||
if align_top == false then
|
||||
y = y - ih
|
||||
end
|
||||
|
||||
local tt
|
||||
if imageindex > 1 then
|
||||
formstring = formstring .. "button["..x..","..y..";"..bw..","..ih..";doc_button_gallery_prev;"..F("<").."]"
|
||||
local tt
|
||||
if rows == 1 then
|
||||
tt = F("Show previous image")
|
||||
else
|
||||
@ -581,6 +589,9 @@ doc.widgets.gallery = function(imagedata, playername, x, y, aspect_ratio, width,
|
||||
totalimagewidth = width
|
||||
iw = totalimagewidth / rows
|
||||
ih = iw * aspect_ratio
|
||||
if align_top == false then
|
||||
y = y - ih
|
||||
end
|
||||
end
|
||||
for i=imageindex, math.min(#imagedata, (imageindex-1)+rows) do
|
||||
xoffset = buttonoffset + (x + pos * iw)
|
||||
|
Loading…
x
Reference in New Issue
Block a user