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