Skip to content

Commit 4a9408f

Browse files
committed
Thumbnail: clamp border to within margins
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.
1 parent d5a17bc commit 4a9408f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/Thumbnail.moon

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
class Thumbnail extends BarAccent
22

3-
rightMargin = settings['thumbnail-right-margin']
4-
leftMargin = settings['thumbnail-left-margin']
53
bottomMargin = settings['thumbnail-bottom-margin']
64
borderExpansion = settings['thumbnail-border-expansion']
5+
rightMargin = settings['thumbnail-right-margin'] + borderExpansion
6+
leftMargin = settings['thumbnail-left-margin'] + borderExpansion
77

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

@@ -28,9 +28,9 @@ class Thumbnail extends BarAccent
2828
reconfigure: =>
2929
super!
3030
rightMargin = settings['thumbnail-right-margin']
31-
leftMargin = settings['thumbnail-left-margin']
32-
bottomMargin = settings['thumbnail-bottom-margin']
3331
borderExpansion = settings['thumbnail-border-expansion']
32+
leftMargin = settings['thumbnail-left-margin'] + borderExpansion
33+
bottomMargin = settings['thumbnail-bottom-margin'] + borderExpansion
3434

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

@@ -48,9 +48,12 @@ class Thumbnail extends BarAccent
4848

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

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

53-
width = (@thumbfast.width / Window.osdScale) + (2 * borderExpansion)
53+
thumbX = clamp(@lastX, leftMargin + (scaledWidth / 2), Window.w - rightMargin - (scaledWidth / 2))
54+
@line[2] = [[%d,%d]]\format thumbX, Window.h - (bottomMargin - borderExpansion)
55+
56+
width = scaledWidth + (2 * borderExpansion)
5457
height = (@thumbfast.height / Window.osdScale) + (2 * borderExpansion)
5558
@line[4] = [[m 0 0 l %d 0 %d %d 0 %d]]\format width, width, height, height
5659

0 commit comments

Comments
 (0)