summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWuzzy <almikes@aol.com>2016-12-02 18:02:38 +0100
committerWuzzy <almikes@aol.com>2016-12-02 18:02:38 +0100
commit43356a7bae7074f4071ba6df352625c3c6e6cadb (patch)
tree6cfac348eafabffcd09723e1c7cd7453e4867678
parente79efcb3704ca9e9e937731a49d0fcca534efd87 (diff)
Add align_left, align_top params to gallery
-rw-r--r--API.md4
-rw-r--r--init.lua17
2 files changed, 17 insertions, 4 deletions
diff --git a/API.md b/API.md
index 4b91a18..bbe32b8 100644
--- a/API.md
+++ b/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
diff --git a/init.lua b/init.lua
index 2280ada..bda8f9d 100644
--- a/init.lua
+++ b/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)