Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
akiyosi committed Jan 6, 2023
1 parent e080f47 commit 8657fba
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
13 changes: 8 additions & 5 deletions editor/guiwidget.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ func (w *Workspace) handleRPCGuiwidgetview(updates []interface{}) {
switch g.mime {
case "text/plain":
baseFont := g.s.ws.font
g.font = initFontNew(
baseFont.fontNew.Family(),
float64(g.height*baseFont.height)*0.8,
0,
0,
g.setFont(
// Set font adjusted to widgets height
initFontNew(
baseFont.fontNew.Family(),
float64(baseFont.height*g.height)*0.7,
0,
0,
),
)
default:
}
Expand Down
2 changes: 1 addition & 1 deletion editor/imetooltip.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (i *IMETooltip) updateVirtualCursorPos() {
i.cursorVisualPos = int(x)
return
}
x += chunk.width
x += float64(chunk.scale) * i.font.cellwidth
k++
}
}
Expand Down
29 changes: 18 additions & 11 deletions editor/tooltip.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type ColorStr struct {
hl *Highlight
str string
width float64
scale int
}

// Tooltip is the tooltip
Expand Down Expand Up @@ -64,7 +64,7 @@ func (t *Tooltip) drawContent(p *gui.QPainter, f func(*gui.QPainter)) {
core.NewQRectF4(
x,
y,
chunk.width,
float64(chunk.scale)*t.font.cellwidth,
height,
),
bg.QColor(),
Expand Down Expand Up @@ -98,14 +98,14 @@ func (t *Tooltip) drawContent(p *gui.QPainter, f func(*gui.QPainter)) {
core.NewQRectF4(
x,
y+height-underlinePos,
chunk.width,
float64(chunk.scale)*t.font.cellwidth,
underlinePos,
),
fg.QColor(),
)
}

x += chunk.width
x += float64(chunk.scale) * t.font.cellwidth
}
}
}
Expand Down Expand Up @@ -151,21 +151,25 @@ func (t *Tooltip) updateText(hl *Highlight, str string) {
// rune text
r := []rune(str)

var preScale int
var preStrWidth float64
var buffer bytes.Buffer
for k, rr := range r {

// detect char width based cell width
w := font.cellwidth
scale := 1
for {
cwidth := font.fontMetrics.HorizontalAdvance(string(rr), -1)
if cwidth <= w {
break
}
w += font.cellwidth
scale++
}
if preStrWidth == 0 {
preStrWidth = w
preScale = scale
}

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

t.text = append(t.text, &ColorStr{
hl: hl,
str: buffer.String(),
width: preStrWidth,
hl: hl,
str: buffer.String(),
// width: preStrWidth,
scale: preScale,
})

buffer.Reset()
buffer.WriteString(string(rr))

if preStrWidth != w && k == len(r)-1 {
t.text = append(t.text, &ColorStr{
hl: hl,
str: buffer.String(),
width: w,
hl: hl,
str: buffer.String(),
// width: w,
scale: scale,
})
}

preStrWidth = w
preScale = scale
}

}
Expand All @@ -221,7 +228,7 @@ func (t *Tooltip) update() {
for _, chunk := range t.text {
r := []rune(chunk.str)
for _, _ = range r {
tooltipWidth += chunk.width
tooltipWidth += float64(chunk.scale) * t.font.cellwidth
}
}

Expand Down
7 changes: 3 additions & 4 deletions editor/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -2783,7 +2783,6 @@ func (g *Guiwidget) drawText(x, y, width, height float64, p *gui.QPainter, f fun
}

for _, chunk := range g.text {
fmt.Println(chunk)

fg := chunk.hl.fg()
bg := chunk.hl.bg()
Expand All @@ -2804,7 +2803,7 @@ func (g *Guiwidget) drawText(x, y, width, height float64, p *gui.QPainter, f fun
core.NewQRectF4(
x,
y,
chunk.width,
float64(chunk.scale)*g.font.cellwidth,
height,
),
bg.QColor(),
Expand Down Expand Up @@ -2838,14 +2837,14 @@ func (g *Guiwidget) drawText(x, y, width, height float64, p *gui.QPainter, f fun
core.NewQRectF4(
x,
y+height-underlinePos,
chunk.width,
float64(chunk.scale)*g.font.cellwidth,
underlinePos,
),
fg.QColor(),
)
}

x += chunk.width
x += float64(chunk.scale) * g.font.cellwidth
}
}
}
Expand Down

0 comments on commit 8657fba

Please sign in to comment.