arrange windows by size, smallest at the front

debugger menu entry and CTRL+A hotkey
This commit is contained in:
JetSetIlly 2022-05-01 09:59:45 +01:00
parent fec98e9895
commit 4448c7cae6
43 changed files with 155 additions and 16 deletions

2
go.mod
View file

@ -1,6 +1,6 @@
module github.com/jetsetilly/gopher2600
go 1.17
go 1.18
require (
github.com/bradleyjkemp/memviz v0.2.3

View file

@ -16,6 +16,8 @@
package sdlimgui
import (
"sort"
"github.com/inkyblackness/imgui-go/v4"
"github.com/jetsetilly/gopher2600/emulation"
)
@ -34,7 +36,13 @@ type manager struct {
// debugger debuggerWindows
debuggerWindows map[string]debuggerWindow
debuggerStack []string
// draw windows in order of size (smallest at the front) on the next draw()
//
// using int because we sometimes need to hold the arrangeBySize "signal"
// in order for it to take effect. in most situations a value of 1 will be
// sufficient for the arrangement to take place
arrangeBySize int
// windows can be open and closed through the menu bar
menu map[menuGroup][]menuEntry
@ -215,8 +223,40 @@ func (wm *manager) draw() {
wm.drawMenu()
// draw windows
for _, w := range wm.debuggerWindows {
w.debuggerDraw()
if wm.arrangeBySize > 0 {
wm.arrangeBySize--
// sort windows in order of size smallest at the front
l := make([]debuggerWindow, 0, len(wm.debuggerWindows))
for _, w := range wm.debuggerWindows {
l = append(l, w)
}
sort.Slice(l, func(i int, j int) bool {
gi := l[i].debuggerGeometry().windowSize
gj := l[j].debuggerGeometry().windowSize
return gi.X*gi.Y > gj.X*gj.X
})
// drawing every window with window focus set will cause an ugly
// colour flash in the title bars. push the inactive color to the
// active color
sty := imgui.CurrentStyle()
imgui.PushStyleColor(imgui.StyleColorTitleBgActive, sty.Color(imgui.StyleColorTitleBg))
// draw in order of size
for _, w := range l {
imgui.SetNextWindowFocus()
w.debuggerDraw()
}
// undo early style push
imgui.PopStyleColor()
} else {
for _, w := range wm.debuggerWindows {
w.debuggerDraw()
}
}
}
}

View file

@ -80,9 +80,16 @@ func (wm *manager) drawMenu() {
imguiSeparator()
if imgui.Selectable(" Arrange Windows") {
wm.arrangeBySize = 1
}
imguiSeparator()
if imgui.Selectable(" Quit") {
wm.img.term.pushCommand("QUIT")
}
imgui.EndMenu()
}

View file

@ -155,5 +155,8 @@ func (wm *manager) loadManagerState() (rerr error) {
}
}
// hold arrangeBySize signal for 5 frames
wm.arrangeBySize = 5
return nil
}

View file

