2018-09-16 21:48:17 +09:00
|
|
|
package editor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/therecipe/qt/widgets"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ScrollBar is
|
|
|
|
type ScrollBar struct {
|
|
|
|
ws *Workspace
|
|
|
|
widget *widgets.QWidget
|
|
|
|
thumb *widgets.QWidget
|
|
|
|
pos int
|
|
|
|
height int
|
|
|
|
}
|
|
|
|
|
|
|
|
func newScrollBar() *ScrollBar {
|
|
|
|
widget := widgets.NewQWidget(nil, 0)
|
|
|
|
widget.SetContentsMargins(0, 0, 0, 0)
|
2018-09-22 07:44:44 +09:00
|
|
|
widget.SetFixedWidth(10)
|
2018-09-16 21:48:17 +09:00
|
|
|
thumb := widgets.NewQWidget(widget, 0)
|
|
|
|
thumb.SetFixedWidth(5)
|
|
|
|
|
|
|
|
scrollBar := &ScrollBar{
|
|
|
|
widget: widget,
|
|
|
|
thumb: thumb,
|
|
|
|
}
|
|
|
|
scrollBar.widget.Hide()
|
|
|
|
|
|
|
|
return scrollBar
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ScrollBar) update() {
|
|
|
|
top := s.ws.screen.scrollRegion[0]
|
|
|
|
bot := s.ws.screen.scrollRegion[1]
|
|
|
|
if top == 0 && bot == 0 {
|
2018-09-17 15:31:34 +09:00
|
|
|
top = 0
|
|
|
|
bot = s.ws.rows - 1
|
|
|
|
}
|
|
|
|
relativeCursorY := int(float64(s.ws.cursor.y) / float64(s.ws.font.lineHeight))
|
|
|
|
if s.ws.maxLine == 0 {
|
|
|
|
s.ws.nvim.Eval("line('$')", &s.ws.maxLine)
|
2018-09-16 21:48:17 +09:00
|
|
|
}
|
|
|
|
if s.ws.maxLine > bot-top {
|
|
|
|
s.height = int(float64(bot-top) / float64(s.ws.maxLine) * float64(s.ws.screen.widget.Height()))
|
2018-09-22 07:44:44 +09:00
|
|
|
if s.height < 20 {
|
|
|
|
s.height = 20
|
|
|
|
}
|
2018-09-16 21:48:17 +09:00
|
|
|
s.thumb.SetFixedHeight(s.height)
|
2018-09-21 22:04:24 +09:00
|
|
|
s.pos = int(float64(s.ws.curLine-relativeCursorY) / float64(s.ws.maxLine) * float64(s.ws.screen.widget.Height()))
|
2018-09-17 15:31:34 +09:00
|
|
|
s.thumb.Move2(0, s.pos)
|
2018-09-16 21:48:17 +09:00
|
|
|
s.widget.Show()
|
|
|
|
} else {
|
|
|
|
s.widget.Hide()
|
|
|
|
}
|
|
|
|
}
|