Initial Commit
This commit is contained in:
43
widget/material/clickable-container.lua
Normal file
43
widget/material/clickable-container.lua
Normal file
@@ -0,0 +1,43 @@
|
||||
local wibox = require('wibox')
|
||||
|
||||
function build(widget, label)
|
||||
local container = wibox.widget {
|
||||
-- widget,
|
||||
wibox.widget {
|
||||
text = label,
|
||||
widget = wibox.widget.textbox,
|
||||
},
|
||||
widget = wibox.container.background
|
||||
}
|
||||
local old_cursor, old_wibox
|
||||
|
||||
container:connect_signal('mouse::enter', function()
|
||||
container.bg = '#ffffff11'
|
||||
-- Hm, no idea how to get the wibox from this signal's arguments...
|
||||
local w = _G.mouse.current_wibox
|
||||
if w then
|
||||
old_cursor, old_wibox = w.cursor, w
|
||||
w.cursor = 'hand1'
|
||||
end
|
||||
end)
|
||||
|
||||
container:connect_signal('mouse::leave', function()
|
||||
container.bg = '#ffffff00'
|
||||
if old_wibox then
|
||||
old_wibox.cursor = old_cursor
|
||||
old_wibox = nil
|
||||
end
|
||||
end)
|
||||
|
||||
container:connect_signal('button::press', function()
|
||||
container.bg = '#ffffff22'
|
||||
end)
|
||||
|
||||
container:connect_signal('button::release', function()
|
||||
container.bg = '#ffffff11'
|
||||
end)
|
||||
|
||||
return container
|
||||
end
|
||||
|
||||
return build
|
14
widget/material/icon-button.lua
Normal file
14
widget/material/icon-button.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
local wibox = require('wibox')
|
||||
local gears = require('gears')
|
||||
local clickable_container = require('widget.material.clickable-container')
|
||||
local dpi = require('beautiful').xresources.apply_dpi
|
||||
|
||||
function build(imagebox, args)
|
||||
return wibox.widget {
|
||||
imagebox,
|
||||
shape = gears.shape.circle,
|
||||
widget = clickable_container
|
||||
}
|
||||
end
|
||||
|
||||
return build
|
80
widget/material/icon.lua
Normal file
80
widget/material/icon.lua
Normal file
@@ -0,0 +1,80 @@
|
||||
-- Default widget requirements
|
||||
local base = require('wibox.widget.base')
|
||||
local gtable = require('gears.table')
|
||||
local setmetatable = setmetatable
|
||||
|
||||
-- Commons requirements
|
||||
local wibox = require('wibox')
|
||||
|
||||
-- Local declarations
|
||||
|
||||
local mat_list_item = {mt = {}}
|
||||
|
||||
function mat_list_item:layout(_, width, height)
|
||||
local layout = {}
|
||||
|
||||
-- Add divider if present
|
||||
if self._private.icon then
|
||||
table.insert(
|
||||
layout,
|
||||
base.place_widget_at(
|
||||
self._private.imagebox,
|
||||
width / 2 - self._private.size / 2,
|
||||
height / 2 - self._private.size / 2,
|
||||
self._private.size,
|
||||
self._private.size
|
||||
)
|
||||
)
|
||||
end
|
||||
return layout
|
||||
end
|
||||
|
||||
function mat_list_item:fit(_, width, height)
|
||||
local min = math.min(width, height)
|
||||
return min, min
|
||||
end
|
||||
|
||||
function mat_list_item:set_icon(icon)
|
||||
self._private.icon = icon
|
||||
self._private.imagebox.image = icon
|
||||
end
|
||||
|
||||
function mat_list_item:get_icon()
|
||||
return self._private.icon
|
||||
end
|
||||
|
||||
function mat_list_item:set_size(size)
|
||||
self._private.size = size
|
||||
self:emit_signal('widget::layout_changed')
|
||||
end
|
||||
|
||||
function mat_list_item:get_size()
|
||||
return self._private.size
|
||||
end
|
||||
|
||||
local function new(icon, size)
|
||||
local ret =
|
||||
base.make_widget(
|
||||
nil,
|
||||
nil,
|
||||
{
|
||||
enable_properties = true
|
||||
}
|
||||
)
|
||||
|
||||
gtable.crush(ret, mat_list_item, true)
|
||||
ret._private.icon = icon
|
||||
ret._private.imagebox = wibox.widget.imagebox(icon)
|
||||
ret._private.size = size
|
||||
return ret
|
||||
end
|
||||
|
||||
function mat_list_item.mt:__call(...)
|
||||
return new(...)
|
||||
end
|
||||
|
||||
--@DOC_widget_COMMON@
|
||||
|
||||
--@DOC_object_COMMON@
|
||||
|
||||
return setmetatable(mat_list_item, mat_list_item.mt)
|
186
widget/material/list-item.lua
Normal file
186
widget/material/list-item.lua
Normal file
@@ -0,0 +1,186 @@
|
||||
-- Default widget requirements
|
||||
local base = require('wibox.widget.base')
|
||||
local gtable = require('gears.table')
|
||||
local setmetatable = setmetatable
|
||||
local dpi = require('beautiful').xresources.apply_dpi
|
||||
|
||||
-- Commons requirements
|
||||
local wibox = require('wibox')
|
||||
local clickable_container = require('widget.material.clickable-container')
|
||||
-- Local declarations
|
||||
|
||||
local mat_list_item = {
|
||||
mt = {}
|
||||
}
|
||||
|
||||
function mat_list_item:build_separator()
|
||||
self._private.separator = wibox.widget {
|
||||
orientation = 'horizontal',
|
||||
forced_height = 1,
|
||||
opacity = 0.08,
|
||||
widget = wibox.widget.separator
|
||||
}
|
||||
self:emit_signal('widget::layout_changed')
|
||||
end
|
||||
|
||||
function mat_list_item:build_clickable_container()
|
||||
self._private.clickable_container = wibox.widget {
|
||||
wibox.widget {
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
widget = clickable_container
|
||||
}
|
||||
self:emit_signal('widget::layout_changed')
|
||||
end
|
||||
|
||||
function mat_list_item:layout(_, width, height)
|
||||
local content_width = width - dpi(32)
|
||||
local content_x = dpi(dpi(16))
|
||||
local layout = {}
|
||||
|
||||
-- Add divider if present
|
||||
if self._private.divider then
|
||||
table.insert(layout, base.place_widget_at(self._private.separator, 0, 0, width, 1))
|
||||
end
|
||||
|
||||
-- Add clickable_container if clickable
|
||||
if self._private.clickable then
|
||||
table.insert(layout, base.place_widget_at(self._private.clickable_container, 0, 0, width, height))
|
||||
end
|
||||
|
||||
if self._private.prefix then
|
||||
content_x = content_x + dpi(54)
|
||||
content_width = content_width - dpi(54)
|
||||
table.insert(layout, base.place_widget_at(self._private.prefix, dpi(16), 0, dpi(48), height))
|
||||
end
|
||||
|
||||
if self._private.suffix then
|
||||
content_width = content_width - dpi(54)
|
||||
table.insert(layout, base.place_widget_at(self._private.suffix, width - dpi(40), dpi(12), width, height))
|
||||
end
|
||||
table.insert(layout, base.place_widget_at(self._private.content, content_x, 0, content_width, height))
|
||||
return layout
|
||||
end
|
||||
|
||||
function mat_list_item:fit(_, width)
|
||||
return width, dpi(48)
|
||||
end
|
||||
|
||||
---- Properties ----
|
||||
|
||||
-- Property clickable
|
||||
function mat_list_item:set_clickable(value)
|
||||
if self._private.clickable ~= value then
|
||||
self._private.clickable = value
|
||||
self:emit_signal('property::clickable')
|
||||
self:emit_signal('widget::layout_changed')
|
||||
|
||||
if self._private.clickable and not self._private.clickable_container then
|
||||
self:build_clickable_container()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function mat_list_item:get_clickable()
|
||||
return self._private.clickable
|
||||
end
|
||||
|
||||
-- Property divider
|
||||
|
||||
function mat_list_item:set_divider(value)
|
||||
if self._private.divider ~= value then
|
||||
self._private.divider = value
|
||||
self:emit_signal('property::divider')
|
||||
self:emit_signal('widget::layout_changed')
|
||||
|
||||
if self._private.divider and not self._private.separator then
|
||||
self:build_separator()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function mat_list_item:get_divider()
|
||||
return self._private.divider
|
||||
end
|
||||
|
||||
function mat_list_item:set_prefix(widget)
|
||||
if widget then
|
||||
base.check_widget(widget)
|
||||
end
|
||||
self._private.prefix = widget
|
||||
self:emit_signal('widget::layout_changed')
|
||||
end
|
||||
|
||||
function mat_list_item:get_prefix()
|
||||
return self._private.prefix
|
||||
end
|
||||
|
||||
function mat_list_item:set_suffix(widget)
|
||||
if widget then
|
||||
base.check_widget(widget)
|
||||
end
|
||||
self._private.suffix = widget
|
||||
self:emit_signal('widget::layout_changed')
|
||||
end
|
||||
|
||||
function mat_list_item:get_suffix()
|
||||
return self._private.suffix
|
||||
end
|
||||
|
||||
--- The widget who will be the content.
|
||||
-- @property content
|
||||
-- @tparam widget widget The widget
|
||||
|
||||
function mat_list_item:set_content(widget)
|
||||
if widget then
|
||||
base.check_widget(widget)
|
||||
end
|
||||
self._private.content = widget
|
||||
self:emit_signal('widget::layout_changed')
|
||||
end
|
||||
|
||||
function mat_list_item:get_content()
|
||||
return self._private.content
|
||||
end
|
||||
|
||||
-- Get the number of children element
|
||||
-- @treturn table The children
|
||||
function mat_list_item:get_children()
|
||||
return {self._private.widget}
|
||||
end
|
||||
|
||||
-- Replace the layout children
|
||||
-- This layout only accept one children, all others will be ignored
|
||||
-- @tparam table children A table composed of valid widgets
|
||||
function mat_list_item:set_children(children)
|
||||
if not children[2] then
|
||||
self:set_content(children[1])
|
||||
else
|
||||
self:set_prefix(children[1])
|
||||
self:set_content(children[2])
|
||||
end
|
||||
if children[3] then
|
||||
self:set_suffix(children[3])
|
||||
end
|
||||
end
|
||||
|
||||
local function new(widget)
|
||||
local ret = base.make_widget(nil, nil, {
|
||||
enable_properties = true
|
||||
})
|
||||
|
||||
gtable.crush(ret, mat_list_item, true)
|
||||
|
||||
ret._private.content = widget
|
||||
return ret
|
||||
end
|
||||
|
||||
function mat_list_item.mt:__call(...)
|
||||
return new(...)
|
||||
end
|
||||
|
||||
-- @DOC_widget_COMMON@
|
||||
|
||||
-- @DOC_object_COMMON@
|
||||
|
||||
return setmetatable(mat_list_item, mat_list_item.mt)
|
117
widget/material/slider.lua
Normal file
117
widget/material/slider.lua
Normal file
@@ -0,0 +1,117 @@
|
||||
-- Default widget requirements
|
||||
local base = require('wibox.widget.base')
|
||||
local gtable = require('gears.table')
|
||||
local setmetatable = setmetatable
|
||||
local dpi = require('beautiful').xresources.apply_dpi
|
||||
|
||||
-- Commons requirements
|
||||
local wibox = require('wibox')
|
||||
local gears = require('gears')
|
||||
local beautiful = require('beautiful')
|
||||
local mat_colors = require('theme.mat-colors')
|
||||
-- Local declarations
|
||||
|
||||
local mat_slider = {
|
||||
mt = {}
|
||||
}
|
||||
|
||||
local properties = {
|
||||
read_only = false
|
||||
}
|
||||
|
||||
function mat_slider:set_value(value)
|
||||
if self._private.value ~= value then
|
||||
self._private.value = value
|
||||
self._private.progress_bar:set_value(self._private.value)
|
||||
self._private.slider:set_value(self._private.value)
|
||||
self:emit_signal('property::value')
|
||||
-- self:emit_signal('widget::layout_changed')
|
||||
end
|
||||
end
|
||||
|
||||
function mat_slider:get_value(value)
|
||||
return self._private.value
|
||||
end
|
||||
|
||||
function mat_slider:set_read_only(value)
|
||||
if self._private.read_only ~= value then
|
||||
self._private.read_only = value
|
||||
self:emit_signal('property::read_only')
|
||||
self:emit_signal('widget::layout_changed')
|
||||
end
|
||||
end
|
||||
|
||||
function mat_slider:get_read_only(value)
|
||||
return self._private.read_only
|
||||
end
|
||||
|
||||
function mat_slider:layout(_, width, height)
|
||||
local layout = {}
|
||||
table.insert(layout, base.place_widget_at(self._private.progress_bar, 0, dpi(21), width, height - dpi(42)))
|
||||
if (not self._private.read_only) then
|
||||
table.insert(layout, base.place_widget_at(self._private.slider, 0, dpi(6), width, height - dpi(12)))
|
||||
end
|
||||
return layout
|
||||
end
|
||||
|
||||
function mat_slider:draw(_, cr, width, height)
|
||||
if (self._private.read_only) then
|
||||
self._private.slider.forced_height = 0
|
||||
end
|
||||
end
|
||||
|
||||
function mat_slider:fit(_, width, height)
|
||||
return width, height
|
||||
end
|
||||
|
||||
local function new(args)
|
||||
local ret = base.make_widget(nil, nil, {
|
||||
enable_properties = true
|
||||
})
|
||||
|
||||
gtable.crush(ret._private, args or {})
|
||||
|
||||
gtable.crush(ret, mat_slider, true)
|
||||
|
||||
ret._private.progress_bar = wibox.widget {
|
||||
max_value = 100,
|
||||
value = 25,
|
||||
forced_height = dpi(6),
|
||||
paddings = 0,
|
||||
shape = gears.shape.rounded_rect,
|
||||
background_color = beautiful.primary.hue_100,
|
||||
color = beautiful.accent.hue_400,
|
||||
widget = wibox.widget.progressbar
|
||||
}
|
||||
|
||||
ret._private.slider = wibox.widget {
|
||||
forced_height = dpi(8),
|
||||
bar_shape = gears.shape.rounded_rect,
|
||||
bar_height = 0,
|
||||
bar_color = beautiful.accent.hue_500,
|
||||
handle_color = beautiful.accent.hue_300,
|
||||
handle_shape = gears.shape.circle,
|
||||
handle_border_color = '#00000012',
|
||||
handle_border_width = dpi(3),
|
||||
value = 25,
|
||||
widget = wibox.widget.slider
|
||||
}
|
||||
|
||||
ret._private.slider:connect_signal('property::value', function()
|
||||
ret:set_value(ret._private.slider.value)
|
||||
end)
|
||||
|
||||
ret._private.read_only = false
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
function mat_slider.mt:__call(...)
|
||||
return new(...)
|
||||
end
|
||||
|
||||
-- @DOC_widget_COMMON@
|
||||
|
||||
-- @DOC_object_COMMON@
|
||||
|
||||
return setmetatable(mat_slider, mat_slider.mt)
|
Reference in New Issue
Block a user