From cfd654c1b24f1e7fdede6cbb42a85e7c12b52ef9 Mon Sep 17 00:00:00 2001 From: Artsiom Trubchyk Date: Fri, 5 Feb 2021 21:07:40 +0300 Subject: [PATCH 1/4] Optimize helper.lua --- druid/helper.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/druid/helper.lua b/druid/helper.lua index 590f5ae..71233ef 100644 --- a/druid/helper.lua +++ b/druid/helper.lua @@ -5,6 +5,7 @@ local const = require("druid.const") local M = {} +local system_name = sys.get_sys_info().system_name --- Text node or icon node can be nil local function get_text_width(text_node) @@ -182,15 +183,13 @@ end --- Check if device is mobile (Android or iOS) -- @function helper..is_mobile function M.is_mobile() - local system_name = sys.get_sys_info().system_name - return system_name == const.OS.IOS or system_name == const.OS.ANDROID + return system_name == const.OS.IOS or SYSTEM_NAME == const.OS.ANDROID end --- Check if device is HTML5 -- @function helper.is_web function M.is_web() - local system_name = sys.get_sys_info().system_name return system_name == const.OS.BROWSER end From fa559a2a28b24666ec0dd10f18356f4401dfac5c Mon Sep 17 00:00:00 2001 From: Artsiom Trubchyk Date: Thu, 11 Feb 2021 12:33:32 +0300 Subject: [PATCH 2/4] Add sys info consts --- druid/const.lua | 4 ++++ druid/helper.lua | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/druid/const.lua b/druid/const.lua index c50cf8e..9f1fc0d 100644 --- a/druid/const.lua +++ b/druid/const.lua @@ -51,6 +51,10 @@ M.PIVOTS = { } +M.SYS_INFO = sys.get_sys_info() +M.CURRENT_SYSTEM_NAME = M.SYS_INFO.system_name + + M.OS = { ANDROID = "Android", IOS = "iPhone OS", diff --git a/druid/helper.lua b/druid/helper.lua index 71233ef..cc83abc 100644 --- a/druid/helper.lua +++ b/druid/helper.lua @@ -183,14 +183,14 @@ end --- Check if device is mobile (Android or iOS) -- @function helper..is_mobile function M.is_mobile() - return system_name == const.OS.IOS or SYSTEM_NAME == const.OS.ANDROID + return const.CURRENT_SYSTEM_NAME == const.OS.IOS or const.CURRENT_SYSTEM_NAME == const.OS.ANDROID end --- Check if device is HTML5 -- @function helper.is_web function M.is_web() - return system_name == const.OS.BROWSER + return const.CURRENT_SYSTEM_NAME == const.OS.BROWSER end From fe3ac2e9850224c1110f756c0aafad1d124902aa Mon Sep 17 00:00:00 2001 From: Insality Date: Thu, 1 Apr 2021 20:28:09 +0300 Subject: [PATCH 3/4] Add locale_id in Lang Text component optional --- docs_md/changelog.md | 1 + druid/extended/lang_text.lua | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs_md/changelog.md b/docs_md/changelog.md index d26860a..832edd1 100644 --- a/docs_md/changelog.md +++ b/docs_md/changelog.md @@ -138,3 +138,4 @@ Desc - Input component: rename field _selected_ to _is_selected_ (according to the docs) - Add EmmyLua annotations. See how to use it FAQ +- Lang text now can be initialized without default locale id diff --git a/druid/extended/lang_text.lua b/druid/extended/lang_text.lua index b62aa6e..64479d1 100644 --- a/druid/extended/lang_text.lua +++ b/druid/extended/lang_text.lua @@ -21,7 +21,7 @@ local LangText = component.create("lang_text", { component.ON_LANGUAGE_CHANGE }) --- Component init function -- @tparam LangText self -- @tparam node node The text node --- @tparam string locale_id Default locale id +-- @tparam string locale_id Default locale id, optional -- @tparam bool no_adjust If true, will not correct text size function LangText.init(self, node, locale_id, no_adjust) self.druid = self:get_druid() @@ -30,7 +30,9 @@ function LangText.init(self, node, locale_id, no_adjust) self.on_change = Event() - self:translate(locale_id) + if locale_id then + self:translate(locale_id) + end return self end @@ -59,7 +61,7 @@ end function LangText.translate(self, locale_id, ...) self.last_locale_args = {...} self.last_locale = locale_id or self.last_locale - self.text:set_to(settings.get_text(self.last_locale, ...)) + self.text:set_to(settings.get_text(self.last_locale, ...) or "") end From 7c79985be663f5443af004a4ad676c85672b366b Mon Sep 17 00:00:00 2001 From: Insality Date: Thu, 1 Apr 2021 20:32:29 +0300 Subject: [PATCH 4/4] #124 Add set_click_zone to scroll component --- docs_md/changelog.md | 1 + druid/base/drag.lua | 6 +++--- druid/base/scroll.lua | 9 +++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs_md/changelog.md b/docs_md/changelog.md index 832edd1..e2fc054 100644 --- a/docs_md/changelog.md +++ b/docs_md/changelog.md @@ -139,3 +139,4 @@ Desc - Input component: rename field _selected_ to _is_selected_ (according to the docs) - Add EmmyLua annotations. See how to use it FAQ - Lang text now can be initialized without default locale id +- **#124** Add _set_click_zone_ functon to Scroll component (just link to Drag:set_click_zone inside scroll component) diff --git a/druid/base/drag.lua b/druid/base/drag.lua index 8632929..9263e29 100644 --- a/druid/base/drag.lua +++ b/druid/base/drag.lua @@ -263,9 +263,9 @@ end --- Strict drag click area. Useful for -- restrict events outside stencil node -- @tparam Drag self --- @tparam node zone Gui node -function Drag.set_click_zone(self, zone) - self.click_zone = self:get_node(zone) +-- @tparam node node Gui node +function Drag.set_click_zone(self, node) + self.click_zone = self:get_node(node) end diff --git a/druid/base/scroll.lua b/druid/base/scroll.lua index 4c532ca..c7681ae 100644 --- a/druid/base/scroll.lua +++ b/druid/base/scroll.lua @@ -379,6 +379,15 @@ function Scroll.bind_grid(self, grid) end +--- Strict drag scroll area. Useful for +-- restrict events outside stencil node +-- @tparam Drag self +-- @tparam node node Gui node +function Scroll.set_click_zone(self, node) + self.drag:set_click_zone(node) +end + + function Scroll._on_scroll_drag(self, dx, dy) local t = self.target_position local b = self.available_pos