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,
	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"
        	up_amount = "b"
		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"
        	down_amount = "b"

        --widget:set_markup("↑" .. net_now.sent.."\n↓" .. net_now.received)
		--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
				up_traffic.font = big_font
		down_traffic.text = math.floor(down)..down_amount
		if #down_traffic.text >= 4 then
				down_traffic.font = small_font
				down_traffic.font = big_font

net = wibox.widget { -- internet monitor
			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:
Maybe this helps you also:

1 Like


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:

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

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by