Add on_style_change to every component

Empty default style is now valid. Every component have their default style values. Removed style function checks
This commit is contained in:
Insality
2020-05-09 12:45:09 +03:00
parent b1b06f9a17
commit 928a212527
12 changed files with 157 additions and 171 deletions

View File

@@ -302,17 +302,18 @@ local function update_size(self)
-- We add extra size only if scroll is available
-- Even the content zone size less than view zone size
local content_border_extra = helper.get_border(self.content_node)
local stretch_size = self.style.EXTRA_STRECH_SIZE
if self.drag.can_x then
local sign = content_size.x > view_size.x and 1 or -1
content_border_extra.x = content_border_extra.x - self.extra_stretch_size * sign
content_border_extra.z = content_border_extra.z + self.extra_stretch_size * sign
content_border_extra.x = content_border_extra.x - stretch_size * sign
content_border_extra.z = content_border_extra.z + stretch_size * sign
end
if self.drag.can_y then
local sign = content_size.y > view_size.y and 1 or -1
content_border_extra.y = content_border_extra.y + self.extra_stretch_size * sign
content_border_extra.w = content_border_extra.w - self.extra_stretch_size * sign
content_border_extra.y = content_border_extra.y + stretch_size * sign
content_border_extra.w = content_border_extra.w - stretch_size * sign
end
if not self.style.SMALL_CONTENT_SCROLL then
@@ -325,13 +326,37 @@ local function update_size(self)
end
--- Change style of component.
-- This function can be called before component:init. This callback
-- only for store component style params inside self context
-- @function scroll:on_style_change
-- @tparam table style The component style table
function M.on_style_change(self, style)
self.style = {}
self.style.EXTRA_STRECH_SIZE = style.EXTRA_STRECH_SIZE or 0
self.style.ANIM_SPEED = style.ANIM_SPEED or 0.2
self.style.BACK_SPEED = style.BACK_SPEED or 0.35
self.style.FRICT = style.FRICT or 0
self.style.FRICT_HOLD = style.FRICT_HOLD or 0
self.style.INERT_THRESHOLD = style.INERT_THRESHOLD or 3
self.style.INERT_SPEED = style.INERT_SPEED or 30
self.style.POINTS_DEADZONE = style.POINTS_DEADZONE or 20
self.style.SMALL_CONTENT_SCROLL = style.SMALL_CONTENT_SCROLL or false
self._is_inert = not (self.style.FRICT == 0 or
self.style.FRICT_HOLD == 0 or
self.style.INERT_SPEED == 0)
end
--- Scroll constructor.
-- @function scroll:init
-- @tparam node view_node GUI view scroll node
-- @tparam node content_node GUI content scroll node
function M.init(self, view_node, content_node)
self.druid = self:get_druid()
self.style = self:get_style()
self.view_node = self:get_node(view_node)
self.content_node = self:get_node(content_node)
@@ -349,9 +374,7 @@ function M.init(self, view_node, content_node)
self.on_point_scroll = Event()
self.selected = nil
self._is_inert = true
self.is_animate = false
self.extra_stretch_size = self.style.EXTRA_STRECH_SIZE
update_size(self)
end
@@ -486,10 +509,10 @@ end
--- Set extra size for scroll stretching.
-- Set 0 to disable stretching effect
-- @function scroll:set_extra_strech_size
-- @tparam number stretch_size Size in pixels of additional scroll area
-- @tparam[opt=0] number stretch_size Size in pixels of additional scroll area
-- @treturn druid.scroll Self instance
function M.set_extra_strech_size(self, stretch_size)
self.extra_stretch_size = stretch_size or self.style.EXTRA_STRECH_SIZE
self.style.EXTRA_STRECH_SIZE = stretch_size or 0
update_size(self)
return self