add move/resize limitation for X and Y axes
This commit is contained in:
parent
b9cc09c1e4
commit
f8a641d22c
|
@ -1,14 +0,0 @@
|
||||||
package console
|
|
||||||
|
|
||||||
const (
|
|
||||||
KeyPause = "p"
|
|
||||||
KeyQuit = "q"
|
|
||||||
KeyResize = "<Resize>"
|
|
||||||
KeyExit = "<C-c>"
|
|
||||||
KeyLeft = "<Left>"
|
|
||||||
KeyRight = "<Right>"
|
|
||||||
KeyUp = "<Up>"
|
|
||||||
KeyDown = "<Down>"
|
|
||||||
KeyEnter = "<Enter>"
|
|
||||||
KeyEsc = "<Escape>"
|
|
||||||
)
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package console
|
||||||
|
|
||||||
|
const (
|
||||||
|
SignalResize = "<Resize>"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
KeyPause = "p"
|
||||||
|
KeyQuit = "q"
|
||||||
|
KeyExit = "<C-c>"
|
||||||
|
KeyLeft = "<Left>"
|
||||||
|
KeyRight = "<Right>"
|
||||||
|
KeyUp = "<Up>"
|
||||||
|
KeyDown = "<Down>"
|
||||||
|
KeyEnter = "<Enter>"
|
||||||
|
KeyEsc = "<Escape>"
|
||||||
|
)
|
|
@ -29,11 +29,9 @@ func (self *Handler) HandleEvents() {
|
||||||
return
|
return
|
||||||
case console.KeyPause:
|
case console.KeyPause:
|
||||||
pause = !pause
|
pause = !pause
|
||||||
case console.KeyResize:
|
case console.SignalResize:
|
||||||
payload := e.Payload.(ui.Resize)
|
payload := e.Payload.(ui.Resize)
|
||||||
self.Layout.ChangeDimensions(payload.Width, payload.Height)
|
self.Layout.ChangeDimensions(payload.Width, payload.Height)
|
||||||
//case "a":
|
|
||||||
// self.Layout.GetComponent(0).DisableSelection()
|
|
||||||
default:
|
default:
|
||||||
self.Layout.HandleConsoleEvent(e.ID)
|
self.Layout.HandleConsoleEvent(e.ID)
|
||||||
}
|
}
|
||||||
|
|
10
main.go
10
main.go
|
@ -20,13 +20,13 @@ func main() {
|
||||||
width, height := ui.TerminalDimensions()
|
width, height := ui.TerminalDimensions()
|
||||||
layout := widgets.NewLayout(width, height, widgets.NewMenu())
|
layout := widgets.NewLayout(width, height, widgets.NewMenu())
|
||||||
|
|
||||||
for _, chartConfig := range cfg.RunCharts {
|
for _, c := range cfg.RunCharts {
|
||||||
|
|
||||||
chart := widgets.NewRunChart(chartConfig.Title, chartConfig.Precision, chartConfig.RefreshRateMs)
|
chart := widgets.NewRunChart(c.Title, c.Precision, c.RefreshRateMs)
|
||||||
layout.AddComponent(chart, chartConfig.Title, chartConfig.Position, chartConfig.Size, widgets.TypeRunChart)
|
layout.AddComponent(chart, c.Title, c.Position, c.Size, widgets.TypeRunChart)
|
||||||
|
|
||||||
for _, item := range chartConfig.Items {
|
for _, item := range c.Items {
|
||||||
data.NewSampler(chart, item, chartConfig.RefreshRateMs)
|
data.NewSampler(chart, item, c.RefreshRateMs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,29 @@ type Size struct {
|
||||||
Y int `yaml:"y"`
|
Y int `yaml:"y"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Component) Move(x, y int) {
|
func (c *Component) Move(x, y int) {
|
||||||
self.Position.X += x
|
c.Position.X += x
|
||||||
self.Position.Y += y
|
c.Position.Y += y
|
||||||
|
c.normalize()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Component) Resize(x, y int) {
|
func (c *Component) Resize(x, y int) {
|
||||||
self.Size.X += x
|
c.Size.X += x
|
||||||
self.Size.Y += y
|
c.Size.Y += y
|
||||||
|
c.normalize()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Component) normalize() {
|
||||||
|
if c.Size.X < 0 {
|
||||||
|
c.Size.X = 0
|
||||||
|
}
|
||||||
|
if c.Size.Y < 0 {
|
||||||
|
c.Size.Y = 0
|
||||||
|
}
|
||||||
|
if c.Position.X < 0 {
|
||||||
|
c.Position.X = 0
|
||||||
|
}
|
||||||
|
if c.Position.Y < 0 {
|
||||||
|
c.Position.Y = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,15 +60,6 @@ func (l *Layout) GetComponents(Type ComponentType) []ui.Drawable {
|
||||||
return components
|
return components
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO func to get prev/next component navigating left/right/top/bottom
|
|
||||||
func (l *Layout) getComponent(i int) Component {
|
|
||||||
return l.components[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Layout) getSelectedComponent() *Component {
|
|
||||||
return &l.components[l.selection]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Layout) HandleConsoleEvent(e string) {
|
func (l *Layout) HandleConsoleEvent(e string) {
|
||||||
switch e {
|
switch e {
|
||||||
case console.KeyEnter:
|
case console.KeyEnter:
|
||||||
|
@ -175,6 +166,15 @@ func (l *Layout) ChangeDimensions(width, height int) {
|
||||||
l.SetRect(0, 0, width, height)
|
l.SetRect(0, 0, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO func to get prev/next component navigating left/right/top/bottom
|
||||||
|
func (l *Layout) getComponent(i int) Component {
|
||||||
|
return l.components[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Layout) getSelectedComponent() *Component {
|
||||||
|
return &l.components[l.selection]
|
||||||
|
}
|
||||||
|
|
||||||
func (l *Layout) Draw(buffer *ui.Buffer) {
|
func (l *Layout) Draw(buffer *ui.Buffer) {
|
||||||
|
|
||||||
columnWidth := float64(l.GetRect().Dx()) / columnsCount
|
columnWidth := float64(l.GetRect().Dx()) / columnsCount
|
||||||
|
|
|
@ -116,25 +116,34 @@ func (m *Menu) renderHighlight(buffer *ui.Buffer) {
|
||||||
m.printAllDirectionsArrowSign(buffer, -2)
|
m.printAllDirectionsArrowSign(buffer, -2)
|
||||||
|
|
||||||
arrowsText := "Use arrows for selection"
|
arrowsText := "Use arrows for selection"
|
||||||
|
arrowsTextPoint := getMiddlePoint(m.Block, arrowsText, 2)
|
||||||
|
if arrowsTextPoint.In(m.Rectangle) {
|
||||||
buffer.SetString(
|
buffer.SetString(
|
||||||
arrowsText,
|
arrowsText,
|
||||||
ui.NewStyle(console.ColorDarkGrey),
|
ui.NewStyle(console.ColorDarkGrey),
|
||||||
getMiddlePoint(m.Block, arrowsText, 2),
|
arrowsTextPoint,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
optionsText := "<ENTER> to view options"
|
optionsText := "<ENTER> to view options"
|
||||||
|
optionsTextPoint := getMiddlePoint(m.Block, optionsText, 3)
|
||||||
|
if optionsTextPoint.In(m.Rectangle) {
|
||||||
buffer.SetString(
|
buffer.SetString(
|
||||||
optionsText,
|
optionsText,
|
||||||
ui.NewStyle(console.ColorDarkGrey),
|
ui.NewStyle(console.ColorDarkGrey),
|
||||||
getMiddlePoint(m.Block, optionsText, 3),
|
getMiddlePoint(m.Block, optionsText, 3),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
resumeText := "<ESC> to resume"
|
resumeText := "<ESC> to resume"
|
||||||
|
resumeTextPoint := getMiddlePoint(m.Block, resumeText, 4)
|
||||||
|
if resumeTextPoint.In(m.Rectangle) {
|
||||||
buffer.SetString(
|
buffer.SetString(
|
||||||
resumeText,
|
resumeText,
|
||||||
ui.NewStyle(console.ColorDarkGrey),
|
ui.NewStyle(console.ColorDarkGrey),
|
||||||
getMiddlePoint(m.Block, resumeText, 4),
|
resumeTextPoint,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Menu) renderMoveAndResize(buffer *ui.Buffer) {
|
func (m *Menu) renderMoveAndResize(buffer *ui.Buffer) {
|
||||||
|
@ -142,12 +151,12 @@ func (m *Menu) renderMoveAndResize(buffer *ui.Buffer) {
|
||||||
m.printAllDirectionsArrowSign(buffer, -2)
|
m.printAllDirectionsArrowSign(buffer, -2)
|
||||||
|
|
||||||
saveText := "<ENTER> to save changes"
|
saveText := "<ENTER> to save changes"
|
||||||
textPoint := getMiddlePoint(m.Block, saveText, 4)
|
saveTextPoint := getMiddlePoint(m.Block, saveText, 4)
|
||||||
if textPoint.In(m.Rectangle) {
|
if saveTextPoint.In(m.Rectangle) {
|
||||||
buffer.SetString(
|
buffer.SetString(
|
||||||
saveText,
|
saveText,
|
||||||
ui.NewStyle(console.ColorDarkGrey),
|
ui.NewStyle(console.ColorDarkGrey),
|
||||||
textPoint,
|
saveTextPoint,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue