From be18f4e90054de42bf93e9665971e457d5b8f321 Mon Sep 17 00:00:00 2001 From: myk002 Date: Fri, 4 Nov 2022 17:41:15 -0700 Subject: [PATCH 1/4] return self from Screen:show() as a convenience --- library/lua/gui.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/library/lua/gui.lua b/library/lua/gui.lua index 8d546b21a..070fceaf9 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -641,6 +641,7 @@ function Screen:show(parent) if not dscreen.show(self, parent.child) then error('Could not show screen') end + return self end function Screen:onAboutToShow(parent) From 28aadea6afce4442b48f8c439c271bd94c9a6aaa Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 7 Nov 2022 13:58:12 -0800 Subject: [PATCH 2/4] allow an alternate ViewRect for getMousePos --- library/lua/gui.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/lua/gui.lua b/library/lua/gui.lua index 070fceaf9..e69237003 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -473,8 +473,8 @@ function View:getWindowSize() return rect.width, rect.height end -function View:getMousePos() - local rect = self.frame_body +function View:getMousePos(view_rect) + local rect = view_rect or self.frame_body local x,y = dscreen.getMousePos() if rect and rect:inClipGlobalXY(x,y) then return rect:localXY(x,y) From a0ff7e4d3f571dc57fc3264ab950dd13753b6ab7 Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 7 Nov 2022 15:58:29 -0800 Subject: [PATCH 3/4] update Lua docs --- docs/Lua API.rst | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/Lua API.rst b/docs/Lua API.rst index 8e6ea1d9f..2b9f8cb52 100644 --- a/docs/Lua API.rst +++ b/docs/Lua API.rst @@ -3707,10 +3707,11 @@ The class has the following methods: Returns the dimensions of the ``frame_body`` rectangle. -* ``view:getMousePos()`` +* ``view:getMousePos([view_rect])`` - Returns the mouse *x,y* in coordinates local to the ``frame_body`` - rectangle if it is within its clip area, or nothing otherwise. + Returns the mouse *x,y* in coordinates local to the given ViewRect (or + ``frame_body`` if no ViewRect is passed) if it is within its clip area, + or nothing otherwise. * ``view:updateLayout([parent_rect])`` @@ -3829,7 +3830,9 @@ It adds the following methods: ``dfhack.screen.show``, calls ``self:onAboutToShow(parent)``. Note that ``onAboutToShow()`` can dismiss active screens, and therefore change the potential parent. If parent is not specified, this function will re-detect the - current topmost window after ``self:onAboutToShow(parent)`` returns. + current topmost window after ``self:onAboutToShow(parent)`` returns. This + function returns ``self`` as a convenience so you can write such code as + ``local view = MyScreen{params=val}:show()``. * ``screen:onAboutToShow(parent)`` *(for overriding)* From b2b2a52b55d23c2fb2a4218443ed7d500b6ad2d7 Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 7 Nov 2022 16:00:43 -0800 Subject: [PATCH 4/4] update changelog --- docs/changelog.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index 3ede58a70..c1f71209a 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -76,6 +76,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - ``dfhack.constructions.findAtTile()``: exposed preexisting function to Lua. - ``dfhack.constructions.insert()``: exposed new function to Lua. - ``widgets.EditField`` now allows other widgets to process characters that the ``on_char`` callback rejects. +- ``gui.Screen.show()`` now returns ``self`` as a convenience +- ``gui.View.getMousePos()`` now takes an optional ``ViewRect`` parameter in case the caller wants to get the mouse pos relative to a rect that is not the frame_body (such as the frame_rect) # 0.47.05-r7