Resizing work

This commit is contained in:
Zachary Yedidia
2019-01-05 19:41:40 -05:00
parent e4e99b03d3
commit 9ed9f517b1
4 changed files with 34 additions and 20 deletions

View File

@@ -1,6 +1,7 @@
package action package action
import ( import (
"log"
"os" "os"
"github.com/zyedidia/micro/cmd/micro/buffer" "github.com/zyedidia/micro/cmd/micro/buffer"
@@ -205,6 +206,7 @@ func VSplit(args []string) {
return return
} }
log.Println("loaded")
MainTab.CurPane().vsplit(buf) MainTab.CurPane().vsplit(buf)
} }

View File

@@ -193,14 +193,14 @@ func main() {
action.InitGlobals() action.InitGlobals()
// Here is the event loop which runs in a separate thread // Here is the event loop which runs in a separate thread
go func() { // go func() {
events = make(chan tcell.Event) // events = make(chan tcell.Event)
for { // for {
screen.Lock() // screen.Lock()
events <- screen.Screen.PollEvent() // events <- screen.Screen.PollEvent()
screen.Unlock() // screen.Unlock()
} // }
}() // }()
for { for {
// Display everything // Display everything
@@ -216,9 +216,12 @@ func main() {
var event tcell.Event var event tcell.Event
// Check for new events // Check for new events
select { screen.Lock()
case event = <-events: event = screen.Screen.PollEvent()
} screen.Unlock()
// select {
// case event = <-events:
// }
if event != nil { if event != nil {
if action.InfoBar.HasPrompt { if action.InfoBar.HasPrompt {

View File

@@ -3,6 +3,7 @@ package util
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"log"
"os" "os"
"strconv" "strconv"
@@ -16,7 +17,9 @@ import (
// This will write the message, and wait for the user // This will write the message, and wait for the user
// to press and key to continue // to press and key to continue
func TermMessage(msg ...interface{}) { func TermMessage(msg ...interface{}) {
log.Println(msg)
screen.TempFini() screen.TempFini()
log.Println("fini")
fmt.Println(msg...) fmt.Println(msg...)
fmt.Print("\nPress enter to continue") fmt.Print("\nPress enter to continue")

View File

@@ -42,7 +42,8 @@ type Node struct {
// the window is resized the split maintains its proportions // the window is resized the split maintains its proportions
propScale bool propScale bool
id uint64 propW, propH float64
id uint64
} }
func (n *Node) ID() uint64 { func (n *Node) ID() uint64 {
@@ -98,6 +99,11 @@ func NewNode(Kind SplitType, x, y, w, h int, parent *Node, id uint64) *Node {
n.children = make([]*Node, 0) n.children = make([]*Node, 0)
n.parent = parent n.parent = parent
n.id = id n.id = id
if parent != nil {
n.propW, n.propH = float64(w)/float64(parent.W), float64(h)/float64(parent.H)
} else {
n.propW, n.propH = 1, 1
}
return n return n
} }
@@ -124,6 +130,7 @@ func (n *Node) vResizeSplit(i int, size int) bool {
c2.Y = size c2.Y = size
c1.Resize(c1.W, size) c1.Resize(c1.W, size)
c2.Resize(c2.W, toth-size) c2.Resize(c2.W, toth-size)
n.propW = float64(size) / float64(n.parent.W)
return true return true
} }
func (n *Node) hResizeSplit(i int, size int) bool { func (n *Node) hResizeSplit(i int, size int) bool {
@@ -138,6 +145,7 @@ func (n *Node) hResizeSplit(i int, size int) bool {
c2.X = size c2.X = size
c1.Resize(size, c1.H) c1.Resize(size, c1.H)
c2.Resize(totw-size, c2.H) c2.Resize(totw-size, c2.H)
n.propH = float64(size) / float64(n.parent.H)
return true return true
} }
@@ -311,16 +319,14 @@ func (n *Node) Resize(w, h int) {
if n.IsLeaf() { if n.IsLeaf() {
n.W, n.H = w, h n.W, n.H = w, h
} else { } 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 x, y := n.X, n.Y
for i, c := range n.children { for i, c := range n.children {
cW := int(float64(c.W) * propW) cW := int(float64(w) * c.propW)
// if c.IsLeaf() && i != len(n.children)-1 { if c.IsLeaf() && i != len(n.children)-1 {
// cW++ cW++
// } }
log.Println("WIDTH:", cW, c.W) cH := int(float64(h) * c.propH)
cH := int(float64(c.H) * propH) log.Println(c.id, c.propW, c.propH, cW, cH, w, h)
c.Resize(cW, cH) c.Resize(cW, cH)
c.X = x c.X = x
c.Y = y c.Y = y