> From 6e061a9a5f37fed5358c5d8179a57fb54b309032 Mon Sep 17 00:00:00 2001
> From: Rocco Aliberti <[email protected]>
> Date: Wed, 15 Jan 2014 23:47:50 +0100
> Subject: [PATCH] wibox.layout.margin: Add margins color parameter
>
> Now the margin layout can color the margins, drawing a bordered widget.
> Added also set_color method.
> Documentation updated.
> Additions to the draw method code written by Uli Schlachter<[email protected]>
Let's make this:
This adds a :set_color() method so that the margin layout can color the
margins, drawing a bordered widget.
(No need to mention the docs nor me :-P)
> ---
> lib/wibox/layout/margin.lua.in | 33 +++++++++++++++++++++++++++++----
> 1 file changed, 29 insertions(+), 4 deletions(-)
>
> diff --git a/lib/wibox/layout/margin.lua.in b/lib/wibox/layout/margin.lua.in
> index 1a278d0..1e86921 100644
> --- a/lib/wibox/layout/margin.lua.in
> +++ b/lib/wibox/layout/margin.lua.in
> @@ -9,6 +9,8 @@ local type = type
> local setmetatable = setmetatable
> local base = require("wibox.layout.base")
> local widget_base = require("wibox.widget.base")
> +local gcolor = require("gears.color")
> +local cairo = require("lgi").cairo
>
> -- wibox.layout.margin
> local margin = { mt = {} }
> @@ -19,11 +21,22 @@ function margin:draw(wibox, cr, width, height)
> local y = self.top
> local w = self.right
> local h = self.bottom
> + local color = self.color
>
> if not self.widget or width <= x + w or height <= y + h then
> return
> end
>
> + if color then
> + cr:save()
> + cr:set_source(gcolor(self.color))
I don't like the gears.color() call here. If it errors out, we get "ungood"
error messages and this creates a temporary object unnecessarily. I would just
save the pattern that gcolor() returns directly (See below).
> + cr:rectangle(0, 0, width, height)
> + cr:rectangle(x, y, width - x - w, height - y - h)
> + cr:set_fill_rule(cairo.FillRule.EVEN_ODD)
> + cr:fill()
> + cr:restore()
> + end
> +
> base.draw_widget(wibox, cr, self.widget, x, y, width - x - w, height - y
> - h)
> end
>
> @@ -51,19 +64,28 @@ function margin:set_widget(widget)
> self._emit_updated()
> end
>
> ---- Set all the margins to val.
> -function margin:set_margins(val)
> +--- Set all the margins to val, and their color to color
> +function margin:set_margins(val, color)
> self.left = val
> self.right = val
> self.top = val
> self.bottom = val
> + self.color = color
> self:emit_signal("widget::updated")
> end
:set_margins() IMO has nothing to do with the color. Why should this be here? I
would just remove it.
> ---- Reset this layout. The widget will be unreferenced and the margins set
> to 0.
> +--- Set the margins color to color
> +function margin:set_color(color)
> + self.color = color
> + self._emit_updated()
> +end
As mentioned above: Please make this:
self.color = color and gcolor(color)
(The "and" is there so that :set_color(null) erases the color instead of setting
a black color)
(Oh and if gears.color() doesn't like the argument, the :set_color() call will
error out instead of breaking the widget by making it error out from its :draw()
method).
> +--- Reset this layout. The widget will be unreferenced, the margins set to 0
> +-- and the color erased
> function margin:reset()
> self:set_widget(nil)
> self:set_margins(0)
> + self:set_color()
:set_color(nil), please.
> end
>
> --- Set the left margin that this layout adds to its widget.
> @@ -104,7 +126,8 @@ end
> -- @param right A margin to use on the right side of the widget (optional)
> -- @param top A margin to use on the top side of the widget (optional)
> -- @param bottom A margin to use on the bottom side of the widget (optional)
> -local function new(widget, left, right, top, bottom)
> +-- @param color A color for the margins (optional)
> +local function new(widget, left, right, top, bottom, color)
> local ret = widget_base.make_widget()
>
> for k, v in pairs(margin) do
> @@ -122,6 +145,8 @@ local function new(widget, left, right, top, bottom)
> ret:set_top(top or 0)
> ret:set_bottom(bottom or 0)
>
> + ret:set_color(color)
> +
> if widget then
> ret:set_widget(widget)
> end
> -- 1.8.4
If you are OK with these changes, I would just change the patch to my liking
locally and commit it. Alternatively, feel free to submit a new version.
Uli
--
"Because I'm in pain," he says. "That's the only way I get your attention."
He picks up the box. "Don't worry, Katniss. It'll pass."
He leaves before I can answer.
--
To unsubscribe, send mail to [email protected].