mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 14:47:16 +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 {
|
func NewTabPane(width, height int, b *buffer.Buffer) *TabPane {
|
||||||
t := new(TabPane)
|
t := new(TabPane)
|
||||||
t.Node = views.NewRoot(0, 0, width, height)
|
t.Node = views.NewRoot(0, 0, width, height)
|
||||||
|
t.Window = display.NewUIWindow(t.Node)
|
||||||
|
|
||||||
e := NewBufEditPane(0, 0, width, height, b)
|
e := NewBufEditPane(0, 0, width, height, b)
|
||||||
e.splitID = t.ID()
|
e.splitID = t.ID()
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package action
|
package action
|
||||||
|
|
||||||
import (
|
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/micro/cmd/micro/views"
|
||||||
"github.com/zyedidia/tcell"
|
"github.com/zyedidia/tcell"
|
||||||
)
|
)
|
||||||
@@ -9,12 +11,20 @@ var MainTab *TabPane
|
|||||||
|
|
||||||
type TabPane struct {
|
type TabPane struct {
|
||||||
*views.Node
|
*views.Node
|
||||||
|
display.Window
|
||||||
Panes []*EditPane
|
Panes []*EditPane
|
||||||
active int
|
active int
|
||||||
|
|
||||||
|
resizing bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TabPane) HandleEvent(event tcell.Event) {
|
func (t *TabPane) HandleEvent(event tcell.Event) {
|
||||||
switch e := event.(type) {
|
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:
|
case *tcell.EventMouse:
|
||||||
switch e.Buttons() {
|
switch e.Buttons() {
|
||||||
case tcell.Button1:
|
case tcell.Button1:
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ func NewInfoWindow(b *info.InfoBuf) *InfoWindow {
|
|||||||
|
|
||||||
func (i *InfoWindow) Resize(w, h int) {
|
func (i *InfoWindow) Resize(w, h int) {
|
||||||
i.width = w
|
i.width = w
|
||||||
|
i.y = h
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (i *InfoWindow) YesNoPrompt() (bool, bool) {
|
// 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
|
// DonePrompt finishes the current prompt and indicates whether or not it was canceled
|
||||||
func (i *InfoBuf) DonePrompt(canceled bool) {
|
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 {
|
if canceled {
|
||||||
i.PromptCallback("", true)
|
i.PromptCallback("", true)
|
||||||
h := i.History[i.PromptType]
|
h := i.History[i.PromptType]
|
||||||
@@ -127,11 +130,9 @@ func (i *InfoBuf) DonePrompt(canceled bool) {
|
|||||||
h[len(h)-1] = resp
|
h[len(h)-1] = resp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if i.YNCallback != nil && i.HasYN {
|
if i.YNCallback != nil && hadYN {
|
||||||
i.YNCallback(i.YNResp, canceled)
|
i.YNCallback(i.YNResp, canceled)
|
||||||
}
|
}
|
||||||
i.HasPrompt = false
|
|
||||||
i.HasYN = false
|
|
||||||
i.PromptCallback = nil
|
i.PromptCallback = nil
|
||||||
i.EventCallback = nil
|
i.EventCallback = nil
|
||||||
i.YNCallback = nil
|
i.YNCallback = nil
|
||||||
|
|||||||
@@ -209,6 +209,7 @@ func main() {
|
|||||||
for _, ep := range action.MainTab.Panes {
|
for _, ep := range action.MainTab.Panes {
|
||||||
ep.Display()
|
ep.Display()
|
||||||
}
|
}
|
||||||
|
action.MainTab.Display()
|
||||||
action.InfoBar.Display()
|
action.InfoBar.Display()
|
||||||
screen.Screen.Show()
|
screen.Screen.Show()
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ type View struct {
|
|||||||
type Node struct {
|
type Node struct {
|
||||||
View
|
View
|
||||||
|
|
||||||
kind SplitType
|
Kind SplitType
|
||||||
|
|
||||||
parent *Node
|
parent *Node
|
||||||
children []*Node
|
children []*Node
|
||||||
@@ -69,6 +69,9 @@ func (n *Node) GetView() View {
|
|||||||
func (n *Node) SetView(v View) {
|
func (n *Node) SetView(v View) {
|
||||||
n.X, n.Y, n.W, n.H = v.X, v.Y, v.W, v.H
|
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 {
|
func (n *Node) GetNode(id uint64) *Node {
|
||||||
if n.id == id && n.IsLeaf() {
|
if n.id == id && n.IsLeaf() {
|
||||||
@@ -86,9 +89,9 @@ func (n *Node) GetNode(id uint64) *Node {
|
|||||||
return nil
|
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 := new(Node)
|
||||||
n.kind = kind
|
n.Kind = Kind
|
||||||
n.canResize = true
|
n.canResize = true
|
||||||
n.propScale = true
|
n.propScale = true
|
||||||
n.X, n.Y, n.W, n.H = x, y, w, h
|
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
|
ind = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if n.parent.kind == STVert {
|
if n.parent.Kind == STVert {
|
||||||
return n.parent.vResizeSplit(ind, size)
|
return n.parent.vResizeSplit(ind, size)
|
||||||
}
|
}
|
||||||
return n.parent.hResizeSplit(ind, size)
|
return n.parent.hResizeSplit(ind, size)
|
||||||
@@ -282,10 +285,10 @@ func (n *Node) HSplit(bottom bool) uint64 {
|
|||||||
if !n.IsLeaf() {
|
if !n.IsLeaf() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
if n.kind == STUndef {
|
if n.Kind == STUndef {
|
||||||
n.kind = STVert
|
n.Kind = STVert
|
||||||
}
|
}
|
||||||
if n.kind == STVert {
|
if n.Kind == STVert {
|
||||||
return n.vHSplit(0, bottom)
|
return n.vHSplit(0, bottom)
|
||||||
}
|
}
|
||||||
return n.hHSplit(bottom)
|
return n.hHSplit(bottom)
|
||||||
@@ -295,32 +298,41 @@ func (n *Node) VSplit(right bool) uint64 {
|
|||||||
if !n.IsLeaf() {
|
if !n.IsLeaf() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
if n.kind == STUndef {
|
if n.Kind == STUndef {
|
||||||
n.kind = STHoriz
|
n.Kind = STHoriz
|
||||||
}
|
}
|
||||||
if n.kind == STVert {
|
if n.Kind == STVert {
|
||||||
return n.vVSplit(right)
|
return n.vVSplit(right)
|
||||||
}
|
}
|
||||||
return n.hVSplit(0, right)
|
return n.hVSplit(0, right)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) Resize(w, h int) {
|
func (n *Node) Resize(w, h int) {
|
||||||
propW, propH := float64(w)/float64(n.W), float64(h)/float64(n.H)
|
if n.IsLeaf() {
|
||||||
x, y := n.X, n.Y
|
n.W, n.H = w, h
|
||||||
for _, c := range n.children {
|
} else {
|
||||||
cW := int(float64(c.W) * propW)
|
propW, propH := float64(w)/float64(n.W), float64(h)/float64(n.H)
|
||||||
cH := int(float64(c.H) * propH)
|
log.Println(w, h, n.W, n.H, propW, propH)
|
||||||
c.Resize(cW, cH)
|
x, y := n.X, n.Y
|
||||||
c.X = x
|
for i, c := range n.children {
|
||||||
c.Y = y
|
cW := int(float64(c.W) * propW)
|
||||||
if n.kind == STHoriz {
|
// if c.IsLeaf() && i != len(n.children)-1 {
|
||||||
x += cW
|
// cW++
|
||||||
} else {
|
// }
|
||||||
y += cH
|
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() {
|
func (n *Node) alignSize() {
|
||||||
@@ -329,21 +341,22 @@ func (n *Node) alignSize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
totw, toth := 0, 0
|
totw, toth := 0, 0
|
||||||
for _, c := range n.children {
|
for i, c := range n.children {
|
||||||
if n.kind == STHoriz {
|
if n.Kind == STHoriz {
|
||||||
|
if i != len(n.children)-1 {
|
||||||
|
c.Resize(c.W-1, c.H)
|
||||||
|
}
|
||||||
totw += c.W
|
totw += c.W
|
||||||
} else {
|
} else {
|
||||||
toth += c.H
|
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 := n.children[len(n.children)-1]
|
||||||
last.Resize(last.W, last.H+n.H-toth)
|
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 := n.children[len(n.children)-1]
|
||||||
last.Resize(last.W+n.W-totw, last.H)
|
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
|
var strf func(n *Node, ident int) string
|
||||||
strf = func(n *Node, ident int) string {
|
strf = func(n *Node, ident int) string {
|
||||||
marker := "|"
|
marker := "|"
|
||||||
if n.kind == STHoriz {
|
if n.Kind == STHoriz {
|
||||||
marker = "-"
|
marker = "-"
|
||||||
}
|
}
|
||||||
str := fmt.Sprint(strings.Repeat("\t", ident), marker, n.View, n.id)
|
str := fmt.Sprint(strings.Repeat("\t", ident), marker, n.View, n.id)
|
||||||
|
|||||||
Reference in New Issue
Block a user