Add a new global get_preferred_size() for all widgets
Replace the fit(9999,9999) used before. This will hopefully be temporary until upstream adopt such a method
This commit is contained in:
parent
cf9bb87b36
commit
1229da75c7
2
bar.lua
2
bar.lua
|
@ -60,7 +60,7 @@ local function setup_drawable(data)
|
||||||
--Getters
|
--Getters
|
||||||
data.get_x = function() return 0 end
|
data.get_x = function() return 0 end
|
||||||
data.get_y = function() return 0 end
|
data.get_y = function() return 0 end
|
||||||
data.get_width = function() return internal.layout.fit(internal.layout,9999,99) end
|
data.get_width = function() return internal.layout:get_preferred_size() end
|
||||||
data.get_height = function() return beautiful.default_height end
|
data.get_height = function() return beautiful.default_height end
|
||||||
data.get_visible = function() return true end
|
data.get_visible = function() return true end
|
||||||
data.get_direction = function() return "left" end
|
data.get_direction = function() return "left" end
|
||||||
|
|
6
base.lua
6
base.lua
|
@ -239,7 +239,7 @@ local function add_widget(data,widget,args)
|
||||||
data._internal.items[#data._internal.items+1] = item
|
data._internal.items[#data._internal.items+1] = item
|
||||||
data:emit_signal("widget::added",item,widget)
|
data:emit_signal("widget::added",item,widget)
|
||||||
if data.visible then
|
if data.visible then
|
||||||
local fit_w,fit_h = data._internal.layout:fit({dpi=96}, 9999,9999)
|
local fit_w,fit_h = data._internal.layout:get_preferred_size()
|
||||||
data.width = data._internal.width or fit_w
|
data.width = data._internal.width or fit_w
|
||||||
data.height = fit_h
|
data.height = fit_h
|
||||||
end
|
end
|
||||||
|
@ -264,7 +264,7 @@ local function get_widget_fit_sum(data)
|
||||||
local h,w = 0,0
|
local h,w = 0,0
|
||||||
-- TODO query this from the layout itself
|
-- TODO query this from the layout itself
|
||||||
for k,v in ipairs(data._internal.widgets) do
|
for k,v in ipairs(data._internal.widgets) do
|
||||||
local fw,fh = v.widget:fit({dpi=96},9999,9999)
|
local fw,fh = v.widget:get_preferred_size()
|
||||||
w,h = w + fw,h + fh
|
w,h = w + fw,h + fh
|
||||||
end
|
end
|
||||||
return w,h
|
return w,h
|
||||||
|
@ -409,7 +409,7 @@ print(beautiful.menu_border_color)
|
||||||
data.set_visible = function(_,value)
|
data.set_visible = function(_,value)
|
||||||
private_data.visible = value
|
private_data.visible = value
|
||||||
if value then
|
if value then
|
||||||
local fit_w,fit_h = data._internal.layout:fit({dpi=96}, 9999,9999)
|
local fit_w,fit_h = data._internal.layout:get_preferred_size()
|
||||||
data.width = internal.width or fit_w
|
data.width = internal.width or fit_w
|
||||||
data.height = fit_h
|
data.height = fit_h
|
||||||
elseif data._tmp_menu and data._current_item then
|
elseif data._tmp_menu and data._current_item then
|
||||||
|
|
6
dock.lua
6
dock.lua
|
@ -165,7 +165,7 @@ local function adapt_size(data,w,h,screen)
|
||||||
local max = get_max_size(data,screen)
|
local max = get_max_size(data,screen)
|
||||||
|
|
||||||
-- Get the current size, then compare and ajust
|
-- Get the current size, then compare and ajust
|
||||||
local fit_w,fit_h = data._internal.layout:fit({dpi=96},20,9999,true)
|
local fit_w,fit_h = data._internal.layout:get_preferred_size({dpi=96,force_values=true},beautiful.default_height)
|
||||||
|
|
||||||
-- Get the number of items minus the number of widgets
|
-- Get the number of items minus the number of widgets
|
||||||
-- This can be used to approximate the number of pixel to remove
|
-- This can be used to approximate the number of pixel to remove
|
||||||
|
@ -325,13 +325,13 @@ local function setup_drawable(data)
|
||||||
data.get_x = function() return 0 end
|
data.get_x = function() return 0 end
|
||||||
data.get_y = function() return 0 end
|
data.get_y = function() return 0 end
|
||||||
data.get_width = function()
|
data.get_width = function()
|
||||||
return internal.w and internal.w.width or data._internal.layout:fit({dpi=96},9999,9999,true)
|
return internal.w and internal.w.width or data._internal.layout:get_preferred_size({force_values=true})
|
||||||
end
|
end
|
||||||
data.get_height = function()
|
data.get_height = function()
|
||||||
if internal.orientation == "horizontal" then
|
if internal.orientation == "horizontal" then
|
||||||
return beautiful.default_height
|
return beautiful.default_height
|
||||||
else
|
else
|
||||||
local w,h = internal.layout.fit(internal.layout,{dpi=96},9999,9999)
|
local w,h = internal.layout:get_preferred_size()
|
||||||
return h
|
return h
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
25
init.lua
25
init.lua
|
@ -57,16 +57,35 @@ local function set_underlay(self,udl,args)
|
||||||
self:emit_signal("widget::updated")
|
self:emit_signal("widget::updated")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_preferred_size(self, context, width, height)
|
||||||
|
local context = context or 1
|
||||||
|
|
||||||
|
if type(context) == "number" then
|
||||||
|
context = {dpi=beautiful.xresources.get_dpi(context)}
|
||||||
|
elseif not context.dpi then
|
||||||
|
context.dpi = beautiful.xresources.get_dpi(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
return self:fit(context, width or 9999, height or 9999)
|
||||||
|
end
|
||||||
|
|
||||||
-- Do some monkey patching to extend all wibox.widget
|
-- Do some monkey patching to extend all wibox.widget
|
||||||
base._make_widget =base.make_widget
|
base._make_widget =base.make_widget
|
||||||
base.make_widget = function(...)
|
base.make_widget = function(...)
|
||||||
local ret = base._make_widget(...)
|
local ret = base._make_widget(...)
|
||||||
ret.set_tooltip = set_tooltip
|
ret.set_tooltip = set_tooltip
|
||||||
ret.set_menu = set_menu
|
ret.set_menu = set_menu
|
||||||
ret.set_underlay = set_underlay
|
ret.set_underlay = set_underlay
|
||||||
|
|
||||||
|
-- Textboxes already have it
|
||||||
|
if not ret.get_preferred_size then
|
||||||
|
ret.get_preferred_size = get_preferred_size
|
||||||
|
end
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local bar = require( "radical.bar" )
|
local bar = require( "radical.bar" )
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -109,7 +109,7 @@ function module:setup_item(data,item,args)
|
||||||
text_w:set_markup(value)
|
text_w:set_markup(value)
|
||||||
end
|
end
|
||||||
if data.auto_resize then
|
if data.auto_resize then
|
||||||
local fit_w,fit_h = text_w:fit({dpi=96},999,9999)
|
local fit_w,fit_h = text_w:get_preferred_size()
|
||||||
local is_largest = item == data._internal.largest_item_h
|
local is_largest = item == data._internal.largest_item_h
|
||||||
--TODO find new largest is item is smaller
|
--TODO find new largest is item is smaller
|
||||||
if not data._internal.largest_item_h_v or data._internal.largest_item_h_v < fit_h then
|
if not data._internal.largest_item_h_v or data._internal.largest_item_h_v < fit_h then
|
||||||
|
@ -145,7 +145,7 @@ local function new(data)
|
||||||
end
|
end
|
||||||
local l = wibox.layout.fixed.horizontal()
|
local l = wibox.layout.fixed.horizontal()
|
||||||
l.fit = function(self,context,w,h,force_values) --TODO use the context instead of extra argument
|
l.fit = function(self,context,w,h,force_values) --TODO use the context instead of extra argument
|
||||||
local result,r2 = wibox.layout.fixed.fit(self,context,force_values and w or 99999,force_values and h or 99999)
|
local result,r2 = wibox.layout.fixed:get_preferred_size(self,context, force_values and w, force_values and h)
|
||||||
local w,h
|
local w,h
|
||||||
if data.auto_resize and data._internal.largest_item_h then
|
if data.auto_resize and data._internal.largest_item_h then
|
||||||
w,h = data.rowcount*(data.item_width or data.default_width),data._internal.largest_item_h_v > data.item_height and data._internal.largest_item_h_v or data.item_height
|
w,h = data.rowcount*(data.item_width or data.default_width),data._internal.largest_item_h_v > data.item_height and data._internal.largest_item_h_v or data.item_height
|
||||||
|
|
|
@ -199,11 +199,11 @@ local function compute_geo(data,width,height,force_values)
|
||||||
if data.auto_resize and data._internal.largest_item_w then
|
if data.auto_resize and data._internal.largest_item_w then
|
||||||
w = data._internal.largest_item_w_v > data.default_width and data._internal.largest_item_w_v or data.default_width
|
w = data._internal.largest_item_w_v > data.default_width and data._internal.largest_item_w_v or data.default_width
|
||||||
end
|
end
|
||||||
|
|
||||||
local visblerow = data.visible_row_count
|
local visblerow = data.visible_row_count
|
||||||
|
|
||||||
local sw,sh = data._internal.suf_l:fit({dpi=96},9999,9999)
|
local sw,sh = data._internal.suf_l:get_preferred_size()
|
||||||
local pw,ph = data._internal.pref_l:fit({dpi=96},9999,9999)
|
local pw,ph = data._internal.pref_l:get_preferred_size()
|
||||||
if not data._internal.has_widget then
|
if not data._internal.has_widget then
|
||||||
return w,(total and total > 0 and total or visblerow*data.item_height) + ph + sh
|
return w,(total and total > 0 and total or visblerow*data.item_height) + ph + sh
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue