【发布时间】:2019-09-25 08:18:17
【问题描述】:
这是How to make mouse events propagate to widgets in `scroll` containers?
的后续行动TL;DR:
我实现的:layout 方法使小部件在其他小部件上绘制(见下图)。如何限制:layout 方法将在哪里绘制我的小部件以及它允许我在哪里与孩子进行交互?
加长版:
所以我最终修补了scroll 容器,我所做的基本上是实现了一个:layout 方法,基于原始scroll 容器代码中已经进行的偏移计算。
这基本上是我做的(我这里只放相关部分):
-- this function emits signals `self._private.fps` times a second
local _need_scroll_redraw = function(self)
if not self._private.paused and not self._private.scroll_timer then
self._private.scroll_timer = timer.start_new(1 / self._private.fps, function()
self._private.scroll_timer = nil
self:emit_signal("widget::redraw_needed")
self:emit_signal("widget::layout_changed") -- this is the only
-- line that I added
-- to this function
end)
end
end
local function calculate_info(self, context, width, height)
-- this is a longer function, but in summary here we calculate the
-- ideal size that the child would like to be, we see if the child
-- is bigger than the space we have for drawing, and if it is,
-- we calculate offsets (and we call `_need_scroll_redraw` here)
-- so we later know where and how often to `:draw` and `:fit` it
end
function scroll:fit(context, width, height)
local info = calculate_info(self, context, width, height)
return info.fit_width, info.fit_height
end
function scroll:layout(context, width, height)
local result = {}
local i = calculate_info(self, context, width, height)
table.insert(result, base.place_widget_at(
self._private.widget, i.first_x, i.first_y, i.surface_width, i.surface_height
))
return result
end
-- Also, there was a `:draw` method, but I took it out entirely since
-- if I add the `:layout` method, things get drawn just fine
-- P.S: I also tried to implement what was in the `:draw` method, inside
-- the `:layout` method, so that it'll clip properly. I also tried that idea
-- with the `:before_draw_children` and `:after_draw_children` methods
-- but since I don't know how to use cairo, god knows what I wrote there,
-- but it didn't work
使用默认的滚动小部件,我的小部件看起来像这样,但我点击的没有任何效果:
但是通过我上面所做的更改,带有行的小部件确实滚动了,我可以很好地点击每个孩子并让它做出反应,只是它在其边界之外绘制 所有内容 ,我也可以点击边界之外的东西:
所以我的问题是:我将如何限制 :layout 方法显示的内容,让它以默认 scroll 布局的方式工作,但仍然能够与孩子互动?
【问题讨论】:
标签: awesome-wm