Skip to content

Commit

Permalink
Thumbnail: clamp border to within margins
Browse files Browse the repository at this point in the history
This changes the logic so that the border expansion is incorporated
into the margins. This will have interesting results if
thumbnail-border-expansion is set to a negative value, and that's fine
by me (the correct way to hide it is to make it fully transparent).
Any border style added has to be manually accounted for using the
margin settings.
  • Loading branch information
torque committed Feb 7, 2025
1 parent d5a17bc commit 4a9408f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Thumbnail.moon
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Thumbnail extends BarAccent

rightMargin = settings['thumbnail-right-margin']
leftMargin = settings['thumbnail-left-margin']
bottomMargin = settings['thumbnail-bottom-margin']
borderExpansion = settings['thumbnail-border-expansion']
rightMargin = settings['thumbnail-right-margin'] + borderExpansion
leftMargin = settings['thumbnail-left-margin'] + borderExpansion

boxStyle = [[)\an2%s%s\p1}]]

Expand All @@ -28,9 +28,9 @@ class Thumbnail extends BarAccent
reconfigure: =>
super!
rightMargin = settings['thumbnail-right-margin']
leftMargin = settings['thumbnail-left-margin']
bottomMargin = settings['thumbnail-bottom-margin']
borderExpansion = settings['thumbnail-border-expansion']
leftMargin = settings['thumbnail-left-margin'] + borderExpansion
bottomMargin = settings['thumbnail-bottom-margin'] + borderExpansion

@line[3] = boxStyle\format settings['default-style'], settings['thumbnail-border-style']

Expand All @@ -48,9 +48,12 @@ class Thumbnail extends BarAccent

hoverTime = mp.get_property_number( 'duration', 0 ) * Mouse.x / Window.w

@line[2] = [[%d,%d]]\format @lastX, Window.h - (bottomMargin - borderExpansion)
scaledWidth = @thumbfast.width / Window.osdScale

width = (@thumbfast.width / Window.osdScale) + (2 * borderExpansion)
thumbX = clamp(@lastX, leftMargin + (scaledWidth / 2), Window.w - rightMargin - (scaledWidth / 2))
@line[2] = [[%d,%d]]\format thumbX, Window.h - (bottomMargin - borderExpansion)

width = scaledWidth + (2 * borderExpansion)
height = (@thumbfast.height / Window.osdScale) + (2 * borderExpansion)
@line[4] = [[m 0 0 l %d 0 %d %d 0 %d]]\format width, width, height, height

Expand Down

0 comments on commit 4a9408f

Please sign in to comment.