how to dynamically resize a widget to be same width

i have a widget that shows me my current net up/download usage, but i dont like seeing it wrap around, and if i use the wrap = "word" option, then i just a if it gets too long.

i want that the text should shrink in size the wider it gets and grow back to the original if theres space.

theres probably a wibox.layout.something that can do it, but i cant find it…


this is the net widget at when it isnt overflowing.


this is the net widget when it is overflowing. i want that instead of making a new line, it should just shrink the text. is there any way of doing this?

i managed to fake it by checking if the length is >=4 then changing the font, else make font normal.

-- {{{ internet traffic
up_traffic = wibox.widget {
		align = "center",
		valign = "center",
		widget = wibox.widget.textbox,
}
down_traffic = wibox.widget {
		align = "center",
		valign = "center",
		widget = wibox.widget.textbox,
}

lain.widget.net({
	units = 1, -- set the units to bytes, not kilobytes (1024)
    settings = function()
		up = net_now.sent
		up_amount = "b"
	    if tonumber(up) > 1000000 then
				up = up/1000000
				up_amount = "m"
    	elseif tonumber(up) > 1000 then
				up = up/1000
				up_amount = "k"
    	else
        	up_amount = "b"
    	end
		down = net_now.received
		down_amount = "b"
	    if tonumber(down) > 1000000 then
				down = down/1000000
				down_amount = "m"
    	elseif tonumber(down) > 1000 then
				down = down/1000
				down_amount = "k"
    	else
        	down_amount = "b"
    	end

        --widget:set_markup("↑" .. net_now.sent.."\n↓" .. net_now.received)
        --widget:set_markup(math.floor(up)..up_amount.."\n"..math.floor(down)..down_amount)
		--textbox.text = (math.floor(up)..up_amount.."\n"..math.floor(down)..down_amount)
		up_traffic.text = math.floor(up)..up_amount
		small_font = "Noto Sans Regular 8"
		big_font = "Noto Sans Regular 10"
		if #up_traffic.text >= 4 then
				up_traffic.font = small_font
		else
				up_traffic.font = big_font
		end
		down_traffic.text = math.floor(down)..down_amount
		if #down_traffic.text >= 4 then
				down_traffic.font = small_font
		else
				down_traffic.font = big_font
		end
    end
})

net = wibox.widget { -- internet monitor
		{
			up_traffic,
			down_traffic,
			forced_height = 35,
			layout = wibox.layout.fixed.vertical,
		},
		direction = "west",
		widget = wibox.container.rotate,
}
-- }}}

but it would still be nice to have an actual way (non hack way) to do it

1 Like

on a related note, i cant figure out how to center horizontal align widgets in a vertical wibox

I do not know of a way to do this. And I do not think there is any. This scaling would require the font size of the textbox to change and this is AFAIK a fixed property, which can be changed by the user as you do already in your hack.
But you can also ask the developers of awesome if they know a way to achieve this in a better way:

I would try to use the place container: https://awesomewm.org/apidoc/widget_containers/wibox.container.place.html
Maybe this helps you also: https://awesomewm.org/apidoc/documentation/03-declarative-layout.md.html

1 Like

image

do you know if theres a way to center the tags within the taglist?

I have not tried it, but I think this should be possible with a margins or place container a bit like in the example here: https://awesomewm.org/apidoc/widgets/awful.widget.taglist.html

You can use the declarative syntax to create a template widget for your taglist. Somewhere down on the webpage of my the last link in my first post the difference between declarative and imperative syntax is explained.

Make a backup of your rc.lua before you start playing around. You could also start using the example and changing parameters to understand how it works (I did that when I set up my taskbar with the declarative syntax)

1 Like

Forum kindly sponsored by Bytemark