From 94197391a531cfb1aea83cf425138114900f2db8 Mon Sep 17 00:00:00 2001 From: Insality Date: Wed, 20 Oct 2021 20:52:14 +0300 Subject: [PATCH] Update docs for #78 text update --- docs_md/01-components.md | 12 +++++++++--- docs_md/changelog.md | 10 +++++++++- druid/base/text.lua | 4 +++- druid/styles/default/style.lua | 4 +++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/docs_md/01-components.md b/docs_md/01-components.md index f0a833c..5b9eb98 100644 --- a/docs_md/01-components.md +++ b/docs_md/01-components.md @@ -1,5 +1,3 @@ - - # Druid components @@ -42,7 +40,7 @@ _fill example usecases_ Basic Druid text component. Text components by default have the text size adjusting. ### Setup -Create text node with druid: `text = druid:new_text(node_name, [initial_value], [is_disable_size_adjust])` +Create text node with druid: `text = druid:new_text(node_name, [initial_value], [text_adjust_type])` ### Notes - Text component by default have auto adjust text sizing. Text never will be bigger, than text node size, which you can setup in GUI scene. It can be disabled on component creating by settings argument `is_no_adjust` to _true_ @@ -53,6 +51,14 @@ Create text node with druid: `text = druid:new_text(node_name, [initial_value], ![](../media/text_anchor.gif) +- There is several text adjust types. Default Downscale. You can change the default adjust type in the text style table. + - **const.TEXT_ADJUST.DOWNSCALE** - Change text's scale to fit in the text node size + - **const.TEXT_ADJUST.TRIM** - Trim the text with postfix (default - "...", override in styles) to fit in the text node size + - **const.TEXT_ADJUST.NO_ADJUST** - No any adjust, like default Defold text node + - **const.TEXT_ADJUST.DOWNSCALE_LIMITED** - Change text's scale list downscale, but there is limit for text's scale + - **const.TEXT_ADJUST.SCROLL** - Change text's pivot to imitate scrolling in the text box. Use with stencil node for better effect. + - **const.TEXT_ADJUST.SCALE_THEN_SCROLL** - Combine two modes: first limited downscale, then scroll + ## Blocker [Blocker API here](https://insality.github.io/druid/modules/Blocker.html) diff --git a/docs_md/changelog.md b/docs_md/changelog.md index 34fad8b..7a21b80 100644 --- a/docs_md/changelog.md +++ b/docs_md/changelog.md @@ -214,4 +214,12 @@ Have a good day. - **#132** Add example with grid add/remove with animations - **#112** Allow remap default Druid input bindings. - **#66** Add `druid:set_whitelist()` and `druid.set_blacklist()` functions. It's affects only on input process step, you can allow/forbid interact with list of specific components -- **#125** Now `component:set_input_priority()` affects on all component's children too \ No newline at end of file +- **#125** Now `component:set_input_priority()` affects on all component's children too +- **#78** Update Text component: + - Add text adjust type instead of _no_adjust_ param. + - const.TEXT_ADJUST.DOWNSCALE - Change text's scale to fit in the text node size + - const.TEXT_ADJUST.TRIM - Trim the text with postfix (default - "...", override in styles) to fit in the text node size + - const.TEXT_ADJUST.NO_ADJUST - No any adjust, like default Defold text node + - const.TEXT_ADJUST.DOWNSCALE_LIMITED - Change text's scale list downscale, but there is limit for text's scale + - const.TEXT_ADJUST.SCROLL - Change text's pivot to imitate scrolling in the text box. Use with stencil node for better effect. + - const.TEXT_ADJUST.SCALE_THEN_SCROLL - Combine two modes: first limited downscale, then scroll \ No newline at end of file diff --git a/druid/base/text.lua b/druid/base/text.lua index 4f477d5..ceeeedf 100644 --- a/druid/base/text.lua +++ b/druid/base/text.lua @@ -168,9 +168,11 @@ end -- or create your own style -- @table style -- @tfield[opt=...] string TRIM_POSTFIX The postfix for TRIM adjust type +-- @tfield[opt=DOWNSCALE] string DEFAULT_ADJUST The default adjust type for any text component function Text.on_style_change(self, style) self.style = {} self.style.TRIM_POSTFIX = style.TRIM_POSTFIX or "..." + self.style.DEFAULT_ADJUST = style.DEFAULT_ADJUST or const.TEXT_ADJUST.DOWNSCALE end @@ -192,7 +194,7 @@ function Text.init(self, node, value, adjust_type) self.text_area.x = self.text_area.x * self.start_scale.x self.text_area.y = self.text_area.y * self.start_scale.y - self.adjust_type = adjust_type or const.TEXT_ADJUST.DOWNSCALE + self.adjust_type = adjust_type or self.style.DEFAULT_ADJUST self.color = gui.get_color(self.node) self.on_set_text = Event() diff --git a/druid/styles/default/style.lua b/druid/styles/default/style.lua index cf1135a..0bd125d 100644 --- a/druid/styles/default/style.lua +++ b/druid/styles/default/style.lua @@ -1,3 +1,4 @@ +local const = require("druid.const") local settings = require("druid.system.settings") local anims = require("druid.styles.default.anims") @@ -131,7 +132,8 @@ M["input"] = { M["text"] = { - TRIM_POSTFIX = "..." + TRIM_POSTFIX = "...", + DEFAULT_ADJUST = const.TEXT_ADJUST.DOWNSCALE }