component selection using mouse click
This commit is contained in:
parent
c8ba8e9491
commit
646fd4f67d
|
@ -66,7 +66,20 @@ func (l *Layout) changeMode(m Mode) {
|
||||||
l.ChangeModeEvents <- m
|
l.ChangeModeEvents <- m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Layout) HandleConsoleEvent(e string) {
|
func (l *Layout) HandleMouseClick(x int, y int) {
|
||||||
|
l.getSelection().CommandChannel <- &data.Command{Type: runchart.CommandMoveSelection, Value: 0}
|
||||||
|
l.menu.Idle()
|
||||||
|
selected, i := l.findComponentAtPoint(image.Point{X: x, Y: y})
|
||||||
|
if selected == nil {
|
||||||
|
l.changeMode(ModeDefault)
|
||||||
|
} else {
|
||||||
|
l.selection = i
|
||||||
|
l.menu.Highlight(selected)
|
||||||
|
l.changeMode(ModeComponentSelect)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Layout) HandleKeyboardEvent(e string) {
|
||||||
|
|
||||||
selected := l.getSelection()
|
selected := l.getSelection()
|
||||||
|
|
||||||
|
@ -289,6 +302,39 @@ func (l *Layout) Draw(buffer *ui.Buffer) {
|
||||||
l.menu.Draw(buffer)
|
l.menu.Draw(buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *Layout) findComponentAtPoint(point image.Point) (*component.Component, int) {
|
||||||
|
|
||||||
|
columnWidth := float64(l.GetRect().Dx()) / float64(columnsCount)
|
||||||
|
rowHeight := float64(l.GetRect().Dy()-statusbarHeight) / float64(rowsCount)
|
||||||
|
|
||||||
|
for i, c := range l.Components {
|
||||||
|
|
||||||
|
x1 := math.Floor(float64(c.Location.X) * columnWidth)
|
||||||
|
y1 := math.Floor(float64(c.Location.Y) * rowHeight)
|
||||||
|
x2 := x1 + math.Floor(float64(c.Size.X))*columnWidth
|
||||||
|
y2 := y1 + math.Floor(float64(c.Size.Y))*rowHeight
|
||||||
|
|
||||||
|
if x2-x1 < minDimension {
|
||||||
|
x2 = x1 + minDimension
|
||||||
|
}
|
||||||
|
|
||||||
|
if y2-y1 < minDimension {
|
||||||
|
y2 = y1 + minDimension
|
||||||
|
}
|
||||||
|
|
||||||
|
rectangle := image.Rectangle{Min: image.Point{
|
||||||
|
X: int(x1), Y: int(y1)},
|
||||||
|
Max: image.Point{X: int(x2), Y: int(y2)},
|
||||||
|
}
|
||||||
|
|
||||||
|
if point.In(rectangle) {
|
||||||
|
return c, i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, -1
|
||||||
|
}
|
||||||
|
|
||||||
func (l *Layout) resetAlerts() {
|
func (l *Layout) resetAlerts() {
|
||||||
for _, c := range l.Components {
|
for _, c := range l.Components {
|
||||||
c.AlertChannel <- nil
|
c.AlertChannel <- nil
|
||||||
|
|
|
@ -122,7 +122,7 @@ func (m *Menu) Draw(buffer *ui.Buffer) {
|
||||||
|
|
||||||
func (m *Menu) renderHighlight(buffer *ui.Buffer) {
|
func (m *Menu) renderHighlight(buffer *ui.Buffer) {
|
||||||
|
|
||||||
arrowsText := "Use arrows for selection"
|
arrowsText := "Use mouse or arrows for selection"
|
||||||
optionsText := "<ENTER> to view options"
|
optionsText := "<ENTER> to view options"
|
||||||
resumeText := "<ESC> to resume"
|
resumeText := "<ESC> to resume"
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package console
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SignalResize = "<Resize>"
|
SignalResize = "<Resize>"
|
||||||
|
SignalClick = "<MouseLeft>"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -44,6 +44,9 @@ func (h *Handler) HandleEvents() {
|
||||||
ui.Render(h.layout)
|
ui.Render(h.layout)
|
||||||
case e := <-h.consoleEvents:
|
case e := <-h.consoleEvents:
|
||||||
switch e.ID {
|
switch e.ID {
|
||||||
|
case console.SignalClick:
|
||||||
|
payload := e.Payload.(ui.Mouse)
|
||||||
|
h.layout.HandleMouseClick(payload.X, payload.Y)
|
||||||
case console.KeyQuit, console.KeyExit:
|
case console.KeyQuit, console.KeyExit:
|
||||||
h.handleExit()
|
h.handleExit()
|
||||||
return
|
return
|
||||||
|
@ -51,7 +54,7 @@ func (h *Handler) HandleEvents() {
|
||||||
payload := e.Payload.(ui.Resize)
|
payload := e.Payload.(ui.Resize)
|
||||||
h.layout.ChangeDimensions(payload.Width, payload.Height)
|
h.layout.ChangeDimensions(payload.Width, payload.Height)
|
||||||
default:
|
default:
|
||||||
h.layout.HandleConsoleEvent(e.ID)
|
h.layout.HandleKeyboardEvent(e.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue