Convert the constraint layout to the new widget system
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
496fbde9b4
commit
746cc23402
|
@ -8,19 +8,16 @@
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local type = type
|
local type = type
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local base = require("wibox.layout.base")
|
local base = require("wibox.widget.base")
|
||||||
local widget_base = require("wibox.widget.base")
|
|
||||||
local math = math
|
local math = math
|
||||||
|
|
||||||
local constraint = { mt = {} }
|
local constraint = { mt = {} }
|
||||||
|
|
||||||
--- Draw a constraint layout
|
--- Layout a constraint layout
|
||||||
function constraint:draw(context, cr, width, height)
|
function constraint:layout(context, width, height)
|
||||||
if not self.widget then
|
if self.widget then
|
||||||
return
|
return { base.place_widget_at(self.widget, 0, 0, width, height) }
|
||||||
end
|
end
|
||||||
|
|
||||||
base.draw_widget(context, cr, self.widget, 0, 0, width, height)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit a constraint layout into the given space
|
--- Fit a constraint layout into the given space
|
||||||
|
@ -43,15 +40,8 @@ end
|
||||||
|
|
||||||
--- Set the widget that this layout adds a constraint on.
|
--- Set the widget that this layout adds a constraint on.
|
||||||
function constraint:set_widget(widget)
|
function constraint:set_widget(widget)
|
||||||
if self.widget then
|
|
||||||
self.widget:disconnect_signal("widget::updated", self._emit_updated)
|
|
||||||
end
|
|
||||||
if widget then
|
|
||||||
widget_base.check_widget(widget)
|
|
||||||
widget:weak_connect_signal("widget::updated", self._emit_updated)
|
|
||||||
end
|
|
||||||
self.widget = widget
|
self.widget = widget
|
||||||
self:emit_signal("widget::updated")
|
self:emit_signal("widget::layout_changed")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set the strategy to use for the constraining. Valid values are 'max',
|
--- Set the strategy to use for the constraining. Valid values are 'max',
|
||||||
|
@ -74,19 +64,19 @@ function constraint:set_strategy(val)
|
||||||
end
|
end
|
||||||
|
|
||||||
self._strategy = func[val]
|
self._strategy = func[val]
|
||||||
self:emit_signal("widget::updated")
|
self:emit_signal("widget::layout_changed")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set the maximum width to val. nil for no width limit.
|
--- Set the maximum width to val. nil for no width limit.
|
||||||
function constraint:set_width(val)
|
function constraint:set_width(val)
|
||||||
self._width = val
|
self._width = val
|
||||||
self:emit_signal("widget::updated")
|
self:emit_signal("widget::layout_changed")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set the maximum height to val. nil for no height limit.
|
--- Set the maximum height to val. nil for no height limit.
|
||||||
function constraint:set_height(val)
|
function constraint:set_height(val)
|
||||||
self._height = val
|
self._height = val
|
||||||
self:emit_signal("widget::updated")
|
self:emit_signal("widget::layout_changed")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Reset this layout. The widget will be unreferenced, strategy set to "max"
|
--- Reset this layout. The widget will be unreferenced, strategy set to "max"
|
||||||
|
@ -117,10 +107,6 @@ local function new(widget, strategy, width, height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ret._emit_updated = function()
|
|
||||||
ret:emit_signal("widget::updated")
|
|
||||||
end
|
|
||||||
|
|
||||||
ret:set_strategy(strategy or "max")
|
ret:set_strategy(strategy or "max")
|
||||||
ret:set_width(width)
|
ret:set_width(width)
|
||||||
ret:set_height(height)
|
ret:set_height(height)
|
||||||
|
|
Loading…
Reference in New Issue