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