mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 18:37:44 +02:00
#142 Add WHEEL_SCROLL_BY_INERTION Scroll style param
This commit is contained in:
parent
d24301cd13
commit
009c3999c4
@ -249,3 +249,5 @@ Have a good day.
|
|||||||
- Example with `set_check_function` exists in general:buttons example collection
|
- Example with `set_check_function` exists in general:buttons example collection
|
||||||
- **#107** Better scale text adjust by height for multiline text nodes (but still not perfect)
|
- **#107** Better scale text adjust by height for multiline text nodes (but still not perfect)
|
||||||
- **#144** Fix some glitches with scroll Points of Interest. Remove false detection of scroll stopped.
|
- **#144** Fix some glitches with scroll Points of Interest. Remove false detection of scroll stopped.
|
||||||
|
- **#142** Add Scroll style param `WHEEL_SCROLL_BY_INERTION` (default - false). If true - mouse wheel will add inertion to scroll, if false - set position directly per mouse wheel event.
|
||||||
|
- This fix caused, what Mac trackpad seems have additional mouse wheel events for simulate inertion. If you uncomfortable with this, you can disable `WHEEL_SCROLL_BY_INERTION` for more controllable scroll by mouse wheel.
|
@ -113,6 +113,7 @@ end
|
|||||||
-- @tfield[opt=false] bool SMALL_CONTENT_SCROLL If true, content node with size less than view node size can be scrolled
|
-- @tfield[opt=false] bool SMALL_CONTENT_SCROLL If true, content node with size less than view node size can be scrolled
|
||||||
-- @tfield[opt=0] bool WHEEL_SCROLL_SPEED The scroll speed via mouse wheel scroll or touchpad. Set to 0 to disable wheel scrolling
|
-- @tfield[opt=0] bool WHEEL_SCROLL_SPEED The scroll speed via mouse wheel scroll or touchpad. Set to 0 to disable wheel scrolling
|
||||||
-- @tfield[opt=false] bool WHEEL_SCROLL_INVERTED If true, invert direction for touchpad and mouse wheel scroll
|
-- @tfield[opt=false] bool WHEEL_SCROLL_INVERTED If true, invert direction for touchpad and mouse wheel scroll
|
||||||
|
-- @tfield[opt=false] bool WHEEL_SCROLL_BY_INERTION If true, wheel will add inertion to scroll. Direct set position otherwise.
|
||||||
function Scroll.on_style_change(self, style)
|
function Scroll.on_style_change(self, style)
|
||||||
self.style = {}
|
self.style = {}
|
||||||
self.style.EXTRA_STRETCH_SIZE = style.EXTRA_STRETCH_SIZE or 0
|
self.style.EXTRA_STRETCH_SIZE = style.EXTRA_STRETCH_SIZE or 0
|
||||||
@ -128,6 +129,7 @@ function Scroll.on_style_change(self, style)
|
|||||||
self.style.SMALL_CONTENT_SCROLL = style.SMALL_CONTENT_SCROLL or false
|
self.style.SMALL_CONTENT_SCROLL = style.SMALL_CONTENT_SCROLL or false
|
||||||
self.style.WHEEL_SCROLL_SPEED = style.WHEEL_SCROLL_SPEED or 0
|
self.style.WHEEL_SCROLL_SPEED = style.WHEEL_SCROLL_SPEED or 0
|
||||||
self.style.WHEEL_SCROLL_INVERTED = style.WHEEL_SCROLL_INVERTED or false
|
self.style.WHEEL_SCROLL_INVERTED = style.WHEEL_SCROLL_INVERTED or false
|
||||||
|
self.style.WHEEL_SCROLL_BY_INERTION = style.WHEEL_SCROLL_BY_INERTION or false
|
||||||
|
|
||||||
self._is_inert = not (self.style.FRICT == 0 or
|
self._is_inert = not (self.style.FRICT == 0 or
|
||||||
self.style.FRICT_HOLD == 0 or
|
self.style.FRICT_HOLD == 0 or
|
||||||
@ -753,15 +755,28 @@ function Scroll._process_scroll_wheel(self, action_id, action)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local koef = (action_id == const.ACTION_SCROLL_UP) and 1 or -1
|
local koef = (action_id == const.ACTION_SCROLL_UP) and 1 or -1
|
||||||
if self.style.WHEEL_SCROLL_INVERTED then
|
if self.style.WHEEL_SCROLL_INVERTED then
|
||||||
koef = -koef
|
koef = -koef
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.drag.can_y then
|
if self.style.WHEEL_SCROLL_BY_INERTION then
|
||||||
self.inertion.y = (self.inertion.y + self.style.WHEEL_SCROLL_SPEED * koef) * self.style.FRICT_HOLD
|
if self.drag.can_y then
|
||||||
elseif self.drag.can_x then
|
self.inertion.y = (self.inertion.y + self.style.WHEEL_SCROLL_SPEED * koef) * self.style.FRICT_HOLD
|
||||||
self.inertion.x = (self.inertion.x + self.style.WHEEL_SCROLL_SPEED * koef) * self.style.FRICT_HOLD
|
elseif self.drag.can_x then
|
||||||
|
self.inertion.x = (self.inertion.x + self.style.WHEEL_SCROLL_SPEED * koef) * self.style.FRICT_HOLD
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if self.drag.can_y then
|
||||||
|
self.target_position.y = self.target_position.y + self.style.WHEEL_SCROLL_SPEED * koef
|
||||||
|
self.inertion.y = 0
|
||||||
|
elseif self.drag.can_x then
|
||||||
|
self.target_position.x = self.target_position.x + self.style.WHEEL_SCROLL_SPEED * koef
|
||||||
|
self.inertion.x = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
self:_set_scroll_position(self.target_position)
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -73,8 +73,9 @@ M["scroll"] = {
|
|||||||
INERT_SPEED = 30, -- koef. of inert speed
|
INERT_SPEED = 30, -- koef. of inert speed
|
||||||
EXTRA_STRETCH_SIZE = 100, -- extra size in pixels outside of scroll (stretch effect)
|
EXTRA_STRETCH_SIZE = 100, -- extra size in pixels outside of scroll (stretch effect)
|
||||||
POINTS_DEADZONE = 20, -- Speed to check points of interests in no_inertion mode
|
POINTS_DEADZONE = 20, -- Speed to check points of interests in no_inertion mode
|
||||||
WHEEL_SCROLL_SPEED = 0,
|
WHEEL_SCROLL_SPEED = 0, -- Amount of pixels to scroll by one wheel event (0 to disable)
|
||||||
WHEEL_SCROLL_INVERTED = false,
|
WHEEL_SCROLL_INVERTED = false, -- Boolean to invert wheel scroll side
|
||||||
|
WHEEL_SCROLL_BY_INERTION = false, -- If true, wheel will add inertion to scroll. Direct set position otherwise.
|
||||||
SMALL_CONTENT_SCROLL = true, -- If true, content node with size less than view node size can be scrolled
|
SMALL_CONTENT_SCROLL = true, -- If true, content node with size less than view node size can be scrolled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user