Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imagebox: add a "cover" fit policy #3811

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/wibox/widget/imagebox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ function imagebox:draw(ctx, cr, width, height)
aspects[aspect] = 1
elseif policy[aspect] == "auto" then
aspects[aspect] = math.min(width / w, height / h)
elseif policy[aspect] == "cover" then
aspects[aspect] = math.max(width / w, height / h)
end
end

Expand Down Expand Up @@ -519,6 +521,7 @@ end
-- @propertyvalue "auto" Honor the `resize` variable and preserve the aspect ratio.
-- @propertyvalue "none" Do not resize at all.
-- @propertyvalue "fit" Resize to the widget width.
-- @propertyvalue "cover" Resize to fill widget and preserve the aspect ratio.
-- @propemits true false
-- @see vertical_fit_policy
-- @see resize
Expand All @@ -534,6 +537,7 @@ end
-- @propertyvalue "auto" Honor the `resize` variable and preserve the aspect ratio.
-- @propertyvalue "none" Do not resize at all.
-- @propertyvalue "fit" Resize to the widget height.
-- @propertyvalue "cover" Resize to fill widget and preserve the aspect ratio.
-- @propemits true false
-- @see horizontal_fit_policy
-- @see resize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ parent:add(l)
l:add_widget_at(wibox.widget.textbox('horizontal_fit_policy = "auto"'), 1, 1)
l:add_widget_at(wibox.widget.textbox('horizontal_fit_policy = "none"'), 2, 1)
l:add_widget_at(wibox.widget.textbox('horizontal_fit_policy = "fit"'), 3, 1)
l:add_widget_at(wibox.widget.textbox('imagebox size'), 4, 1)
l:add_widget_at(wibox.widget.textbox('vertical_fit_policy = "cover"'), 4, 1)
l:add_widget_at(wibox.widget.textbox('imagebox size'), 5, 1)

for i,size in ipairs({16, 32, 64}) do
l:add_widget_at(build_ib(size, "auto"), 1, i + 1)
l:add_widget_at(build_ib(size, "none"), 2, i + 1)
l:add_widget_at(build_ib(size, "fit" ), 3, i + 1)
l:add_widget_at(cell_centered_widget(wibox.widget.textbox(size..'x'..size)), 4, i + 1)
l:add_widget_at(build_ib(size, "cover"), 4, i + 1)
l:add_widget_at(cell_centered_widget(wibox.widget.textbox(size..'x'..size)), 5, i + 1)
end

--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
6 changes: 4 additions & 2 deletions tests/examples/wibox/widget/imagebox/vertical_fit_policy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ parent:add(l)
l:add_widget_at(wibox.widget.textbox('vertical_fit_policy = "auto"'), 1, 1)
l:add_widget_at(wibox.widget.textbox('versical_fit_policy = "none"'), 2, 1)
l:add_widget_at(wibox.widget.textbox('vertical_fit_policy = "fit"'), 3, 1)
l:add_widget_at(wibox.widget.textbox('imagebox size'), 4, 1)
l:add_widget_at(wibox.widget.textbox('vertical_fit_policy = "cover"'), 4, 1)
l:add_widget_at(wibox.widget.textbox('imagebox size'), 5, 1)

for i,size in ipairs({16, 32, 64}) do
l:add_widget_at(build_ib(size, "auto"), 1, i + 1)
l:add_widget_at(build_ib(size, "none"), 2, i + 1)
l:add_widget_at(build_ib(size, "fit" ), 3, i + 1)
l:add_widget_at(cell_centered_widget(wibox.widget.textbox(size..'x'..size)), 4, i + 1)
l:add_widget_at(build_ib(size, "cover"), 4, i + 1)
l:add_widget_at(cell_centered_widget(wibox.widget.textbox(size..'x'..size)), 5, i + 1)
end

--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80