feat(w.l.overflow): Rename ambiguous property
Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
This commit is contained in:
parent
580a0803a5
commit
5e10f2620e
|
@ -122,7 +122,7 @@ function overflow:layout(context, orig_width, orig_height)
|
||||||
|
|
||||||
local need_scrollbar = used_in_dir > avail_in_dir and scrollbar_enabled
|
local need_scrollbar = used_in_dir > avail_in_dir and scrollbar_enabled
|
||||||
|
|
||||||
local scroll_position = self._private.position
|
local scroll_position = self._private.scroll_factor
|
||||||
|
|
||||||
if need_scrollbar then
|
if need_scrollbar then
|
||||||
local scrollbar_widget = self._private.scrollbar_widget
|
local scrollbar_widget = self._private.scrollbar_widget
|
||||||
|
@ -134,7 +134,7 @@ function overflow:layout(context, orig_width, orig_height)
|
||||||
-- Make scrollbar length reflect `visible_percent`
|
-- Make scrollbar length reflect `visible_percent`
|
||||||
-- TODO: Apply a default minimum length
|
-- TODO: Apply a default minimum length
|
||||||
local bar_length = math.floor(visible_percent * avail_in_dir)
|
local bar_length = math.floor(visible_percent * avail_in_dir)
|
||||||
local bar_pos = (avail_in_dir - bar_length) * self._private.position
|
local bar_pos = (avail_in_dir - bar_length) * self._private.scroll_factor
|
||||||
|
|
||||||
if is_y then
|
if is_y then
|
||||||
bar_w, bar_h = base.fit_widget(self, context, scrollbar_widget, scrollbar_width, bar_length)
|
bar_w, bar_h = base.fit_widget(self, context, scrollbar_widget, scrollbar_width, bar_length)
|
||||||
|
@ -279,8 +279,9 @@ end
|
||||||
--
|
--
|
||||||
-- @method overflow:scroll
|
-- @method overflow:scroll
|
||||||
-- @tparam number amount The amount to scroll by.
|
-- @tparam number amount The amount to scroll by.
|
||||||
-- @emits property::overflow::position
|
-- @emits property::overflow::scroll_factor
|
||||||
-- @emitstparam property::overflow::position number position The new position.
|
-- @emitstparam property::overflow::scroll_factor number scroll_factor The new
|
||||||
|
-- scroll factor.
|
||||||
-- @emits widget::layout_changed
|
-- @emits widget::layout_changed
|
||||||
-- @emits widget::redraw_needed
|
-- @emits widget::redraw_needed
|
||||||
function overflow:scroll(amount)
|
function overflow:scroll(amount)
|
||||||
|
@ -290,39 +291,42 @@ function overflow:scroll(amount)
|
||||||
local interval = self._private.used_in_dir
|
local interval = self._private.used_in_dir
|
||||||
local delta = self._private.step / interval
|
local delta = self._private.step / interval
|
||||||
|
|
||||||
local pos = self._private.position + (delta * amount)
|
local factor = self._private.scroll_factor + (delta * amount)
|
||||||
self:set_position(pos)
|
self:set_scroll_factor(factor)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- The scroll position.
|
--- The scroll factor.
|
||||||
-- The position is represented as a fraction from `0` to `1`.
|
|
||||||
--
|
--
|
||||||
-- @property position
|
-- The scroll factor represents the how for the layout's content is currently
|
||||||
-- @tparam number position The position.
|
-- scrolled. It is represented as a fraction from `0` to `1`, where `0` is the
|
||||||
|
-- start of the content and `0` is the end.
|
||||||
|
--
|
||||||
|
-- @property scroll_factor
|
||||||
|
-- @tparam number scroll_factor The scroll factor.
|
||||||
-- @propemits true false
|
-- @propemits true false
|
||||||
|
|
||||||
function overflow:set_position(pos)
|
function overflow:set_scroll_factor(factor)
|
||||||
local current = self._private.position
|
local current = self._private.scroll_factor
|
||||||
local interval = self._private.used_in_dir - self._private.avail_in_dir
|
local interval = self._private.used_in_dir - self._private.avail_in_dir
|
||||||
if current == pos
|
if current == factor
|
||||||
-- the content takes less space than what is available, i.e. everything
|
-- the content takes less space than what is available, i.e. everything
|
||||||
-- is already visible
|
-- is already visible
|
||||||
or interval <= 0
|
or interval <= 0
|
||||||
-- the position is out of range
|
-- the scroll factor is out of range
|
||||||
or (current <= 0 and pos < 0)
|
or (current <= 0 and factor < 0)
|
||||||
or (current >= 1 and pos > 1) then
|
or (current >= 1 and factor > 1) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
self._private.position = math.min(1, math.max(pos, 0))
|
self._private.scroll_factor = math.min(1, math.max(factor, 0))
|
||||||
|
|
||||||
self:emit_signal("widget::layout_changed")
|
self:emit_signal("widget::layout_changed")
|
||||||
self:emit_signal("property::position", pos)
|
self:emit_signal("property::scroll_factor", factor)
|
||||||
end
|
end
|
||||||
|
|
||||||
function overflow:get_position()
|
function overflow:get_scroll_factor()
|
||||||
return self._private.position
|
return self._private.scroll_factor
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -403,11 +407,11 @@ function overflow:get_scrollbar_enabled()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Wraps a callback function for `mousegrabber` that is capable of
|
-- Wraps a callback function for `mousegrabber` that is capable of
|
||||||
-- updating the scroll position.
|
-- updating the scroll factor.
|
||||||
local function build_grabber(container)
|
local function build_grabber(container)
|
||||||
local is_y = container._private.dir == "y"
|
local is_y = container._private.dir == "y"
|
||||||
local bar_interval = container._private.avail_in_dir - container._private.bar_length
|
local bar_interval = container._private.avail_in_dir - container._private.bar_length
|
||||||
local start_pos = container._private.position * bar_interval
|
local start_pos = container._private.scroll_factor * bar_interval
|
||||||
local coords = mouse.coords()
|
local coords = mouse.coords()
|
||||||
local start = is_y and coords.y or coords.x
|
local start = is_y and coords.y or coords.x
|
||||||
|
|
||||||
|
@ -417,7 +421,7 @@ local function build_grabber(container)
|
||||||
end
|
end
|
||||||
|
|
||||||
local pos = is_y and mouse.y or mouse.x
|
local pos = is_y and mouse.y or mouse.x
|
||||||
container:set_position((start_pos + (pos - start)) / bar_interval)
|
container:set_scroll_factor((start_pos + (pos - start)) / bar_interval)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -466,8 +470,8 @@ local function new(dir, ...)
|
||||||
gtable.crush(ret, overflow, true)
|
gtable.crush(ret, overflow, true)
|
||||||
ret.widget_name = gobject.modulename(2)
|
ret.widget_name = gobject.modulename(2)
|
||||||
|
|
||||||
-- Manually set the position here. We don't know the bounding size yet.
|
-- Manually set the scroll factor here. We don't know the bounding size yet.
|
||||||
ret._private.position = 0
|
ret._private.scroll_factor = 0
|
||||||
|
|
||||||
-- Apply defaults. Bypass setters to avoid signals.
|
-- Apply defaults. Bypass setters to avoid signals.
|
||||||
ret._private.step = 10
|
ret._private.step = 10
|
||||||
|
|
|
@ -104,7 +104,7 @@ describe("wibox.layout.overflow", function()
|
||||||
p(second, 0, 10, 95, 15),
|
p(second, 0, 10, 95, 15),
|
||||||
})
|
})
|
||||||
|
|
||||||
layout:set_position(1)
|
layout:set_scroll_factor(1)
|
||||||
|
|
||||||
assert.widget_layout(layout, { 100, 20 }, {
|
assert.widget_layout(layout, { 100, 20 }, {
|
||||||
p(scrollbar, 95, 9, 5, 10),
|
p(scrollbar, 95, 9, 5, 10),
|
||||||
|
|
Loading…
Reference in New Issue