diff --git a/editor/guiwidget.go b/editor/guiwidget.go index 0aaf2631..20f0f360 100644 --- a/editor/guiwidget.go +++ b/editor/guiwidget.go @@ -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: } diff --git a/editor/imetooltip.go b/editor/imetooltip.go index f1c9ee02..826da521 100644 --- a/editor/imetooltip.go +++ b/editor/imetooltip.go @@ -149,7 +149,7 @@ func (i *IMETooltip) updateVirtualCursorPos() { i.cursorVisualPos = int(x) return } - x += chunk.width + x += float64(chunk.scale) * i.font.cellwidth k++ } } diff --git a/editor/tooltip.go b/editor/tooltip.go index 4c2538d3..86e07d0f 100644 --- a/editor/tooltip.go +++ b/editor/tooltip.go @@ -11,7 +11,7 @@ import ( type ColorStr struct { hl *Highlight str string - width float64 + scale int } // Tooltip is the tooltip @@ -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(), @@ -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 } } } @@ -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 { @@ -178,9 +182,10 @@ 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() @@ -188,13 +193,15 @@ func (t *Tooltip) updateText(hl *Highlight, str string) { 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 } } @@ -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 } } diff --git a/editor/window.go b/editor/window.go index dc1bab12..85304f2c 100644 --- a/editor/window.go +++ b/editor/window.go @@ -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() @@ -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(), @@ -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 } } }