@ -15,13 +15,55 @@
package sdlimgui
import "fmt"
import (
"fmt"
"github.com/inkyblackness/imgui-go/v4"
)
// the window type represents all the windows used in the sdlimgui.
type window interface {
// initialisation function. by the first call to manager.draw()
init()
// id should return a unique identifier for the window. note that the
// window title and any menu entry do not have to have the same value as
// the id() but it can.
id() string
}
type windowGeometry interface {
pos() imgui.Vec2
size() imgui.Vec2
}
// size and position of the window. is embedded in playmodeWin and debuggerWin
// interfaces. for window type that implent interfaces then windowGeom
// method calls will need to disambiguate which geometry to use
type windowGeom struct {
windowPos imgui.Vec2
windowSize imgui.Vec2
}
func (g *windowGeom) update() {
g.windowPos = imgui.WindowPos()
g.windowSize = imgui.WindowSize()
}
func (g windowGeom) pos() imgui.Vec2 {
return g.windowPos
}
func (g windowGeom) size() imgui.Vec2 {
return g.windowSize
}
// playmodeWin is a partial implementation of the playmodeWindow interface. it
// does not implement playmodeDraw or the any of the plain window interface.
type playmodeWin struct {
playmodeWindow
playmodeOpen bool
playmodeGeom windowGeom
}
func (w playmodeWin) playmodeID(id string) string {
@ -36,11 +78,16 @@ func (w *playmodeWin) playmodeSetOpen(open bool) {
w.playmodeOpen = open
}
func (w *playmodeWin) playmodeGeometry() windowGeom {
return w.playmodeGeom
}
// debuggerWin is a partial implementation of the debuggerWindow interface. it
// does not implement debuggerDraw or the any of the plain window interface.
type debuggerWin struct {
debuggerWindow
debuggerOpen bool
debuggerGeom windowGeom
}
func (w debuggerWin) debuggerID(id string) string {
@ -55,11 +102,16 @@ func (w *debuggerWin) debuggerSetOpen(open bool) {
w.debuggerOpen = open
}
func (w *debuggerWin) debuggerGeometry() windowGeom {
return w.debuggerGeom
}
type playmodeWindow interface {
window
playmodeDraw()
playmodeIsOpen() bool
playmodeSetOpen(bool)
playmodeGeometry() windowGeom
}
type debuggerWindow interface {
@ -67,17 +119,7 @@ type debuggerWindow interface {
debuggerDraw()
debuggerIsOpen() bool
debuggerSetOpen(bool)
}
// the window type represents all the windows used in the sdlimgui.
type window interface {
// initialisation function. by the first call to manager.draw()
init()
// id should return a unique identifier for the window. note that the
// window title and any menu entry do not have to have the same value as
// the id() but it can.
id() string
debuggerGeometry() windowGeom
}
// toggles a window open according to emulation state

View file

@ -437,6 +437,13 @@ func (img *SdlImgui) serviceKeyboard(ev *sdl.KeyboardEvent) {
}
}
case sdl.SCANCODE_A:
if ctrl {
img.wm.arrangeBySize = 1
} else {
handled = false
}
case sdl.SCANCODE_R:
if ctrl {
img.dbg.PushRawEvent(func() {

View file

@ -98,6 +98,7 @@ func (win *win6507Pinout) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -159,6 +159,7 @@ func (win *winBot) playmodeDraw() {
win.draw()
}
win.playmodeGeom.update()
imgui.End()
}

View file

@ -61,6 +61,7 @@ func (win *winCDFRegisters) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -206,6 +206,7 @@ func (win *winCDFStreams) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -61,6 +61,7 @@ func (win *winDPCregisters) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -61,6 +61,7 @@ func (win *winDPCplusRegisters) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -69,6 +69,7 @@ func (win *winCartRAM) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -62,6 +62,7 @@ func (win *winCartStatic) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -63,6 +63,7 @@ func (win *winSuperchargerRegisters) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -60,6 +60,7 @@ func (win *winCartTape) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -54,6 +54,7 @@ func (win *winCollisions) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -125,6 +125,7 @@ func (win *winComparison) playmodeDraw() {
win.draw()
}
win.playmodeGeom.update()
imgui.End()
}

View file

@ -95,6 +95,7 @@ func (win *winControl) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -75,6 +75,7 @@ func (win *winCoProcDisasm) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -81,6 +81,7 @@ func (win *winCoProcGlobals) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -73,6 +73,7 @@ func (win *winCoProcIllegalAccess) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -82,6 +82,7 @@ func (win *winCoProcPerformance) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -158,6 +158,7 @@ func (win *winCoProcSource) debuggerDraw() {
win.isCollapsed = true
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -76,6 +76,7 @@ func (win *winCPU) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -167,6 +167,7 @@ func (win *winDbgScr) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -114,6 +114,7 @@ func (win *winDisasm) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -59,6 +59,7 @@ func (win *winLog) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -84,6 +84,7 @@ func (win *winOscilloscope) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -66,6 +66,7 @@ func (win *winPeripherals) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -61,6 +61,7 @@ func (win *winPlusROMNetwork) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -59,6 +59,7 @@ func (win *winPlusROMNick) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -58,6 +58,7 @@ func (win *winPorts) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -56,6 +56,7 @@ func (win *winPrefs) playmodeDraw() {
win.draw()
}
win.playmodeWin.playmodeGeom.update()
imgui.End()
}
@ -70,6 +71,7 @@ func (win *winPrefs) debuggerDraw() {
win.draw()
}
win.debuggerWin.debuggerGeom.update()
imgui.End()
}

View file

@ -52,6 +52,7 @@ func (win *winRAM) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -151,6 +151,7 @@ func (win *winSelectROM) playmodeDraw() {
win.draw()
}
win.playmodeWin.playmodeGeom.update()
imgui.End()
}
@ -181,6 +182,7 @@ func (win *winSelectROM) debuggerDraw() {
win.draw()
}
win.debuggerWin.debuggerGeom.update()
imgui.End()
}

View file

@ -62,6 +62,7 @@ func (win *winSaveKeyEEPROM) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -62,6 +62,7 @@ func (win *winSaveKeyI2C) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -231,6 +231,7 @@ func (win *winTerm) debuggerDraw() {
imgui.PopItemWidth()
})
win.debuggerGeom.update()
imgui.End()
}

View file

@ -77,6 +77,7 @@ func (win *winTIA) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -101,6 +101,7 @@ func (win *winTimeline) debuggerDraw() {
win.drawKey()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -57,6 +57,7 @@ func (win *winTimer) debuggerDraw() {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
}

View file

@ -75,6 +75,7 @@ func (win *winTracker) playmodeDraw() {
win.draw()
}
win.playmodeWin.playmodeGeom.update()
imgui.End()
}
@ -93,6 +94,7 @@ func (win *winTracker) debuggerDraw() {
win.draw()
}
win.debuggerWin.debuggerGeom.update()
imgui.End()
}