From b0bec3da6a03d65e34635795c314830c3c6b10a2 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 7 Nov 2016 21:30:03 +0100 Subject: Add optional text widget boundaries --- API.md | 11 +++++++---- init.lua | 12 ++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/API.md b/API.md index cb92f65..f275f78 100644 --- a/API.md +++ b/API.md @@ -404,10 +404,13 @@ this function may be deprecated if it isn't needed anymore. #### Parameters * `data`: Text to be written inside the widget -* `x`: Formspec X coordinate -* `y`: Formspec Y coordinate -* `width`: Width of the widget in formspec units -* `height`: Height of the widget in formspec units +* `x`: Formspec X coordinate (optional) +* `y`: Formspec Y coordinate (optional) +* `width`: Width of the widget in formspec units (optional) +* `height`: Height of the widget in formspec units (optional) + +The default values for the optional parameters result in a widget which fills +nearly the entire entry page. #### Return value A string which contains a complete formspec definition building the widget. diff --git a/init.lua b/init.lua index df9641f..b1b6a03 100644 --- a/init.lua +++ b/init.lua @@ -424,6 +424,18 @@ doc.widgets = {} local text_id = 1 -- Scrollable freeform text doc.widgets.text = function(data, x, y, width, height) + if x == nil then + x = doc.FORMSPEC.ENTRY_START_X + end + if y == nil then + y = doc.FORMSPEC.ENTRY_START_Y + end + if width == nil then + width = doc.FORMSPEC.ENTRY_WIDTH + end + if height == nil then + height = doc.FORMSPEC.ENTRY_HEIGHT + end local baselength = 80 local widget_basewidth = doc.FORMSPEC.WIDTH local linelength = math.max(20, math.floor(baselength * (width / widget_basewidth))) -- cgit v1.2.3