Skip to content

Commit ba218ff

Browse files
committed
fixup
1 parent 2645d37 commit ba218ff

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
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: 18 additions & 11 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
@@ -64,7 +64,7 @@ func (t *Tooltip) drawContent(p *gui.QPainter, f func(*gui.QPainter)) {
6464
core.NewQRectF4(
6565
x,
6666
y,
67-
chunk.width,
67+
float64(chunk.scale)*t.font.cellwidth,
6868
height,
6969
),
7070
bg.QColor(),
@@ -98,14 +98,14 @@ func (t *Tooltip) drawContent(p *gui.QPainter, f func(*gui.QPainter)) {
9898
core.NewQRectF4(
9999
x,
100100
y+height-underlinePos,
101-
chunk.width,
101+
float64(chunk.scale)*t.font.cellwidth,
102102
underlinePos,
103103
),
104104
fg.QColor(),
105105
)
106106
}
107107

108-
x += chunk.width
108+
x += float64(chunk.scale) * t.font.cellwidth
109109
}
110110
}
111111
}
@@ -151,21 +151,25 @@ func (t *Tooltip) updateText(hl *Highlight, str string) {
151151
// rune text
152152
r := []rune(str)
153153

154+
var preScale int
154155
var preStrWidth float64
155156
var buffer bytes.Buffer
156157
for k, rr := range r {
157158

158159
// detect char width based cell width
159160
w := font.cellwidth
161+
scale := 1
160162
for {
161163
cwidth := font.fontMetrics.HorizontalAdvance(string(rr), -1)
162164
if cwidth <= w {
163165
break
164166
}
165167
w += font.cellwidth
168+
scale++
166169
}
167170
if preStrWidth == 0 {
168171
preStrWidth = w
172+
preScale = scale
169173
}
170174

171175
if preStrWidth == w {
@@ -178,23 +182,26 @@ func (t *Tooltip) updateText(hl *Highlight, str string) {
178182
if buffer.Len() != 0 {
179183

180184
t.text = append(t.text, &ColorStr{
181-
hl: hl,
182-
str: buffer.String(),
183-
width: preStrWidth,
185+
hl: hl,
186+
str: buffer.String(),
187+
// width: preStrWidth,
188+
scale: preScale,
184189
})
185190

186191
buffer.Reset()
187192
buffer.WriteString(string(rr))
188193

189194
if preStrWidth != w && k == len(r)-1 {
190195
t.text = append(t.text, &ColorStr{
191-
hl: hl,
192-
str: buffer.String(),
193-
width: w,
196+
hl: hl,
197+
str: buffer.String(),
198+
// width: w,
199+
scale: scale,
194200
})
195201
}
196202

197203
preStrWidth = w
204+
preScale = scale
198205
}
199206

200207
}
@@ -221,7 +228,7 @@ func (t *Tooltip) update() {
221228
for _, chunk := range t.text {
222229
r := []rune(chunk.str)
223230
for _, _ = range r {
224-
tooltipWidth += chunk.width
231+
tooltipWidth += float64(chunk.scale) * t.font.cellwidth
225232
}
226233
}
227234

editor/window.go

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

27852785
for _, chunk := range g.text {
2786-
fmt.Println(chunk)
27872786

27882787
fg := chunk.hl.fg()
27892788
bg := chunk.hl.bg()
@@ -2804,7 +2803,7 @@ func (g *Guiwidget) drawText(x, y, width, height float64, p *gui.QPainter, f fun
28042803
core.NewQRectF4(
28052804
x,
28062805
y,
2807-
chunk.width,
2806+
float64(chunk.scale)*g.font.cellwidth,
28082807
height,
28092808
),
28102809
bg.QColor(),
@@ -2838,14 +2837,14 @@ func (g *Guiwidget) drawText(x, y, width, height float64, p *gui.QPainter, f fun
28382837
core.NewQRectF4(
28392838
x,
28402839
y+height-underlinePos,
2841-
chunk.width,
2840+
float64(chunk.scale)*g.font.cellwidth,
28422841
underlinePos,
28432842
),
28442843
fg.QColor(),
28452844
)
28462845
}
28472846

2848-
x += chunk.width
2847+
x += float64(chunk.scale) * g.font.cellwidth
28492848
}
28502849
}
28512850
}

0 commit comments

Comments
 (0)