mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-07 07:30:20 +09:00
Split improvements
This commit is contained in:
@@ -31,6 +31,7 @@ func NewBufEditPane(x, y, width, height int, b *buffer.Buffer) *EditPane {
|
||||
func NewTabPane(width, height int, b *buffer.Buffer) *TabPane {
|
||||
t := new(TabPane)
|
||||
t.Node = views.NewRoot(0, 0, width, height)
|
||||
t.Window = display.NewUIWindow(t.Node)
|
||||
|
||||
e := NewBufEditPane(0, 0, width, height, b)
|
||||
e.splitID = t.ID()
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"github.com/zyedidia/micro/cmd/micro/display"
|
||||
"github.com/zyedidia/micro/cmd/micro/screen"
|
||||
"github.com/zyedidia/micro/cmd/micro/views"
|
||||
"github.com/zyedidia/tcell"
|
||||
)
|
||||
@@ -9,12 +11,20 @@ var MainTab *TabPane
|
||||
|
||||
type TabPane struct {
|
||||
*views.Node
|
||||
display.Window
|
||||
Panes []*EditPane
|
||||
active int
|
||||
|
||||
resizing bool
|
||||
}
|
||||
|
||||
func (t *TabPane) HandleEvent(event tcell.Event) {
|
||||
switch e := event.(type) {
|
||||
case *tcell.EventResize:
|
||||
w, h := screen.Screen.Size()
|
||||
InfoBar.Resize(w, h-1)
|
||||
t.Node.Resize(w, h-1)
|
||||
t.Resize()
|
||||
case *tcell.EventMouse:
|
||||
switch e.Buttons() {
|
||||
case tcell.Button1:
|
||||
|
||||
@@ -50,6 +50,7 @@ func NewInfoWindow(b *info.InfoBuf) *InfoWindow {
|
||||
|
||||
func (i *InfoWindow) Resize(w, h int) {
|
||||
i.width = w
|
||||
i.y = h
|
||||
}
|
||||
|
||||
// func (i *InfoWindow) YesNoPrompt() (bool, bool) {
|
||||
|
||||
63
cmd/micro/display/uiwindow.go
Normal file
63
cmd/micro/display/uiwindow.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package display
|
||||
|
||||
import (
|
||||
"github.com/zyedidia/micro/cmd/micro/buffer"
|
||||
"github.com/zyedidia/micro/cmd/micro/config"
|
||||
"github.com/zyedidia/micro/cmd/micro/screen"
|
||||
"github.com/zyedidia/micro/cmd/micro/views"
|
||||
)
|
||||
|
||||
type UIWindow struct {
|
||||
root *views.Node
|
||||
}
|
||||
|
||||
func NewUIWindow(n *views.Node) *UIWindow {
|
||||
uw := new(UIWindow)
|
||||
uw.root = n
|
||||
return uw
|
||||
}
|
||||
|
||||
func (w *UIWindow) drawNode(n *views.Node) {
|
||||
cs := n.Children()
|
||||
for i, c := range cs {
|
||||
if c.IsLeaf() && c.Kind == views.STVert {
|
||||
if i != len(cs)-1 {
|
||||
for h := 0; h < c.H; h++ {
|
||||
screen.Screen.SetContent(c.X+c.W, c.Y+h, '|', nil, config.DefStyle.Reverse(true))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
w.drawNode(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (w *UIWindow) Display() {
|
||||
w.drawNode(w.root)
|
||||
}
|
||||
|
||||
func (w *UIWindow) Clear() {}
|
||||
func (w *UIWindow) Relocate() bool { return false }
|
||||
func (w *UIWindow) GetView() *View { return nil }
|
||||
func (w *UIWindow) SetView(*View) {}
|
||||
func (w *UIWindow) GetMouseLoc(vloc buffer.Loc) buffer.Loc {
|
||||
var mouseLoc func(*views.Node) buffer.Loc
|
||||
mouseLoc = func(n *views.Node) buffer.Loc {
|
||||
cs := n.Children()
|
||||
for i, c := range cs {
|
||||
if c.IsLeaf() && c.Kind == views.STVert {
|
||||
if i != len(cs)-1 {
|
||||
if vloc.X == c.X+c.W {
|
||||
return vloc
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return mouseLoc(c)
|
||||
}
|
||||
}
|
||||
return buffer.Loc{}
|
||||
}
|
||||
return mouseLoc(w.root)
|
||||
}
|
||||
func (w *UIWindow) Resize(width, height int) {}
|
||||
func (w *UIWindow) SetActive(b bool) {}
|
||||
@@ -115,7 +115,10 @@ func (i *InfoBuf) YNPrompt(prompt string, donecb func(bool, bool)) {
|
||||
|
||||
// DonePrompt finishes the current prompt and indicates whether or not it was canceled
|
||||
func (i *InfoBuf) DonePrompt(canceled bool) {
|
||||
if i.PromptCallback != nil && !i.HasYN {
|
||||
hadYN := i.HasYN
|
||||
i.HasPrompt = false
|
||||
i.HasYN = false
|
||||
if i.PromptCallback != nil && !hadYN {
|
||||
if canceled {
|
||||
i.PromptCallback("", true)
|
||||
h := i.History[i.PromptType]
|
||||
@@ -127,11 +130,9 @@ func (i *InfoBuf) DonePrompt(canceled bool) {
|
||||
h[len(h)-1] = resp
|
||||
}
|
||||
}
|
||||
if i.YNCallback != nil && i.HasYN {
|
||||
if i.YNCallback != nil && hadYN {
|
||||
i.YNCallback(i.YNResp, canceled)
|
||||
}
|
||||
i.HasPrompt = false
|
||||
i.HasYN = false
|
||||
i.PromptCallback = nil
|
||||
i.EventCallback = nil
|
||||
i.YNCallback = nil
|
||||
|
||||
@@ -209,6 +209,7 @@ func main() {
|
||||
for _, ep := range action.MainTab.Panes {
|
||||
ep.Display()
|
||||
}
|
||||
action.MainTab.Display()
|
||||
action.InfoBar.Display()
|
||||
screen.Screen.Show()
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ type View struct {
|
||||
type Node struct {
|
||||
View
|
||||
|
||||
kind SplitType
|
||||
Kind SplitType
|
||||
|
||||
parent *Node
|
||||
children []*Node
|
||||
@@ -69,6 +69,9 @@ func (n *Node) GetView() View {
|
||||
func (n *Node) SetView(v View) {
|
||||
n.X, n.Y, n.W, n.H = v.X, v.Y, v.W, v.H
|
||||
}
|
||||
func (n *Node) Children() []*Node {
|
||||
return n.children
|
||||
}
|
||||
|
||||
func (n *Node) GetNode(id uint64) *Node {
|
||||
if n.id == id && n.IsLeaf() {
|
||||
@@ -86,9 +89,9 @@ func (n *Node) GetNode(id uint64) *Node {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewNode(kind SplitType, x, y, w, h int, parent *Node, id uint64) *Node {
|
||||
func NewNode(Kind SplitType, x, y, w, h int, parent *Node, id uint64) *Node {
|
||||
n := new(Node)
|
||||
n.kind = kind
|
||||
n.Kind = Kind
|
||||
n.canResize = true
|
||||
n.propScale = true
|
||||
n.X, n.Y, n.W, n.H = x, y, w, h
|
||||
@@ -145,7 +148,7 @@ func (n *Node) ResizeSplit(size int) bool {
|
||||
ind = i
|
||||
}
|
||||
}
|
||||
if n.parent.kind == STVert {
|
||||
if n.parent.Kind == STVert {
|
||||
return n.parent.vResizeSplit(ind, size)
|
||||
}
|
||||
return n.parent.hResizeSplit(ind, size)
|
||||
@@ -282,10 +285,10 @@ func (n *Node) HSplit(bottom bool) uint64 {
|
||||
if !n.IsLeaf() {
|
||||
return 0
|
||||
}
|
||||
if n.kind == STUndef {
|
||||
n.kind = STVert
|
||||
if n.Kind == STUndef {
|
||||
n.Kind = STVert
|
||||
}
|
||||
if n.kind == STVert {
|
||||
if n.Kind == STVert {
|
||||
return n.vHSplit(0, bottom)
|
||||
}
|
||||
return n.hHSplit(bottom)
|
||||
@@ -295,32 +298,41 @@ func (n *Node) VSplit(right bool) uint64 {
|
||||
if !n.IsLeaf() {
|
||||
return 0
|
||||
}
|
||||
if n.kind == STUndef {
|
||||
n.kind = STHoriz
|
||||
if n.Kind == STUndef {
|
||||
n.Kind = STHoriz
|
||||
}
|
||||
if n.kind == STVert {
|
||||
if n.Kind == STVert {
|
||||
return n.vVSplit(right)
|
||||
}
|
||||
return n.hVSplit(0, right)
|
||||
}
|
||||
|
||||
func (n *Node) Resize(w, h int) {
|
||||
propW, propH := float64(w)/float64(n.W), float64(h)/float64(n.H)
|
||||
x, y := n.X, n.Y
|
||||
for _, c := range n.children {
|
||||
cW := int(float64(c.W) * propW)
|
||||
cH := int(float64(c.H) * propH)
|
||||
c.Resize(cW, cH)
|
||||
c.X = x
|
||||
c.Y = y
|
||||
if n.kind == STHoriz {
|
||||
x += cW
|
||||
} else {
|
||||
y += cH
|
||||
if n.IsLeaf() {
|
||||
n.W, n.H = w, h
|
||||
} else {
|
||||
propW, propH := float64(w)/float64(n.W), float64(h)/float64(n.H)
|
||||
log.Println(w, h, n.W, n.H, propW, propH)
|
||||
x, y := n.X, n.Y
|
||||
for i, c := range n.children {
|
||||
cW := int(float64(c.W) * propW)
|
||||
// if c.IsLeaf() && i != len(n.children)-1 {
|
||||
// cW++
|
||||
// }
|
||||
log.Println("WIDTH:", cW, c.W)
|
||||
cH := int(float64(c.H) * propH)
|
||||
c.Resize(cW, cH)
|
||||
c.X = x
|
||||
c.Y = y
|
||||
if n.Kind == STHoriz {
|
||||
x += cW
|
||||
} else {
|
||||
y += cH
|
||||
}
|
||||
}
|
||||
n.alignSize()
|
||||
n.W, n.H = w, h
|
||||
}
|
||||
n.alignSize()
|
||||
n.W, n.H = w, h
|
||||
}
|
||||
|
||||
func (n *Node) alignSize() {
|
||||
@@ -329,21 +341,22 @@ func (n *Node) alignSize() {
|
||||
}
|
||||
|
||||
totw, toth := 0, 0
|
||||
for _, c := range n.children {
|
||||
if n.kind == STHoriz {
|
||||
for i, c := range n.children {
|
||||
if n.Kind == STHoriz {
|
||||
if i != len(n.children)-1 {
|
||||
c.Resize(c.W-1, c.H)
|
||||
}
|
||||
totw += c.W
|
||||
} else {
|
||||
toth += c.H
|
||||
}
|
||||
}
|
||||
if n.kind == STVert && toth != n.H {
|
||||
if n.Kind == STVert && toth != n.H {
|
||||
last := n.children[len(n.children)-1]
|
||||
last.Resize(last.W, last.H+n.H-toth)
|
||||
log.Println("bad height")
|
||||
} else if n.kind == STHoriz && totw != n.W {
|
||||
} else if n.Kind == STHoriz && totw != n.W {
|
||||
last := n.children[len(n.children)-1]
|
||||
last.Resize(last.W+n.W-totw, last.H)
|
||||
log.Println("bad width")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,7 +368,7 @@ func (n *Node) String() string {
|
||||
var strf func(n *Node, ident int) string
|
||||
strf = func(n *Node, ident int) string {
|
||||
marker := "|"
|
||||
if n.kind == STHoriz {
|
||||
if n.Kind == STHoriz {
|
||||
marker = "-"
|
||||
}
|
||||
str := fmt.Sprint(strings.Repeat("\t", ident), marker, n.View, n.id)
|
||||
|
||||
Reference in New Issue
Block a user