From 5ac0829f5df5f15b24528b4e50bb7fb30e8bc685 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Tue, 21 Dec 2021 11:55:36 +0100 Subject: [PATCH] docs(w.w.slider): Add value signal to initial example Since the primary use case of the slider widget is to do something with the value when it changes, the initial example should show how to do that. --- .../examples/wibox/widget/defaults/slider.lua | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/tests/examples/wibox/widget/defaults/slider.lua b/tests/examples/wibox/widget/defaults/slider.lua index 94c3012e..1450a871 100644 --- a/tests/examples/wibox/widget/defaults/slider.lua +++ b/tests/examples/wibox/widget/defaults/slider.lua @@ -1,12 +1,12 @@ ---DOC_GEN_IMAGE --DOC_HIDE -local parent = ... --DOC_HIDE -local wibox = require( "wibox" ) --DOC_HIDE -local beautiful = require( "beautiful" ) --DOC_HIDE -local gears = {shape=require("gears.shape") } --DOC_HIDE +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require( "wibox" ) +local beautiful = require( "beautiful" ) +local gears = {shape=require("gears.shape") } +local naughty = { notify = function(_) end } -parent:add( --DOC_HIDE - -wibox.widget { +--DOC_HIDE_END +local widget = wibox.widget { bar_shape = gears.shape.rounded_rect, bar_height = 3, bar_color = beautiful.border_color, @@ -19,6 +19,19 @@ wibox.widget { forced_height = 50, --DOC_HIDE forced_width = 100, --DOC_HIDE } +--DOC_NEWLINE +-- Connect to `property::value` to use the value on change +widget:connect_signal("property::value", function(_, new_value) + --DOC_HIDE_START + if new_value ~= 10 then + error(string.format("unexpected value %s", new_value)) + end + --DOC_HIDE_END + naughty.notify { title = "Slider changed", message = new_value } +end) -) --DOC_HIDE ---DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 +--DOC_HIDE_START +widget.value = 10 +parent:add(widget) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80