@@ -11,7 +11,7 @@ import (
1111type ColorStr struct {
1212 hl * Highlight
1313 str string
14- width float64
14+ scale int
1515}
1616
1717// Tooltip is the tooltip
@@ -59,15 +59,17 @@ func (t *Tooltip) drawContent(p *gui.QPainter, f func(*gui.QPainter)) {
5959 r := []rune (chunk .str )
6060 for _ , rr := range r {
6161 // draw background
62- p .FillRect4 (
63- core .NewQRectF4 (
64- x ,
65- y ,
66- chunk .width ,
67- height ,
68- ),
69- bg .QColor (),
70- )
62+ if ! bg .equals (t .s .ws .background ) {
63+ p .FillRect4 (
64+ core .NewQRectF4 (
65+ x ,
66+ y ,
67+ float64 (chunk .scale )* t .font .cellwidth ,
68+ height ,
69+ ),
70+ bg .QColor (),
71+ )
72+ }
7173
7274 // set italic
7375 if italic {
@@ -96,14 +98,14 @@ func (t *Tooltip) drawContent(p *gui.QPainter, f func(*gui.QPainter)) {
9698 core .NewQRectF4 (
9799 x ,
98100 y + height - underlinePos ,
99- chunk .width ,
101+ float64 ( chunk .scale ) * t . font . cellwidth ,
100102 underlinePos ,
101103 ),
102104 fg .QColor (),
103105 )
104106 }
105107
106- x += chunk .width
108+ x += float64 ( chunk .scale ) * t . font . cellwidth
107109 }
108110 }
109111}
@@ -149,21 +151,25 @@ func (t *Tooltip) updateText(hl *Highlight, str string) {
149151 // rune text
150152 r := []rune (str )
151153
154+ var preScale int
152155 var preStrWidth float64
153156 var buffer bytes.Buffer
154157 for k , rr := range r {
155158
156159 // detect char width based cell width
157160 w := font .cellwidth
161+ scale := 1
158162 for {
159163 cwidth := font .fontMetrics .HorizontalAdvance (string (rr ), - 1 )
160164 if cwidth <= w {
161165 break
162166 }
163167 w += font .cellwidth
168+ scale ++
164169 }
165170 if preStrWidth == 0 {
166171 preStrWidth = w
172+ preScale = scale
167173 }
168174
169175 if preStrWidth == w {
@@ -176,23 +182,26 @@ func (t *Tooltip) updateText(hl *Highlight, str string) {
176182 if buffer .Len () != 0 {
177183
178184 t .text = append (t .text , & ColorStr {
179- hl : hl ,
180- str : buffer .String (),
181- width : preStrWidth ,
185+ hl : hl ,
186+ str : buffer .String (),
187+ // width: preStrWidth,
188+ scale : preScale ,
182189 })
183190
184191 buffer .Reset ()
185192 buffer .WriteString (string (rr ))
186193
187194 if preStrWidth != w && k == len (r )- 1 {
188195 t .text = append (t .text , & ColorStr {
189- hl : hl ,
190- str : buffer .String (),
191- width : w ,
196+ hl : hl ,
197+ str : buffer .String (),
198+ // width: w,
199+ scale : scale ,
192200 })
193201 }
194202
195203 preStrWidth = w
204+ preScale = scale
196205 }
197206
198207 }
@@ -219,7 +228,7 @@ func (t *Tooltip) update() {
219228 for _ , chunk := range t .text {
220229 r := []rune (chunk .str )
221230 for _ , _ = range r {
222- tooltipWidth += chunk .width
231+ tooltipWidth += float64 ( chunk .scale ) * t . font . cellwidth
223232 }
224233 }
225234
0 commit comments