mirror of
https://github.com/akiyosi/goneovim.git
synced 2025-08-06 10:55:02 +02:00
Changed UI and implementation of ext-message
This commit is contained in:
parent
e339a3a8e0
commit
f2be0588b3
6 changed files with 1104 additions and 693 deletions
|
@ -151,9 +151,9 @@ func (i *IMETooltip) updateVirtualCursorPos() {
|
|||
i.cursorVisualPos = int(x)
|
||||
return
|
||||
}
|
||||
x += chunk.width
|
||||
k++
|
||||
}
|
||||
x += chunk.width
|
||||
}
|
||||
|
||||
i.cursorVisualPos = int(x)
|
||||
|
@ -201,23 +201,25 @@ func (i *IMETooltip) parsePreeditString(preeditStr string) {
|
|||
if preeditStr != "" {
|
||||
r := []rune(preeditStr)
|
||||
|
||||
letterSpace := float64(i.s.ws.font.letterSpace)
|
||||
|
||||
if length > 0 {
|
||||
if start > 0 {
|
||||
i.updateText(preeditHl, string(r[:start]), i.s.ws.font.letterSpace, i.getFont().qfont)
|
||||
i.updateText(preeditHl, string(r[:start]), letterSpace, i.getFont().qfont)
|
||||
if start+length < len(r) {
|
||||
i.updateText(currConvHl, string(r[start:start+length]), i.s.ws.font.letterSpace, i.getFont().qfont)
|
||||
i.updateText(preeditHl, string(r[start+length:]), i.s.ws.font.letterSpace, i.getFont().qfont)
|
||||
i.updateText(currConvHl, string(r[start:start+length]), letterSpace, i.getFont().qfont)
|
||||
i.updateText(preeditHl, string(r[start+length:]), letterSpace, i.getFont().qfont)
|
||||
} else {
|
||||
i.updateText(currConvHl, string(r[start:]), i.s.ws.font.letterSpace, i.getFont().qfont)
|
||||
i.updateText(currConvHl, string(r[start:]), letterSpace, i.getFont().qfont)
|
||||
}
|
||||
} else if start == 0 && length < len(r) {
|
||||
i.updateText(currConvHl, string(r[0:length]), i.s.ws.font.letterSpace, i.getFont().qfont)
|
||||
i.updateText(preeditHl, string(r[length:]), i.s.ws.font.letterSpace, i.getFont().qfont)
|
||||
i.updateText(currConvHl, string(r[0:length]), letterSpace, i.getFont().qfont)
|
||||
i.updateText(preeditHl, string(r[length:]), letterSpace, i.getFont().qfont)
|
||||
} else {
|
||||
i.updateText(preeditHl, preeditStr, i.s.ws.font.letterSpace, i.getFont().qfont)
|
||||
i.updateText(preeditHl, preeditStr, letterSpace, i.getFont().qfont)
|
||||
}
|
||||
} else {
|
||||
i.updateText(preeditHl, preeditStr, i.s.ws.font.letterSpace, i.getFont().qfont)
|
||||
i.updateText(preeditHl, preeditStr, letterSpace, i.getFont().qfont)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
1016
editor/message.go
1016
editor/message.go
File diff suppressed because it is too large
Load diff
222
editor/message2.go
Normal file
222
editor/message2.go
Normal file
|
@ -0,0 +1,222 @@
|
|||
package editor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/akiyosi/goneovim/util"
|
||||
)
|
||||
|
||||
const (
|
||||
MARGINOFMESSAGEPOS = 10
|
||||
)
|
||||
|
||||
type Messages struct {
|
||||
ws *Workspace
|
||||
|
||||
msgs []*Message
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
Tooltip
|
||||
|
||||
m *Messages
|
||||
|
||||
kind string
|
||||
replaceLast bool
|
||||
|
||||
expires int
|
||||
isDrag bool
|
||||
isExpand bool
|
||||
}
|
||||
|
||||
func initMessages() *Messages {
|
||||
return &Messages{
|
||||
msgs: []*Message{},
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Messages) msgClear() {
|
||||
for _, msg := range m.msgs {
|
||||
msg.Hide()
|
||||
}
|
||||
|
||||
m.msgs = []*Message{}
|
||||
}
|
||||
|
||||
func (m *Messages) msgShow(args []interface{}, bulkmsg bool) {
|
||||
var msg *Message
|
||||
for _, arg := range args {
|
||||
|
||||
// kind
|
||||
var ok bool
|
||||
var kind string
|
||||
kind, ok = arg.([]interface{})[0].(string)
|
||||
|
||||
// replaceLast
|
||||
var replaceLast bool
|
||||
if len(arg.([]interface{})) > 2 {
|
||||
replaceLast, ok = arg.([]interface{})[2].(bool)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if replaceLast {
|
||||
// m.msgs[len(m.msgs)-2].Hide()
|
||||
|
||||
for _, mm := range m.msgs {
|
||||
mm.Hide()
|
||||
}
|
||||
}
|
||||
|
||||
maximumWidth := m.ws.screen.widget.Width() / 2
|
||||
fixedWidth := false
|
||||
if bulkmsg {
|
||||
maximumWidth = int(float64(m.ws.screen.widget.Width()) * 0.85)
|
||||
fixedWidth = true
|
||||
}
|
||||
|
||||
var emmitNewMsg bool = true
|
||||
if len(m.msgs) == 0 || replaceLast {
|
||||
msg = m.newMessage(maximumWidth, fixedWidth)
|
||||
} else if len(m.msgs) > 0 && kind != "" && m.msgs[len(m.msgs)-1].kind != kind && !bulkmsg {
|
||||
msg = m.newMessage(maximumWidth, fixedWidth)
|
||||
} else {
|
||||
msg = m.msgs[len(m.msgs)-1]
|
||||
emmitNewMsg = false
|
||||
}
|
||||
|
||||
// content
|
||||
for _, c := range arg.([]interface{})[1].([]interface{}) {
|
||||
tuple, ok := c.([]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
attrId, textChunk := parseContent(tuple)
|
||||
hl, ok := msg.m.ws.screen.hlAttrDef[attrId]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Println(textChunk)
|
||||
if !emmitNewMsg {
|
||||
msg.updateText(
|
||||
hl,
|
||||
"\n",
|
||||
0,
|
||||
msg.font.qfont,
|
||||
)
|
||||
}
|
||||
|
||||
msg.updateText(
|
||||
hl,
|
||||
textChunk,
|
||||
float64(m.ws.screen.font.letterSpace),
|
||||
resolveFontFallback(
|
||||
m.ws.screen.font,
|
||||
m.ws.screen.fallbackfonts,
|
||||
textChunk,
|
||||
).qfont,
|
||||
)
|
||||
}
|
||||
|
||||
msg.kind = kind
|
||||
msg.replaceLast = replaceLast
|
||||
msg.update()
|
||||
|
||||
msg.emmit()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (m *Messages) msgHistoryShow(entries []interface{}) {
|
||||
for _, entrie := range entries {
|
||||
m.msgShow((entrie.([]interface{})[0]).([]interface{}), true)
|
||||
}
|
||||
}
|
||||
|
||||
func parseContent(tuple []interface{}) (attrId int, textChunk string) {
|
||||
if len(tuple) != 2 {
|
||||
return
|
||||
}
|
||||
|
||||
attrId = util.ReflectToInt(tuple[0])
|
||||
|
||||
var ok bool
|
||||
textChunk, ok = tuple[1].(string)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (m *Messages) newMessage(maximumWidth int, fixedWidth bool) *Message {
|
||||
msg := NewMessage(m.ws.screen.widget, 0)
|
||||
msg.s = m.ws.screen
|
||||
msg.setPadding(20, 10)
|
||||
msg.setRadius(14, 10)
|
||||
msg.maximumWidth = maximumWidth
|
||||
msg.pathWidth = 2
|
||||
msg.setBgColor(m.ws.background)
|
||||
msg.setFont(m.ws.font)
|
||||
msg.fixedWidth = fixedWidth
|
||||
msg.ConnectPaintEvent(msg.paint)
|
||||
|
||||
m.msgs = append(m.msgs, msg)
|
||||
msg.m = m
|
||||
|
||||
return msg
|
||||
}
|
||||
|
||||
func (msg *Message) emmit() {
|
||||
// TODO: stacked positioning
|
||||
stackedMsgHeight := 0
|
||||
for _, mm := range msg.m.msgs {
|
||||
if !mm.IsVisible() {
|
||||
continue
|
||||
}
|
||||
if mm == msg {
|
||||
break
|
||||
}
|
||||
stackedMsgHeight += mm.Height() + MARGINOFMESSAGEPOS
|
||||
}
|
||||
msg.show()
|
||||
msg.Move2(
|
||||
msg.m.ws.screen.widget.Width()-msg.Width()-MARGINOFMESSAGEPOS,
|
||||
stackedMsgHeight,
|
||||
)
|
||||
msg.SetGraphicsEffect(util.DropShadow(-1, 16, 130, 180))
|
||||
}
|
||||
|
||||
func (m *Messages) updateFont() {
|
||||
|
||||
var newMsgs []*Message
|
||||
|
||||
for _, msg := range m.msgs {
|
||||
oldText := msg.text
|
||||
var newText []*ColorStr
|
||||
msg.text = newText
|
||||
|
||||
for _, colorStr := range oldText {
|
||||
hl := colorStr.hl
|
||||
text := colorStr.str
|
||||
msg.updateText(
|
||||
hl,
|
||||
text,
|
||||
float64(m.ws.screen.font.letterSpace),
|
||||
resolveFontFallback(
|
||||
m.ws.screen.font,
|
||||
m.ws.screen.fallbackfonts,
|
||||
text,
|
||||
).qfont,
|
||||
)
|
||||
msg.update()
|
||||
newMsgs = append(newMsgs, msg)
|
||||
}
|
||||
}
|
||||
|
||||
m.msgs = newMsgs
|
||||
}
|
|
@ -2,6 +2,8 @@ package editor
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"github.com/akiyosi/qt/core"
|
||||
"github.com/akiyosi/qt/gui"
|
||||
|
@ -9,9 +11,10 @@ import (
|
|||
)
|
||||
|
||||
type ColorStr struct {
|
||||
hl *Highlight
|
||||
str string
|
||||
width float64
|
||||
hl *Highlight
|
||||
str string
|
||||
width float64
|
||||
cellwidth float64
|
||||
}
|
||||
|
||||
// Tooltip is the tooltip
|
||||
|
@ -23,35 +26,35 @@ type Tooltip struct {
|
|||
font *Font
|
||||
fallbackfonts []*Font
|
||||
widthSlice []float64
|
||||
}
|
||||
|
||||
func resolveMetricsInFontFallback(font *Font, fallbackfonts []*Font, char string) float64 {
|
||||
if len(fallbackfonts) == 0 {
|
||||
return font.fontMetrics.HorizontalAdvance(char, -1)
|
||||
}
|
||||
textWidth float64
|
||||
msgHeight float64
|
||||
background *RGBA
|
||||
|
||||
hasGlyph := font.hasGlyph(char)
|
||||
if hasGlyph {
|
||||
return font.fontMetrics.HorizontalAdvance(char, -1)
|
||||
} else {
|
||||
for _, ff := range fallbackfonts {
|
||||
hasGlyph = ff.hasGlyph(char)
|
||||
if hasGlyph {
|
||||
return ff.fontMetrics.HorizontalAdvance(char, -1)
|
||||
}
|
||||
}
|
||||
}
|
||||
pathWidth float64
|
||||
xPadding float64
|
||||
yPadding float64
|
||||
xRadius float64
|
||||
yRadius float64
|
||||
|
||||
return font.fontMetrics.HorizontalAdvance(char, -1)
|
||||
maximumWidth int
|
||||
fixedWidth bool
|
||||
|
||||
backgrond *RGBA
|
||||
}
|
||||
|
||||
func (t *Tooltip) drawContent(p *gui.QPainter, getFont func() *Font) {
|
||||
|
||||
if t.text == nil {
|
||||
return
|
||||
}
|
||||
|
||||
height := float64(t.s.tooltip.font.height) * 1.1
|
||||
lineHeight := float64(t.s.tooltip.font.lineHeight)
|
||||
screenWidth := t.s.widget.Width()
|
||||
if t.maximumWidth == 0 {
|
||||
t.maximumWidth = screenWidth
|
||||
}
|
||||
height := float64(t.font.height) * 1.1
|
||||
lineHeight := float64(t.font.lineHeight)
|
||||
if height > float64(lineHeight) {
|
||||
height = float64(lineHeight)
|
||||
}
|
||||
|
@ -59,6 +62,82 @@ func (t *Tooltip) drawContent(p *gui.QPainter, getFont func() *Font) {
|
|||
var x float64
|
||||
var y float64 = float64(lineHeight-height) / 2
|
||||
|
||||
color := t.background
|
||||
if color == nil {
|
||||
if t.s != nil {
|
||||
color = t.s.ws.background
|
||||
}
|
||||
}
|
||||
|
||||
if t.xRadius == 0 && t.yRadius == 0 {
|
||||
p.FillRect4(
|
||||
core.NewQRectF4(
|
||||
0,
|
||||
0,
|
||||
t.textWidth+t.xPadding*2.0,
|
||||
t.msgHeight+t.yPadding*2.0,
|
||||
),
|
||||
color.QColor(),
|
||||
)
|
||||
|
||||
} else {
|
||||
|
||||
outlineColor := warpColor(color, -20)
|
||||
p.SetPen(
|
||||
gui.NewQPen4(
|
||||
gui.NewQBrush3(
|
||||
gui.NewQColor3(
|
||||
outlineColor.R,
|
||||
outlineColor.G,
|
||||
outlineColor.B,
|
||||
255,
|
||||
),
|
||||
core.Qt__BrushStyle(1),
|
||||
),
|
||||
t.pathWidth,
|
||||
core.Qt__SolidLine,
|
||||
core.Qt__FlatCap,
|
||||
core.Qt__MiterJoin,
|
||||
),
|
||||
)
|
||||
|
||||
width := t.textWidth + t.xPadding*2.0
|
||||
if width > float64(t.maximumWidth)-t.pathWidth*2 {
|
||||
width = float64(t.maximumWidth) - t.pathWidth*2
|
||||
}
|
||||
if t.fixedWidth {
|
||||
width = float64(t.maximumWidth) - t.pathWidth*2
|
||||
}
|
||||
|
||||
path := gui.NewQPainterPath()
|
||||
path.AddRoundedRect(
|
||||
core.NewQRectF4(
|
||||
t.pathWidth,
|
||||
t.pathWidth,
|
||||
width,
|
||||
t.msgHeight+t.yPadding*2.0,
|
||||
),
|
||||
t.xRadius,
|
||||
t.yRadius,
|
||||
core.Qt__AbsoluteSize,
|
||||
)
|
||||
p.DrawPath(path)
|
||||
|
||||
p.FillPath(
|
||||
path,
|
||||
gui.NewQBrush3(
|
||||
gui.NewQColor3(
|
||||
color.R,
|
||||
color.G,
|
||||
color.B,
|
||||
255,
|
||||
),
|
||||
core.Qt__BrushStyle(1),
|
||||
),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
for _, chunk := range t.text {
|
||||
|
||||
fg := chunk.hl.fg()
|
||||
|
@ -77,66 +156,88 @@ func (t *Tooltip) drawContent(p *gui.QPainter, getFont func() *Font) {
|
|||
underdashed := chunk.hl.underdashed
|
||||
strikethrough := chunk.hl.strikethrough
|
||||
|
||||
// set foreground color
|
||||
p.SetPen2(fg.QColor())
|
||||
|
||||
r := []rune(chunk.str)
|
||||
for _, rr := range r {
|
||||
p.SetFont(resolveFontFallback(getFont(), t.fallbackfonts, string(rr)).qfont)
|
||||
font := p.Font()
|
||||
|
||||
// draw background
|
||||
p.FillRect4(
|
||||
core.NewQRectF4(
|
||||
x,
|
||||
y,
|
||||
chunk.width,
|
||||
height,
|
||||
),
|
||||
bg.QColor(),
|
||||
)
|
||||
|
||||
// set italic, bold
|
||||
font.SetItalic(italic)
|
||||
font.SetBold(bold)
|
||||
|
||||
p.DrawText(
|
||||
core.NewQPointF3(
|
||||
float64(x),
|
||||
float64(shift),
|
||||
),
|
||||
string(rr),
|
||||
)
|
||||
|
||||
//
|
||||
// set text decoration
|
||||
//
|
||||
|
||||
if strikethrough {
|
||||
drawStrikethrough(p, t.font, sp.QColor(), 0, x, x+chunk.width, 0, 0)
|
||||
for i, s := range strings.Split(chunk.str, "\n") {
|
||||
if i > 0 {
|
||||
x = 0
|
||||
y += lineHeight
|
||||
}
|
||||
|
||||
if underline {
|
||||
drawUnderline(p, t.font, sp.QColor(), 0, x, x+chunk.width, 0, 0)
|
||||
}
|
||||
// set foreground color
|
||||
p.SetPen2(fg.QColor())
|
||||
|
||||
if undercurl {
|
||||
drawUndercurl(p, t.font, sp.QColor(), 0, x, x+chunk.width, 0, 0)
|
||||
}
|
||||
r := []rune(s)
|
||||
|
||||
if underdouble {
|
||||
drawUnderdouble(p, t.font, sp.QColor(), 0, x, x+chunk.width, 0, 0)
|
||||
}
|
||||
for _, rr := range r {
|
||||
|
||||
if underdotted {
|
||||
drawUnderdotted(p, t.font, sp.QColor(), 0, x, x+chunk.width, 0, 0)
|
||||
}
|
||||
if x+t.xPadding*2 >= float64(t.maximumWidth) {
|
||||
x = 0
|
||||
y += lineHeight
|
||||
}
|
||||
|
||||
if underdashed {
|
||||
drawUnderdashed(p, t.font, sp.QColor(), 0, x, x+chunk.width, 0, 0)
|
||||
}
|
||||
p.SetFont(resolveFontFallback(getFont(), t.fallbackfonts, string(rr)).qfont)
|
||||
font := p.Font()
|
||||
cwidth := gui.NewQFontMetricsF(t.font.qfont).HorizontalAdvance(string(rr), -1)
|
||||
w := chunk.cellwidth
|
||||
for {
|
||||
if cwidth <= w {
|
||||
break
|
||||
}
|
||||
w += chunk.cellwidth
|
||||
}
|
||||
|
||||
x += chunk.width
|
||||
// draw background
|
||||
p.FillRect4(
|
||||
core.NewQRectF4(
|
||||
x+t.xPadding,
|
||||
y+t.yPadding,
|
||||
w,
|
||||
height,
|
||||
),
|
||||
bg.QColor(),
|
||||
)
|
||||
|
||||
// set italic, bold
|
||||
font.SetItalic(italic)
|
||||
font.SetBold(bold)
|
||||
|
||||
p.DrawText(
|
||||
core.NewQPointF3(
|
||||
x+t.xPadding,
|
||||
y+float64(shift)+t.yPadding,
|
||||
),
|
||||
string(rr),
|
||||
)
|
||||
|
||||
//
|
||||
// set text decoration
|
||||
//
|
||||
|
||||
if strikethrough {
|
||||
drawStrikethrough(p, t.font, sp.QColor(), 0, x, x+chunk.width, 0, 0)
|
||||
}
|
||||
|
||||
if underline {
|
||||
drawUnderline(p, t.font, sp.QColor(), 0, x, x+chunk.width, 0, 0)
|
||||
}
|
||||
|
||||
if undercurl {
|
||||
drawUndercurl(p, t.font, sp.QColor(), 0, x, x+chunk.width, 0, 0)
|
||||
}
|
||||
|
||||
if underdouble {
|
||||
drawUnderdouble(p, t.font, sp.QColor(), 0, x, x+chunk.width, 0, 0)
|
||||
}
|
||||
|
||||
if underdotted {
|
||||
drawUnderdotted(p, t.font, sp.QColor(), 0, x, x+chunk.width, 0, 0)
|
||||
}
|
||||
|
||||
if underdashed {
|
||||
drawUnderdashed(p, t.font, sp.QColor(), 0, x, x+chunk.width, 0, 0)
|
||||
}
|
||||
|
||||
x += w
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -145,6 +246,24 @@ func (t *Tooltip) getFont() *Font {
|
|||
return t.font
|
||||
}
|
||||
|
||||
func (t *Tooltip) setBgColor(color *RGBA) {
|
||||
t.background = color
|
||||
}
|
||||
|
||||
func (t *Tooltip) setPadding(xv, yv float64) {
|
||||
t.xPadding = xv
|
||||
t.yPadding = yv
|
||||
}
|
||||
|
||||
func (t *Tooltip) setRadius(xr, yr float64) {
|
||||
t.xRadius = xr
|
||||
t.yRadius = yr
|
||||
}
|
||||
|
||||
func (t *Tooltip) setQpainterFont(p *gui.QPainter) {
|
||||
p.SetFont(t.font.qfont)
|
||||
}
|
||||
|
||||
func (t *Tooltip) paint(event *gui.QPaintEvent) {
|
||||
p := gui.NewQPainter2(t)
|
||||
|
||||
|
@ -153,10 +272,6 @@ func (t *Tooltip) paint(event *gui.QPaintEvent) {
|
|||
p.DestroyQPainter()
|
||||
}
|
||||
|
||||
func (t *Tooltip) move(x int, y int) {
|
||||
t.Move(core.NewQPoint2(x, y))
|
||||
}
|
||||
|
||||
func (t *Tooltip) setFont(font *Font) {
|
||||
t.font = font
|
||||
}
|
||||
|
@ -166,74 +281,68 @@ func (t *Tooltip) clearText() {
|
|||
t.text = newText
|
||||
}
|
||||
|
||||
func (t *Tooltip) updateText(hl *Highlight, str string, letterspace int, font *gui.QFont) {
|
||||
// func (t *Tooltip) updateText(hl *Highlight, str string, letterspace float64, font *gui.QFont) {
|
||||
func (t *Tooltip) updateText(hl *Highlight, str string, letterspace float64, font *gui.QFont) {
|
||||
if t.font == nil {
|
||||
return
|
||||
}
|
||||
|
||||
fontMetrics := gui.NewQFontMetricsF(font)
|
||||
cellwidth := fontMetrics.HorizontalAdvance("w", -1) + float64(letterspace)
|
||||
cellwidth := fontMetrics.HorizontalAdvance("w", -1) + letterspace
|
||||
|
||||
// rune text
|
||||
r := []rune(str)
|
||||
|
||||
var preStrWidth float64
|
||||
var width float64
|
||||
var maxWidth float64
|
||||
var widthList []float64
|
||||
var buffer bytes.Buffer
|
||||
for k, rr := range r {
|
||||
for _, rr := range r {
|
||||
buffer.WriteString(string(rr))
|
||||
|
||||
// detect char width based cell width
|
||||
w := cellwidth
|
||||
cwidth := fontMetrics.HorizontalAdvance(string(rr), -1)
|
||||
|
||||
if string(rr) == "\n" {
|
||||
widthList = append(widthList, width)
|
||||
width = 0
|
||||
continue
|
||||
}
|
||||
|
||||
for {
|
||||
// cwidth := fontMetrics.HorizontalAdvance(string(rr), -1)
|
||||
cwidth := resolveMetricsInFontFallback(t.font, t.fallbackfonts, string(rr))
|
||||
if cwidth <= w {
|
||||
break
|
||||
}
|
||||
w += cellwidth
|
||||
}
|
||||
if preStrWidth == 0 {
|
||||
preStrWidth = w
|
||||
}
|
||||
|
||||
if preStrWidth == w {
|
||||
buffer.WriteString(string(rr))
|
||||
if k < len(r)-1 {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if buffer.Len() != 0 {
|
||||
|
||||
t.text = append(t.text, &ColorStr{
|
||||
hl: hl,
|
||||
str: buffer.String(),
|
||||
width: preStrWidth,
|
||||
})
|
||||
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
||||
preStrWidth = w
|
||||
}
|
||||
|
||||
width += w
|
||||
}
|
||||
widthList = append(widthList, width)
|
||||
|
||||
for _, v := range widthList {
|
||||
if maxWidth < v {
|
||||
maxWidth = v
|
||||
}
|
||||
}
|
||||
|
||||
t.text = append(t.text, &ColorStr{
|
||||
hl: hl,
|
||||
str: buffer.String(),
|
||||
width: maxWidth,
|
||||
cellwidth: cellwidth,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (t *Tooltip) show() {
|
||||
if t.s != nil {
|
||||
t.SetAutoFillBackground(true)
|
||||
p := gui.NewQPalette()
|
||||
p.SetColor2(gui.QPalette__Background, t.s.ws.background.QColor())
|
||||
t.SetPalette(p)
|
||||
}
|
||||
// if t.s != nil {
|
||||
// t.SetAutoFillBackground(true)
|
||||
// p := gui.NewQPalette()
|
||||
// p.SetColor2(gui.QPalette__Background, t.s.ws.background.QColor())
|
||||
// t.SetPalette(p)
|
||||
// }
|
||||
|
||||
t.Show()
|
||||
t.Raise()
|
||||
|
@ -241,21 +350,78 @@ func (t *Tooltip) show() {
|
|||
|
||||
func (t *Tooltip) update() {
|
||||
// detect width
|
||||
var tooltipWidth float64
|
||||
var textWidth float64
|
||||
var msgHeight float64
|
||||
screenWidth := t.s.widget.Width()
|
||||
screenHeight := t.s.widget.Height()
|
||||
|
||||
if t.maximumWidth == 0 {
|
||||
t.maximumWidth = screenWidth
|
||||
}
|
||||
|
||||
if len(t.text) == 0 {
|
||||
return
|
||||
}
|
||||
for _, chunk := range t.text {
|
||||
r := []rune(chunk.str)
|
||||
for _, _ = range r {
|
||||
tooltipWidth += chunk.width
|
||||
var width float64
|
||||
var height int
|
||||
for i, chunk := range t.text {
|
||||
if i == 0 {
|
||||
msgHeight += float64(t.font.lineHeight)
|
||||
}
|
||||
|
||||
width += chunk.width
|
||||
for j, s := range strings.Split(chunk.str, "\n") {
|
||||
if j > 0 {
|
||||
msgHeight += float64(t.font.lineHeight)
|
||||
width = 0
|
||||
}
|
||||
r := []rune(s)
|
||||
for k, _ := range r {
|
||||
if width > float64(t.maximumWidth)-t.xPadding*2-t.pathWidth*2 {
|
||||
height = int(math.Floor(width)) / int(math.Ceil((float64(t.maximumWidth) - t.xPadding*2 - t.pathWidth*2)))
|
||||
residue := int(math.Floor(width)) % int(math.Ceil((float64(t.maximumWidth) - t.xPadding*2 - t.pathWidth*2)))
|
||||
if height > 0 && residue == 0 {
|
||||
height -= 1
|
||||
}
|
||||
} else if textWidth < width {
|
||||
textWidth = width
|
||||
}
|
||||
|
||||
if k == len(r)-1 && textWidth < width {
|
||||
textWidth = width
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if height > 0 {
|
||||
msgHeight += float64(height * t.font.lineHeight)
|
||||
}
|
||||
|
||||
t.textWidth = textWidth
|
||||
t.msgHeight = msgHeight
|
||||
|
||||
var tooltipwidth float64
|
||||
if t.fixedWidth {
|
||||
tooltipwidth = float64(t.maximumWidth) + t.pathWidth*2
|
||||
} else {
|
||||
tooltipwidth = t.textWidth + t.xPadding*2.0 + t.pathWidth*2
|
||||
if tooltipwidth > float64(t.maximumWidth) {
|
||||
tooltipwidth = float64(t.maximumWidth) + t.pathWidth*2
|
||||
}
|
||||
}
|
||||
|
||||
tooltipheight := t.msgHeight + t.yPadding*2.0 + t.pathWidth*2
|
||||
if tooltipheight > float64(screenHeight) {
|
||||
tooltipheight = float64(screenHeight)
|
||||
}
|
||||
|
||||
// update widget size
|
||||
t.SetFixedSize2(
|
||||
int(tooltipWidth),
|
||||
t.font.lineHeight,
|
||||
int(tooltipwidth),
|
||||
int(tooltipheight),
|
||||
)
|
||||
|
||||
t.Update()
|
||||
|
|
|
@ -3614,6 +3614,13 @@ func (w *Window) setUIParent() {
|
|||
}
|
||||
|
||||
w.s.ws.cursor.raise()
|
||||
if w.s.ws.messages != nil {
|
||||
for _, msg := range w.s.ws.messages.msgs {
|
||||
if msg.IsVisible() {
|
||||
msg.emmit()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Window) show() {
|
||||
|
|
|
@ -28,7 +28,7 @@ type neovimSignal struct {
|
|||
_ func() `signal:"redrawSignal"`
|
||||
_ func() `signal:"guiSignal"`
|
||||
|
||||
_ func() `signal:"messageSignal"`
|
||||
_ func() `signal:"messagesSignal"`
|
||||
|
||||
_ func() `signal:"lazyLoadSignal"`
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ type Workspace struct {
|
|||
palette *Palette
|
||||
popup *PopupMenu
|
||||
cmdline *Cmdline
|
||||
message *Message
|
||||
messages *Messages
|
||||
minimap *MiniMap
|
||||
fontdialog *widgets.QFontDialog
|
||||
guiUpdates chan []interface{}
|
||||
|
@ -174,23 +174,20 @@ func (ws *Workspace) initUI() {
|
|||
ws.popup.widget.Hide()
|
||||
}
|
||||
|
||||
// messages
|
||||
// messagess
|
||||
if editor.config.Editor.ExtMessages {
|
||||
ws.message = initMessage()
|
||||
ws.message.ws = ws
|
||||
ws.message.widget.SetParent(ws.widget)
|
||||
ws.signal.ConnectMessageSignal(func() {
|
||||
ws.message.update()
|
||||
})
|
||||
ws.messages = initMessages()
|
||||
ws.messages.ws = ws
|
||||
// ws.messages.widget.SetParent(ws.widget)
|
||||
// ws.signal.ConnectMessagesSignal(func() {
|
||||
// ws.messages.update()
|
||||
// })
|
||||
}
|
||||
|
||||
if ws.tabline != nil {
|
||||
ws.isDrawTabline = editor.config.Tabline.Visible && editor.config.Editor.ExtTabline
|
||||
ws.tabline.connectUI()
|
||||
}
|
||||
if ws.message != nil {
|
||||
ws.message.connectUI()
|
||||
}
|
||||
|
||||
// workspace widget, layouts
|
||||
layout := widgets.NewQVBoxLayout()
|
||||
|
@ -827,9 +824,9 @@ func (ws *Workspace) updateSize() (windowWidth, windowHeight, cols, rows int) {
|
|||
if ws.palette != nil {
|
||||
ws.palette.resize()
|
||||
}
|
||||
if ws.message != nil {
|
||||
ws.message.resize()
|
||||
}
|
||||
// if ws.messages != nil {
|
||||
// ws.messages.resize()
|
||||
// }
|
||||
|
||||
windowWidth = marginWidth + sideWidth + scrollbarWidth + minimapWidth + ws.screen.width
|
||||
windowHeight = marginHeight + titlebarHeight + tablineHeight + ws.screen.height
|
||||
|
@ -1059,16 +1056,24 @@ func (ws *Workspace) handleRedraw(updates [][]interface{}) {
|
|||
case "cmdline_block_append":
|
||||
case "cmdline_block_hide":
|
||||
|
||||
// Message/Dialog Events
|
||||
// // -- deprecated events
|
||||
// case "wildmenu_show":
|
||||
// ws.cmdline.wildmenuShow(args)
|
||||
// case "wildmenu_select":
|
||||
// ws.cmdline.wildmenuSelect(args)
|
||||
// case "wildmenu_hide":
|
||||
// ws.cmdline.wildmenuHide()
|
||||
|
||||
// messages/Dialog Events
|
||||
case "msg_show":
|
||||
ws.msgShow(args)
|
||||
ws.messages.msgShow(args, false)
|
||||
case "msg_clear":
|
||||
ws.msgClear()
|
||||
ws.messages.msgClear()
|
||||
case "msg_showmode":
|
||||
case "msg_showcmd":
|
||||
case "msg_ruler":
|
||||
case "msg_history_show":
|
||||
ws.msgHistoryShow(args)
|
||||
ws.messages.msgHistoryShow(args)
|
||||
default:
|
||||
}
|
||||
|
||||
|
@ -1339,9 +1344,10 @@ func (ws *Workspace) updateWorkspaceColor() {
|
|||
ws.popup.setColor()
|
||||
}
|
||||
|
||||
if ws.message != nil {
|
||||
ws.message.setColor()
|
||||
}
|
||||
// TODO
|
||||
// if ws.messages != nil {
|
||||
// ws.messages.setColor()
|
||||
// }
|
||||
|
||||
// ws.screen.setColor()
|
||||
|
||||
|
@ -1411,7 +1417,7 @@ func (ws *Workspace) optionSet(args []interface{}) {
|
|||
// case "ext_hlstate":
|
||||
// case "ext_linegrid":
|
||||
// case "ext_multigrid":
|
||||
// case "ext_messages":
|
||||
// case "ext_messagess":
|
||||
// case "ext_popupmenu":
|
||||
// case "ext_tabline":
|
||||
// case "ext_termcolors":
|
||||
|
@ -1426,23 +1432,23 @@ func (ws *Workspace) optionSet(args []interface{}) {
|
|||
}
|
||||
}
|
||||
|
||||
func (ws *Workspace) msgHistoryShow(args []interface{}) {
|
||||
if ws.message != nil {
|
||||
ws.message.msgHistoryShow(args)
|
||||
}
|
||||
}
|
||||
|
||||
func (ws *Workspace) msgClear() {
|
||||
if ws.message != nil {
|
||||
ws.message.msgClear()
|
||||
}
|
||||
}
|
||||
|
||||
func (ws *Workspace) msgShow(args []interface{}) {
|
||||
if ws.message != nil {
|
||||
ws.message.msgShow(args)
|
||||
}
|
||||
}
|
||||
// func (ws *Workspace) msgHistoryShow(args []interface{}) {
|
||||
// if ws.message != nil {
|
||||
// ws.message.msgHistoryShow(args)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func (ws *Workspace) msgClear() {
|
||||
// if ws.message != nil {
|
||||
// ws.message.msgClear()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func (ws *Workspace) msgShow(args []interface{}) {
|
||||
// if ws.message != nil {
|
||||
// ws.message.msgShow(args)
|
||||
// }
|
||||
// }
|
||||
|
||||
func (ws *Workspace) cmdlineFunctionHide(args []interface{}) {
|
||||
if ws.cmdline != nil {
|
||||
|
@ -2056,9 +2062,12 @@ func (ws *Workspace) letterSpacing(arg interface{}) {
|
|||
if ws.popup != nil {
|
||||
ws.popup.updateFont(font)
|
||||
}
|
||||
if ws.message != nil {
|
||||
ws.message.updateFont()
|
||||
}
|
||||
|
||||
// TODO
|
||||
// if ws.messages != nil {
|
||||
// ws.messages.updateFont()
|
||||
// }
|
||||
|
||||
ws.screen.tooltip.setFont(font)
|
||||
ws.cursor.updateFont(nil, font, fallbackfonts)
|
||||
}
|
||||
|
@ -2118,9 +2127,11 @@ func (ws *Workspace) guiFont(args string) {
|
|||
if ws.popup != nil {
|
||||
ws.popup.updateFont(font)
|
||||
}
|
||||
if ws.message != nil {
|
||||
ws.message.updateFont()
|
||||
}
|
||||
|
||||
// // TODO
|
||||
// if ws.messages != nil {
|
||||
// ws.messages.updateFont()
|
||||
// }
|
||||
|
||||
ws.screen.tooltip.setFont(font)
|
||||
ws.screen.tooltip.fallbackfonts = fallbackfonts
|
||||
|
@ -2135,6 +2146,9 @@ func (ws *Workspace) guiFont(args string) {
|
|||
if ws.tabline != nil {
|
||||
ws.tabline.updateFont()
|
||||
}
|
||||
if ws.messages != nil {
|
||||
ws.messages.updateFont()
|
||||
}
|
||||
}
|
||||
|
||||
func (ws *Workspace) guiFontWide(args string) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue