cleanup: Remove duplicated logic
This commit is contained in:
parent
0be013f1f7
commit
b65ddbed0e
|
@ -1,4 +1,4 @@
|
|||
local wibox = require( "wibox" )
|
||||
local wibox = require( "wibox" )
|
||||
|
||||
local module = {}
|
||||
|
||||
|
|
|
@ -192,6 +192,30 @@ local function new_item(data,args)
|
|||
item_style(item)
|
||||
end
|
||||
|
||||
function item:set_text(text)
|
||||
local text_w = item._internal.text_w
|
||||
if not text_w then return end
|
||||
|
||||
if data.disable_markup then
|
||||
text_w:set_text(text)
|
||||
else
|
||||
text_w:set_markup(text)
|
||||
end
|
||||
|
||||
if data.auto_resize then
|
||||
local fit_w,fit_h = text_w:get_preferred_size()
|
||||
local is_largest = item == data._internal.largest_item_h
|
||||
|
||||
--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
|
||||
-- data._internal.largest_item_h =item
|
||||
-- data._internal.largest_item_h_v = fit_h
|
||||
-- end
|
||||
end
|
||||
|
||||
item._private_data.text = text
|
||||
end
|
||||
|
||||
-- Overlay and underlay
|
||||
item.set_infoshapes = set_infoshapes
|
||||
|
||||
|
|
|
@ -55,15 +55,6 @@ function module:setup_sub_menu_arrow(item,data)
|
|||
end
|
||||
end
|
||||
|
||||
local function set_text(self, value)
|
||||
if data.disable_markup then
|
||||
self:set_text(value)
|
||||
else
|
||||
self:set_markup(value)
|
||||
end
|
||||
self._private_data.text = value
|
||||
end
|
||||
|
||||
-- Create the actual widget
|
||||
local function create_item(item,data,args)
|
||||
-- F keys
|
||||
|
@ -110,6 +101,7 @@ local function create_item(item,data,args)
|
|||
{
|
||||
-- The main textbox
|
||||
id = "main_text" ,
|
||||
_data = data ,
|
||||
_private_data = item._private_data ,
|
||||
text = item.text ,
|
||||
widget = wibox.widget.textbox,
|
||||
|
@ -159,9 +151,6 @@ local function create_item(item,data,args)
|
|||
item._internal.text_w = item.widget:get_children_by_id("main_text" )[1]
|
||||
item._internal.icon_w = icon
|
||||
|
||||
-- Override some methods
|
||||
item._internal.text_w.set_text = set_text
|
||||
|
||||
-- Export the margin
|
||||
local mrgns = margins2(
|
||||
item._internal.margin_w,
|
||||
|
|
|
@ -1,45 +1,27 @@
|
|||
local setmetatable = setmetatable
|
||||
local print,pairs = print,pairs
|
||||
local unpack=unpack
|
||||
local util = require( "awful.util" )
|
||||
local button = require( "awful.button" )
|
||||
local checkbox = require( "radical.widgets.checkbox" )
|
||||
local wibox = require( "wibox" )
|
||||
local common = require( "radical.common" )
|
||||
local item_layout = require("radical.item.layout.icon")
|
||||
local wibox = require( "wibox" )
|
||||
local common = require( "radical.common" )
|
||||
|
||||
local module = {}
|
||||
|
||||
function module:setup_item(data,item,args)
|
||||
local text_w = item._internal.text_w
|
||||
-- Compute the minimum width
|
||||
if data.auto_resize then --FIXME this wont work if thext change
|
||||
local _, fit_h = item._internal.margin_w:get_preferred_size()
|
||||
|
||||
-- Setup text
|
||||
item.set_text = function (_,value)
|
||||
if data.disable_markup then
|
||||
text_w:set_text(value)
|
||||
else
|
||||
text_w:set_markup(value)
|
||||
if not data._internal.largest_item_h_v or data._internal.largest_item_h_v < fit_h then
|
||||
data._internal.largest_item_h = item
|
||||
data._internal.largest_item_h_v = fit_h
|
||||
end
|
||||
end
|
||||
if data.auto_resize then
|
||||
local fit_w,fit_h = text_w:get_preferred_size()
|
||||
local is_largest = item == data._internal.largest_item_h
|
||||
--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
|
||||
data._internal.largest_item_h =item
|
||||
data._internal.largest_item_h_v = fit_h
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
item:set_text(item._private_data.text)
|
||||
|
||||
item:set_text(item._private_data.text)
|
||||
end
|
||||
|
||||
--Get preferred item geometry
|
||||
local function item_fit(data,item,self, content, width, height)
|
||||
if not data.visible then return 1,1 end
|
||||
local w, h = item._private_data._fit(self,content,width,height) --TODO port to new context API
|
||||
return data.item_width or 70, item._private_data.height or h --TODO broken
|
||||
local function item_fit(data,item,self, context, width, height)
|
||||
local w, h = item._private_data._fit(self,context,width,height) --TODO port to new context API
|
||||
|
||||
return data.item_width or w, h --TODO broken
|
||||
end
|
||||
|
||||
local function new(data)
|
||||
|
|
|
@ -1,22 +1,15 @@
|
|||
local setmetatable = setmetatable
|
||||
local print,ipairs = print,ipairs
|
||||
local scroll = require( "radical.widgets.scroll" )
|
||||
local filter = require( "radical.widgets.filter" )
|
||||
local wibox = require( "wibox" )
|
||||
local cairo = require( "lgi" ).cairo
|
||||
local common = require( "radical.common" )
|
||||
local horizontal_item_layout= require( "radical.item.layout.horizontal" )
|
||||
local scroll = require( "radical.widgets.scroll" )
|
||||
local filter = require( "radical.widgets.filter" )
|
||||
local wibox = require( "wibox" )
|
||||
local common = require( "radical.common" )
|
||||
|
||||
local module = {}
|
||||
|
||||
--Get preferred item geometry
|
||||
local function item_fit(data,item,self,context, width,height)
|
||||
local w, h = 0,0--item._internal.cache_w or 1,item._internal.cache_h or 1
|
||||
if data.visible then
|
||||
w, h = item._private_data._fit(self,context,width,height)
|
||||
end
|
||||
|
||||
return w, item.height or h
|
||||
local w, h = item._private_data._fit(self,context,width,height)
|
||||
return w, item.height or h --TODO use a constraint widget
|
||||
end
|
||||
|
||||
function module:setup_item(data,item,args)
|
||||
|
@ -27,9 +20,9 @@ function module:setup_item(data,item,args)
|
|||
item._internal.margin_w.fit = function(...) return item_fit(data,item,...) end
|
||||
|
||||
-- Compute the minimum width
|
||||
if data.auto_resize then
|
||||
local fit_w = wibox.layout.margin.fit(item._internal.margin_w,{dpi=96},9999,9999)
|
||||
local is_largest = item == data._internal.largest_item_w
|
||||
if data.auto_resize then --FIXME this wont work if thext change
|
||||
local fit_w = item._internal.margin_w:get_preferred_size()
|
||||
|
||||
if fit_w < 1000 and (not data._internal.largest_item_w_v or data._internal.largest_item_w_v < fit_w) then
|
||||
data._internal.largest_item_w = item
|
||||
data._internal.largest_item_w_v = fit_w
|
||||
|
|
Loading…
Reference in New Issue