Skip to content

Commit 6ea6fb2

Browse files
committed
fixup
1 parent 954e366 commit 6ea6fb2

File tree

4 files changed

+40
-29
lines changed

4 files changed

+40
-29
lines changed

editor/guiwidget.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,14 @@ func (w *Workspace) handleRPCGuiwidgetview(updates []interface{}) {
155155
switch g.mime {
156156
case "text/plain":
157157
baseFont := g.s.ws.font
158-
g.font = initFontNew(
159-
baseFont.fontNew.Family(),
160-
float64(g.height*baseFont.height)*0.8,
161-
0,
162-
0,
158+
g.setFont(
159+
// Set font adjusted to widgets height
160+
initFontNew(
161+
baseFont.fontNew.Family(),
162+
float64(baseFont.height*g.height)*0.7,
163+
0,
164+
0,
165+
),
163166
)
164167
default:
165168
}

editor/imetooltip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (i *IMETooltip) updateVirtualCursorPos() {
149149
i.cursorVisualPos = int(x)
150150
return
151151
}
152-
x += chunk.width
152+
x += float64(chunk.scale) * i.font.cellwidth
153153
k++
154154
}
155155
}

editor/tooltip.go

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
type 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

editor/window.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,7 +2741,6 @@ func (g *Guiwidget) drawText(x, y, width, height float64, p *gui.QPainter, f fun
27412741
}
27422742

27432743
for _, chunk := range g.text {
2744-
fmt.Println(chunk)
27452744

27462745
fg := chunk.hl.fg()
27472746
bg := chunk.hl.bg()
@@ -2762,7 +2761,7 @@ func (g *Guiwidget) drawText(x, y, width, height float64, p *gui.QPainter, f fun
27622761
core.NewQRectF4(
27632762
x,
27642763
y,
2765-
chunk.width,
2764+
float64(chunk.scale)*g.font.cellwidth,
27662765
height,
27672766
),
27682767
bg.QColor(),
@@ -2796,14 +2795,14 @@ func (g *Guiwidget) drawText(x, y, width, height float64, p *gui.QPainter, f fun
27962795
core.NewQRectF4(
27972796
x,
27982797
y+height-underlinePos,
2799-
chunk.width,
2798+
float64(chunk.scale)*g.font.cellwidth,
28002799
underlinePos,
28012800
),
28022801
fg.QColor(),
28032802
)
28042803
}
28052804

2806-
x += chunk.width
2805+
x += float64(chunk.scale) * g.font.cellwidth
28072806
}
28082807
}
28092808
}

0 commit comments

Comments
 (0)