mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-21 22:54:11 +08:00
fix(tray): Set tray width based on actual unread count text width
This commit is contained in:
parent
27ae261d1b
commit
f66c24918f
1 changed files with 12 additions and 4 deletions
|
@ -72,23 +72,31 @@ CanvasUtils =
|
||||||
|
|
||||||
return DragCanvas
|
return DragCanvas
|
||||||
|
|
||||||
|
measureTextInCanvas: (text, font) ->
|
||||||
|
canvas = document.createElement('canvas')
|
||||||
|
context = canvas.getContext('2d')
|
||||||
|
context.font = font
|
||||||
|
return Math.ceil(context.measureText(text).width)
|
||||||
|
|
||||||
canvasWithSystemTrayIconAndText: (img, text) ->
|
canvasWithSystemTrayIconAndText: (img, text) ->
|
||||||
canvas = SystemTrayCanvas
|
canvas = SystemTrayCanvas
|
||||||
w = img.width
|
w = img.width
|
||||||
h = img.height
|
h = img.height
|
||||||
# Rough estimate of extra width to hold text
|
font = '14px Nylas-Pro, sans-serif'
|
||||||
canvas.width = w + (10 * text.length)
|
|
||||||
|
textWidth = if text.length > 0 then CanvasUtils.measureTextInCanvas(text, font) + 2 else 0
|
||||||
|
canvas.width = w + textWidth
|
||||||
canvas.height = h
|
canvas.height = h
|
||||||
|
|
||||||
context = canvas.getContext('2d')
|
context = canvas.getContext('2d')
|
||||||
context.font = '14px Nylas-Pro, sans-serif'
|
context.font = font
|
||||||
context.fillStyle = 'black'
|
context.fillStyle = 'black'
|
||||||
context.textAlign = 'start'
|
context.textAlign = 'start'
|
||||||
context.textBaseline = 'middle'
|
context.textBaseline = 'middle'
|
||||||
|
|
||||||
context.drawImage(img, 0, 0)
|
context.drawImage(img, 0, 0)
|
||||||
# Place after img, vertically aligned
|
# Place after img, vertically aligned
|
||||||
context.fillText(text, w + 2, h / 2)
|
context.fillText(text, w, h / 2)
|
||||||
return canvas
|
return canvas
|
||||||
|
|
||||||
module.exports = CanvasUtils
|
module.exports = CanvasUtils
|
||||||
|
|
Loading…
Reference in a new issue