mirror of
https://github.com/felixangell/phi.git
synced 2024-09-11 15:55:25 +03:00
clicking in a buffer now moves the cursor to the selected line; set cursor to ibeam
This commit is contained in:
parent
5a2f71e9ad
commit
2012c04a10
@ -146,6 +146,11 @@ func NewBuffer(conf *cfg.TomlConfig, buffOpts BufferConfig, parent *View, index
|
||||
config = cfg.NewDefaultConfig()
|
||||
}
|
||||
|
||||
curs := sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_IBEAM)
|
||||
|
||||
// TODO do this only if we are hovering over the buffer
|
||||
sdl.SetCursor(curs)
|
||||
|
||||
buff := &Buffer{
|
||||
index: index,
|
||||
parent: parent,
|
||||
@ -639,7 +644,7 @@ func (b *Buffer) moveToEndOfLine() {
|
||||
|
||||
// TODO make this scroll auto magically.
|
||||
func (b *Buffer) gotoLine(num int64) {
|
||||
distToMove := float64(num - int64(b.curs.y))
|
||||
distToMove := float64((num - 1) - int64(b.curs.y))
|
||||
for i := int64(0); i < int64(math.Abs(distToMove)); i++ {
|
||||
if distToMove < 0 {
|
||||
b.moveUp()
|
||||
@ -1063,6 +1068,17 @@ var ldx, ldy = 0, 0
|
||||
var ySpeed = 1
|
||||
var last = time.Now()
|
||||
|
||||
func (b *Buffer) processLeftClick() {
|
||||
// here we set the cursor y position
|
||||
// based off the click location
|
||||
yPos := strife.MouseCoords()[1]
|
||||
|
||||
yPosToLine := ((yPos / (last_h + pad)) + 1) + b.cam.y
|
||||
|
||||
fmt.Println(yPos, " line ", yPosToLine)
|
||||
b.gotoLine(int64(yPosToLine))
|
||||
}
|
||||
|
||||
func (b *Buffer) OnUpdate() bool {
|
||||
if "animations on" == "true" {
|
||||
if b.cam.y < b.cam.dy {
|
||||
@ -1075,6 +1091,12 @@ func (b *Buffer) OnUpdate() bool {
|
||||
b.cam.x = b.cam.dx
|
||||
b.cam.y = b.cam.dy
|
||||
}
|
||||
|
||||
switch strife.MouseButtonsState() {
|
||||
case strife.LeftMouseButton:
|
||||
b.processLeftClick()
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
67
gui/debug_pane.go
Normal file
67
gui/debug_pane.go
Normal file
@ -0,0 +1,67 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"github.com/felixangell/strife"
|
||||
)
|
||||
|
||||
type debugPane struct {
|
||||
fpsGraph *lineGraph
|
||||
}
|
||||
|
||||
type lineGraph struct {
|
||||
yAxisLabel string
|
||||
xAxisLabel string
|
||||
|
||||
xValues []float64
|
||||
yValues []float64
|
||||
}
|
||||
|
||||
func newLineGraph(xAxis, yAxis string) *lineGraph {
|
||||
return &lineGraph{
|
||||
xAxis,
|
||||
yAxis,
|
||||
[]float64{},
|
||||
[]float64{1, 2, 3, 4, 5, 6, 7},
|
||||
}
|
||||
}
|
||||
|
||||
func (l *lineGraph) plot(x, y float64) {
|
||||
l.xValues = append(l.xValues, x)
|
||||
l.yValues = append(l.yValues, y)
|
||||
}
|
||||
|
||||
func max(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (l *lineGraph) render(ctx *strife.Renderer, x, y int) {
|
||||
graphWidth, graphHeight := 256, 256
|
||||
|
||||
ctx.SetColor(strife.RGBA(0, 0, 0, 255))
|
||||
ctx.Rect(x, y, graphWidth, graphHeight, strife.Fill)
|
||||
|
||||
// render last ten values
|
||||
// xSnip := l.xValues[len(l.xValues)-10:]
|
||||
ySnip := l.yValues[max(len(l.yValues)-256, 0):]
|
||||
|
||||
size := graphHeight / len(ySnip)
|
||||
|
||||
for idx, yItem := range ySnip {
|
||||
ctx.SetColor(strife.RGB(255, 0, 255))
|
||||
ctx.Rect(x+(idx*size), y+(graphHeight-(int(yItem)*size)), 5, 5, strife.Fill)
|
||||
}
|
||||
}
|
||||
|
||||
var pane = &debugPane{
|
||||
newLineGraph("time", "framerate"),
|
||||
}
|
||||
|
||||
func renderDebugPane(ctx *strife.Renderer, x, y int) {
|
||||
ctx.SetColor(strife.HexRGB(0xff00ff))
|
||||
{
|
||||
pane.fpsGraph.render(ctx, x, y)
|
||||
}
|
||||
}
|
@ -316,8 +316,10 @@ func (n *View) OnRender(ctx *strife.Renderer) {
|
||||
|
||||
if DEBUG_MODE {
|
||||
ctx.SetColor(strife.HexRGB(0xff00ff))
|
||||
mPos := strife.MouseState()
|
||||
ctx.Rect(mPos[0], mPos[1], 16, 24, strife.Line)
|
||||
mPos := strife.MouseCoords()
|
||||
ctx.Rect(mPos[0], mPos[1], 16, 16, strife.Line)
|
||||
|
||||
renderDebugPane(ctx, 10, 10)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user