From 3ded301fd35b6030d92db90f4024570e593df5d9 Mon Sep 17 00:00:00 2001 From: Kai O'Reilly Date: Tue, 16 Apr 2024 18:39:08 -0700 Subject: [PATCH] rename core.StageMgr to core.Stages; more associated renames and clean up from RenderWin to RenderWindow rename --- core/app.go | 14 +++--- core/body.go | 4 +- core/dialogs.go | 2 +- core/enumgen.go | 6 +-- core/eventmgr.go | 25 +++++----- core/events.go | 8 +-- core/events_test.go | 2 +- core/mainstage.go | 68 ++++++++++++------------- core/menu.go | 4 +- core/popupstage.go | 26 +++++----- core/render.go | 8 +-- core/renderwindow.go | 76 ++++++++++++++-------------- core/scene.go | 42 ++++++---------- core/settings.go | 2 +- core/sprite.go | 4 +- core/stage.go | 80 +++++++++++++++--------------- core/{stagemgr.go => stages.go} | 48 +++++++++--------- core/testing.go | 2 +- core/typegen.go | 30 +++++------ core/widget.go | 4 +- core/windowgeometry.go | 4 +- core/windowlists.go | 4 +- docs/content/2-widgets/choosers.md | 2 +- examples/filetree/filetree.go | 2 +- examples/svg/svg.go | 8 +-- video/video.go | 2 +- xyzview/scene.go | 6 +-- 27 files changed, 238 insertions(+), 245 deletions(-) rename core/{stagemgr.go => stages.go} (84%) diff --git a/core/app.go b/core/app.go index 830889abfd..c3b756bff2 100644 --- a/core/app.go +++ b/core/app.go @@ -117,17 +117,17 @@ func StandardAppBarBack(tb *Toolbar) *Button { bt := NewButton(tb, "back").SetIcon(icons.ArrowBack).SetTooltip("Back").SetKey(keymap.HistPrev) // TODO(kai/abc): app bar back button disabling // bt.StyleFirst(func(s *styles.Style) { - // if tb.Scene.Stage.MainMgr == nil { + // if tb.Scene.Stage.Mains == nil { // return // } - // s.SetState(tb.Scene.Stage.MainMgr.Stack.Len() <= 1 && len(AllRenderWins) <= 1, states.Disabled) + // s.SetState(tb.Scene.Stage.Mains.Stack.Len() <= 1 && len(AllRenderWins) <= 1, states.Disabled) // }) bt.OnClick(func(e events.Event) { - if slen := tb.Scene.Stage.MainMgr.Stack.Len(); slen > 1 { + if slen := tb.Scene.Stage.Mains.Stack.Len(); slen > 1 { if tb.Scene.Stage.CloseOnBack { tb.Scene.Close() } else { - tb.Scene.Stage.MainMgr.Stack.ValueByIndex(slen - 2).Raise() + tb.Scene.Stage.Mains.Stack.ValueByIndex(slen - 2).Raise() } return } @@ -193,7 +193,7 @@ func (tb *Toolbar) StandardOverflowMenu(m *Scene) { //types:add }) NewButton(m).SetText("Minimize").SetIcon(icons.Minimize). OnClick(func(e events.Event) { - win := tb.Scene.RenderWin() + win := tb.Scene.RenderWindow() if win != nil { win.Minimize() } @@ -201,7 +201,7 @@ func (tb *Toolbar) StandardOverflowMenu(m *Scene) { //types:add NewSeparator(m) NewButton(m).SetText("Close window").SetIcon(icons.Close).SetKey(keymap.WinClose). OnClick(func(e events.Event) { - win := tb.Scene.RenderWin() + win := tb.Scene.RenderWindow() if win != nil { win.CloseReq() } @@ -265,7 +265,7 @@ func ConfigAppChooser(ch *Chooser, tb *Toolbar) *Chooser { ch.AddItemsFunc(func() { for _, rw := range AllRenderWindows { - for _, kv := range rw.MainStageMgr.Stack.Order { + for _, kv := range rw.Mains.Stack.Order { st := kv.Value // we do not include ourself if st == tb.Scene.Stage { diff --git a/core/body.go b/core/body.go index 4b4273d114..e3c2f2f540 100644 --- a/core/body.go +++ b/core/body.go @@ -59,7 +59,7 @@ func (bd *Body) SetStyles() { }) } -// SetTitle sets the title in the Body, Scene, and Stage, RenderWin, and title widget. +// SetTitle sets the title in the Body, Scene, and Stage, RenderWindow, and title widget. // This is the one place to change the title for everything. func (bd *Body) SetTitle(title string) *Body { bd.Nm = title @@ -67,7 +67,7 @@ func (bd *Body) SetTitle(title string) *Body { bd.Scene.Nm = title if bd.Scene.Stage != nil { bd.Scene.Stage.Title = title - win := bd.Scene.RenderWin() + win := bd.Scene.RenderWindow() if win != nil { win.SetName(title) win.SetTitle(title) diff --git a/core/dialogs.go b/core/dialogs.go index 46e772e870..24e60f7090 100644 --- a/core/dialogs.go +++ b/core/dialogs.go @@ -22,7 +22,7 @@ func NonNilContext(ctx Widget) Widget { if !reflectx.AnyIsNil(ctx) { return ctx } - return CurrentRenderWindow.MainStageMgr.Top().Scene + return CurrentRenderWindow.Mains.Top().Scene } // NewDialog returns a new [DialogStage] that does not take up the diff --git a/core/enumgen.go b/core/enumgen.go index 8e84c635c2..05ea0a08a6 100644 --- a/core/enumgen.go +++ b/core/enumgen.go @@ -410,7 +410,7 @@ const WindowFlagsN WindowFlags = 7 var _WindowFlagsValueMap = map[string]WindowFlags{`HasSavedGeom`: 0, `Closing`: 1, `Resizing`: 2, `GotFocus`: 3, `SentShow`: 4, `StopEventLoop`: 5, `SelectionMode`: 6} -var _WindowFlagsDescMap = map[WindowFlags]string{0: `WindowHasSavedGeom indicates if this window has WindowGeometry setting that sized it -- affects whether other default geom should be applied.`, 1: `WindowClosing is atomic flag indicating window is closing`, 2: `WindowResizing is atomic flag indicating window is resizing`, 3: `WindowGotFocus indicates that have we received RenderWin focus`, 4: `WindowSentShow have we sent the show event yet? Only ever sent ONCE`, 5: `WindowStopEventLoop is set when event loop stop is requested`, 6: `WindowSelectionMode indicates that the window is in Cogent Core inspect editor edit mode`} +var _WindowFlagsDescMap = map[WindowFlags]string{0: `WindowHasSavedGeom indicates if this window has WindowGeometry setting that sized it -- affects whether other default geom should be applied.`, 1: `WindowClosing is atomic flag indicating window is closing`, 2: `WindowResizing is atomic flag indicating window is resizing`, 3: `WindowGotFocus indicates that have we received RenderWindow focus`, 4: `WindowSentShow have we sent the show event yet? Only ever sent ONCE`, 5: `WindowStopEventLoop is set when event loop stop is requested`, 6: `WindowSelectionMode indicates that the window is in Cogent Core inspect editor edit mode`} var _WindowFlagsMap = map[WindowFlags]string{0: `HasSavedGeom`, 1: `Closing`, 2: `Resizing`, 3: `GotFocus`, 4: `SentShow`, 5: `StopEventLoop`, 6: `SelectionMode`} @@ -530,7 +530,7 @@ const ScFlagsN ScFlags = 10 var _ScFlagsValueMap = map[string]ScFlags{`ScUpdating`: 2, `ScNeedsRender`: 3, `ScNeedsLayout`: 4, `ScNeedsRebuild`: 5, `ScImageUpdated`: 6, `ScPrefSizing`: 7, `ScPreserve`: 8, `ScRenderBBoxes`: 9} -var _ScFlagsDescMap = map[ScFlags]string{2: `ScUpdating means scene is in the process of updating: set for any kind of tree-level update. skip any further update passes until it goes off.`, 3: `ScNeedsRender means nodes have flagged that they need a Render update.`, 4: `ScNeedsLayout means that this scene needs DoLayout stack: GetSize, DoLayout, then Render. This is true after any Config.`, 5: `ScNeedsRebuild means that this scene needs full Rebuild: Config, Layout, Render with DoRebuild flag set (e.g., after global style changes, zooming, etc)`, 6: `ScImageUpdated indicates that the Scene's image has been updated e.g., due to a render or a resize. This is reset by the global RenderWin rendering pass, so it knows whether it needs to copy the image up to the GPU or not.`, 7: `ScPrefSizing means that this scene is currently doing a PrefSize computation to compute the size of the scene (for sizing window for example) -- affects layout size computation only for Over`, 8: `ScPreserve keeps this scene around instead of deleting when it is no longer needed. Set if added to SceneLibrary for example.`, 9: `ScRenderBBoxes renders the bounding boxes for all objects in scene`} +var _ScFlagsDescMap = map[ScFlags]string{2: `ScUpdating means scene is in the process of updating: set for any kind of tree-level update. skip any further update passes until it goes off.`, 3: `ScNeedsRender means nodes have flagged that they need a Render update.`, 4: `ScNeedsLayout means that this scene needs DoLayout stack: GetSize, DoLayout, then Render. This is true after any Config.`, 5: `ScNeedsRebuild means that this scene needs full Rebuild: Config, Layout, Render with DoRebuild flag set (e.g., after global style changes, zooming, etc)`, 6: `ScImageUpdated indicates that the Scene's image has been updated e.g., due to a render or a resize. This is reset by the global RenderWindow rendering pass, so it knows whether it needs to copy the image up to the GPU or not.`, 7: `ScPrefSizing means that this scene is currently doing a PrefSize computation to compute the size of the scene (for sizing window for example) -- affects layout size computation only for Over`, 8: `ScPreserve keeps this scene around instead of deleting when it is no longer needed. Set if added to SceneLibrary for example.`, 9: `ScRenderBBoxes renders the bounding boxes for all objects in scene`} var _ScFlagsMap = map[ScFlags]string{2: `ScUpdating`, 3: `ScNeedsRender`, 4: `ScNeedsLayout`, 5: `ScNeedsRebuild`, 6: `ScImageUpdated`, 7: `ScPrefSizing`, 8: `ScPreserve`, 9: `ScRenderBBoxes`} @@ -681,7 +681,7 @@ const StageTypesN StageTypes = 6 var _StageTypesValueMap = map[string]StageTypes{`WindowStage`: 0, `DialogStage`: 1, `MenuStage`: 2, `TooltipStage`: 3, `SnackbarStage`: 4, `CompleterStage`: 5} -var _StageTypesDescMap = map[StageTypes]string{0: `WindowStage is a MainStage that displays a Scene in a full window. One of these must be created first, as the primary App contents, and it typically persists throughout. It fills the RenderWin window. Additional Windows can be created either within the same RenderWin (Mobile) or in separate RenderWin windows (Desktop, NewWindow).`, 1: `DialogStage is a MainStage that displays Scene in a smaller dialog window on top of a Window, or in its own RenderWin (on Desktop only). It can be Modal or not.`, 2: `MenuStage is a PopupStage that displays a Scene with Action Widgets overlaid on a MainStage. It is typically Modal and ClickOff, and closes when an Action is selected.`, 3: `TooltipStage is a PopupStage that displays a Scene with extra info overlaid on a MainStage. It is typically ClickOff and not Modal.`, 4: `SnackbarStage is a PopupStage displays a Scene with info and typically an additional optional Action, usually displayed at the bottom. It is typically not ClickOff or Modal, but has a timeout.`, 5: `CompleterStage is a PopupStage that displays a Scene with text completions, spelling corrections, or other such dynamic info. It is typically ClickOff, not Modal, dynamically updating, and closes when something is selected or typing renders it no longer relevant.`} +var _StageTypesDescMap = map[StageTypes]string{0: `WindowStage is a MainStage that displays a Scene in a full window. One of these must be created first, as the primary App contents, and it typically persists throughout. It fills the RenderWindow window. Additional Windows can be created either within the same RenderWin (Mobile) or in separate RenderWindow windows (Desktop, NewWindow).`, 1: `DialogStage is a MainStage that displays Scene in a smaller dialog window on top of a Window, or in its own RenderWindow (on Desktop only). It can be Modal or not.`, 2: `MenuStage is a PopupStage that displays a Scene with Action Widgets overlaid on a MainStage. It is typically Modal and ClickOff, and closes when an Action is selected.`, 3: `TooltipStage is a PopupStage that displays a Scene with extra info overlaid on a MainStage. It is typically ClickOff and not Modal.`, 4: `SnackbarStage is a PopupStage displays a Scene with info and typically an additional optional Action, usually displayed at the bottom. It is typically not ClickOff or Modal, but has a timeout.`, 5: `CompleterStage is a PopupStage that displays a Scene with text completions, spelling corrections, or other such dynamic info. It is typically ClickOff, not Modal, dynamically updating, and closes when something is selected or typing renders it no longer relevant.`} var _StageTypesMap = map[StageTypes]string{0: `WindowStage`, 1: `DialogStage`, 2: `MenuStage`, 3: `TooltipStage`, 4: `SnackbarStage`, 5: `CompleterStage`} diff --git a/core/eventmgr.go b/core/eventmgr.go index 07ad47a1ec..831a044c6c 100644 --- a/core/eventmgr.go +++ b/core/eventmgr.go @@ -132,21 +132,22 @@ type EventMgr struct { DragData any } -// MainStageMgr returns the MainStageMgr for our Main Stage -func (em *EventMgr) MainStageMgr() *StageMgr { +// Mains returns the stack of main stages for our scene. +func (em *EventMgr) Mains() *Stages { if em.Scene == nil { return nil } - return em.Scene.MainStageMgr() + return em.Scene.Stage.Mains } -// RenderWin returns the overall render window, which could be nil -func (em *EventMgr) RenderWin() *RenderWindow { - mgr := em.MainStageMgr() +// RenderWindow returns the overall render window in which we reside, +// which could be nil. +func (em *EventMgr) RenderWindow() *RenderWindow { + mgr := em.Mains() if mgr == nil { return nil } - return mgr.RenderWin + return mgr.RenderWindow } /////////////////////////////////////////////////////////////////////// @@ -623,7 +624,7 @@ func (em *EventMgr) HandleLong(e events.Event, deep Widget, w *Widget, pos *imag // fmt.Println("setting new:", deep) *pos = e.WindowPos() *t = time.AfterFunc(stime, func() { - win := em.RenderWin() + win := em.RenderWindow() if win == nil { return } @@ -806,7 +807,7 @@ func (em *EventMgr) DropFinalize(de *events.DragDrop) { // if available. func (em *EventMgr) Clipboard() system.Clipboard { var gwin system.Window - if win := em.RenderWin(); win != nil { + if win := em.RenderWindow(); win != nil { gwin = win.SystemWindow } return system.TheApp.Clipboard(gwin) @@ -814,7 +815,7 @@ func (em *EventMgr) Clipboard() system.Clipboard { // SetCursor sets window cursor to given Cursor func (em *EventMgr) SetCursor(cur cursors.Cursor) { - win := em.RenderWin() + win := em.RenderWindow() if win == nil { return } @@ -1062,7 +1063,7 @@ func (em *EventMgr) ManagerKeyChordEvents(e events.Event) { if e.Type() != events.KeyChord { return } - win := em.RenderWin() + win := em.RenderWindow() if win == nil { return } @@ -1094,7 +1095,7 @@ func (em *EventMgr) ManagerKeyChordEvents(e events.Event) { dstr := time.Now().Format("Mon_Jan_2_15:04:05_MST_2006") fnm, _ := filepath.Abs("./GrabOf_" + sc.Name() + "_" + dstr + ".png") imagex.Save(sc.Pixels, fnm) - fmt.Printf("Saved RenderWin Image to: %s\n", fnm) + fmt.Printf("Saved RenderWindow Image to: %s\n", fnm) e.SetHandled() case keymap.ZoomIn: win.StepZoom(1) diff --git a/core/events.go b/core/events.go index 498907fe56..3a50bb03b6 100644 --- a/core/events.go +++ b/core/events.go @@ -28,7 +28,7 @@ func (wb *WidgetBase) EventMgr() *EventMgr { // SystemEventMgr returns the lower-level system event // manager for this [Widget]'s [Scene]. func (wb *WidgetBase) SystemEventMgr() *events.Mgr { - return wb.Scene.RenderWin().SystemWindow.EventMgr() + return wb.Scene.RenderWindow().SystemWindow.EventMgr() } // Clipboard returns the clipboard for the [Widget] to use. @@ -420,7 +420,7 @@ func (wb *WidgetBase) HandleLongHoverTooltip() { }) wb.On(events.LongHoverEnd, func(e events.Event) { if wb.Scene.Stage != nil { - wb.Scene.Stage.PopupMgr.PopDeleteType(TooltipStage) + wb.Scene.Stage.Popups.PopDeleteType(TooltipStage) } }) @@ -435,7 +435,7 @@ func (wb *WidgetBase) HandleLongHoverTooltip() { }) wb.On(events.LongPressEnd, func(e events.Event) { if wb.Scene.Stage != nil { - wb.Scene.Stage.PopupMgr.PopDeleteType(TooltipStage) + wb.Scene.Stage.Popups.PopDeleteType(TooltipStage) } }) } @@ -465,7 +465,7 @@ func (wb *WidgetBase) HandleWidgetStateFromFocus() { func (wb *WidgetBase) HandleWidgetMagnify() { wb.On(events.Magnify, func(e events.Event) { ev := e.(*events.TouchMagnify) - wb.EventMgr().RenderWin().StepZoom(ev.ScaleFactor - 1) + wb.EventMgr().RenderWindow().StepZoom(ev.ScaleFactor - 1) }) } diff --git a/core/events_test.go b/core/events_test.go index 4bf05dc308..8606ca1cfe 100644 --- a/core/events_test.go +++ b/core/events_test.go @@ -61,7 +61,7 @@ func TestWidgetEventManager(t *testing.T) { assert.Equal(t, &w.Scene.EventMgr, w.EventMgr()) b.AssertRender(t, "events/event-manager", func() { - assert.Equal(t, w.Scene.RenderWin().SystemWindow.EventMgr(), w.SystemEventMgr()) + assert.Equal(t, w.Scene.RenderWindow().SystemWindow.EventMgr(), w.SystemEventMgr()) assert.Equal(t, w.EventMgr().Clipboard(), w.Clipboard()) }) } diff --git a/core/mainstage.go b/core/mainstage.go index 2bdb606b89..ab336f1246 100644 --- a/core/mainstage.go +++ b/core/mainstage.go @@ -25,8 +25,8 @@ func NewMainStage(typ StageTypes, sc *Scene) *Stage { st := &Stage{} st.SetType(typ) st.SetScene(sc) - st.PopupMgr = &StageMgr{} - st.PopupMgr.Main = st + st.Popups = &Stages{} + st.Popups.Main = st st.Main = st return st } @@ -83,7 +83,7 @@ func (st *Stage) AddDialogDecor() *Stage { np := sc.SceneGeom.Pos.Add(pd) np.X = max(np.X, 0) np.Y = max(np.Y, 0) - rw := sc.RenderWin() + rw := sc.RenderWindow() sz := rw.SystemWindow.Size() mx := sz.X - int(sc.SceneGeom.Size.X) my := sz.Y - int(sc.SceneGeom.Size.Y) @@ -117,11 +117,11 @@ func (st *Stage) InheritBars() { st.Scene.InheritBarsWidget(st.Context) } -// FirstWinManager creates a temporary Main StageMgr for the first window -// to be able to get sizing information prior to having a RenderWin, +// FirstWindowStages creates a temporary [Stages] for the first window +// to be able to get sizing information prior to having a RenderWindow, // based on the system App Screen Size. Only adds a RenderContext. -func (st *Stage) FirstWinManager() *StageMgr { - ms := &StageMgr{} +func (st *Stage) FirstWindowStages() *Stages { + ms := &Stages{} ms.RenderContext = NewRenderContext() return ms } @@ -149,10 +149,10 @@ func (st *Stage) RunWindow() *Stage { sc := st.Scene if CurrentRenderWindow == nil { // If we have no current render window, we need to be in a new window, - // and we need a *temporary* MainMgr to get initial pref size - st.SetMainMgr(st.FirstWinManager()) + // and we need a *temporary* Mains to get initial pref size + st.SetMains(st.FirstWindowStages()) } else { - st.SetMainMgr(&CurrentRenderWindow.MainStageMgr) + st.SetMains(&CurrentRenderWindow.Mains) } st.ConfigMainStage() @@ -195,48 +195,48 @@ func (st *Stage) RunWindow() *Stage { } } } - st.MainMgr = nil // reset + st.Mains = nil // reset if DebugSettings.WinRenderTrace { fmt.Println("MainStage.RunWindow: Window Size:", sz) } if st.NewWindow || CurrentRenderWindow == nil { sc.Resize(math32.Geom2DInt{st.RenderContext.Geom.Pos, sz}) - win := st.NewRenderWin() + win := st.NewRenderWindow() MainRenderWindows.Add(win) CurrentRenderWindow = win win.GoStartEventLoop() return st } if st.Context != nil { - ms := st.Context.AsWidget().Scene.MainStageMgr() + ms := st.Context.AsWidget().Scene.Stage.Mains msc := ms.Top().Scene sc.SceneGeom.Size = sz sc.FitInWindow(msc.SceneGeom) // does resize ms.Push(st) - st.SetMainMgr(ms) + st.SetMains(ms) } else { - ms := &CurrentRenderWindow.MainStageMgr + ms := &CurrentRenderWindow.Mains msc := ms.Top().Scene sc.SceneGeom.Size = sz sc.FitInWindow(msc.SceneGeom) // does resize ms.Push(st) - st.SetMainMgr(ms) + st.SetMains(ms) } return st } // GetValidContext ensures that the Context is non-nil and has a valid -// Scene pointer, using CurRenderWin if the current Context is not valid. -// If CurRenderWin is nil (should not happen), then it returns false and +// Scene pointer, using CurrentRenderWindow if the current Context is not valid. +// If CurrentRenderWindow is nil (should not happen), then it returns false and // the calling function must bail. func (st *Stage) GetValidContext() bool { if st.Context == nil || st.Context.This() == nil || st.Context.AsWidget().Scene == nil { if CurrentRenderWindow == nil { - slog.Error("Stage Run: Context is nil and CurRenderWin is nil, cannot Run!", "Name", st.Name, "Title", st.Title) + slog.Error("Stage Run: Context is nil and CurrentRenderWindow is nil, cannot Run!", "Name", st.Name, "Title", st.Title) return false } - st.Context = CurrentRenderWindow.MainStageMgr.Top().Scene + st.Context = CurrentRenderWindow.Mains.Top().Scene } return true } @@ -247,7 +247,7 @@ func (st *Stage) RunDialog() *Stage { return st } ctx := st.Context.AsWidget() - ms := ctx.Scene.MainStageMgr() + ms := ctx.Scene.Stage.Mains // if our main stage manager is nil, we wait until our context is shown and then try again if ms == nil { @@ -262,7 +262,7 @@ func (st *Stage) RunDialog() *Stage { st.AddDialogDecor() sc.SceneGeom.Pos = st.Pos - st.SetMainMgr(ms) // temporary for prefs + st.SetMains(ms) // temporary for prefs sz := ms.RenderContext.Geom.Size if !st.FullWindow || st.NewWindow { @@ -275,11 +275,11 @@ func (st *Stage) RunDialog() *Stage { } if st.NewWindow { - st.MainMgr = nil + st.Mains = nil sc.Resize(math32.Geom2DInt{st.RenderContext.Geom.Pos, sz}) st.Type = WindowStage // critical: now is its own window! sc.SceneGeom.Pos = image.Point{} // ignore pos - win := st.NewRenderWin() + win := st.NewRenderWindow() DialogRenderWindows.Add(win) CurrentRenderWindow = win win.GoStartEventLoop() @@ -289,11 +289,11 @@ func (st *Stage) RunDialog() *Stage { // fmt.Println("dlg:", sc.SceneGeom, "win:", winGeom) sc.FitInWindow(st.RenderContext.Geom) // does resize ms.Push(st) - // st.SetMainMgr(ms) // already set + // st.SetMains(ms) // already set return st } -func (st *Stage) NewRenderWin() *RenderWindow { +func (st *Stage) NewRenderWindow() *RenderWindow { name := st.Name title := st.Title opts := &system.NewWindowOptions{ @@ -325,13 +325,13 @@ func (st *Stage) NewRenderWin() *RenderWindow { win.SetFlag(true, WindowHasSavedGeom) } AllRenderWindows.Add(win) - // initialize MainStageMgr - win.MainStageMgr.RenderWin = win - win.MainStageMgr.RenderContext = NewRenderContext() // sets defaults according to Screen + // initialize Mains + win.Mains.RenderWindow = win + win.Mains.RenderContext = NewRenderContext() // sets defaults according to Screen // note: win is not yet created by the OS and we don't yet know its actual size // or dpi. - win.MainStageMgr.Push(st) - st.SetMainMgr(&win.MainStageMgr) + win.Mains.Push(st) + st.SetMains(&win.Mains) return win } @@ -340,8 +340,8 @@ func (st *Stage) MainHandleEvent(e events.Event) { if st.Scene == nil { return } - st.PopupMgr.PopupHandleEvent(e) - if e.IsHandled() || st.PopupMgr.TopIsModal() { + st.Popups.PopupHandleEvent(e) + if e.IsHandled() || st.Popups.TopIsModal() { if DebugSettings.EventTrace && e.Type() != events.MouseMove { fmt.Println("Event handled by popup:", e) } @@ -352,7 +352,7 @@ func (st *Stage) MainHandleEvent(e events.Event) { } // MainHandleEvent calls MainHandleEvent on relevant stages in reverse order. -func (sm *StageMgr) MainHandleEvent(e events.Event) { +func (sm *Stages) MainHandleEvent(e events.Event) { n := sm.Stack.Len() for i := n - 1; i >= 0; i-- { st := sm.Stack.ValueByIndex(i) diff --git a/core/menu.go b/core/menu.go index fd8ad190fa..6f9426a052 100644 --- a/core/menu.go +++ b/core/menu.go @@ -97,7 +97,7 @@ func NewMenuScene(menu func(m *Scene), name ...string) *Scene { // NewMenuStage returns a new Menu stage with given scene contents, // in connection with given widget, which provides key context -// for constructing the menu, at given RenderWin position +// for constructing the menu, at given RenderWindow position // (e.g., use ContextMenuPos or WinPos method on ctx Widget). // Make further configuration choices using Set* methods, which // can be chained directly after the New call. @@ -116,7 +116,7 @@ func NewMenuStage(sc *Scene, ctx Widget, pos image.Point) *Stage { // NewMenu returns a new menu stage based on the given menu constructor // function, in connection with given widget, which provides key context -// for constructing the menu at given RenderWin position +// for constructing the menu at given RenderWindow position // (e.g., use ContextMenuPos or WinPos method on ctx Widget). // Make further configuration choices using Set* methods, which // can be chained directly after the New call. diff --git a/core/popupstage.go b/core/popupstage.go index 156c1de45d..b7139ebc36 100644 --- a/core/popupstage.go +++ b/core/popupstage.go @@ -68,11 +68,11 @@ func (st *Stage) RunPopup() *Stage { if st.Type == SnackbarStage { // only one snackbar can exist - ms.PopupMgr.PopDeleteType(SnackbarStage) + ms.Popups.PopDeleteType(SnackbarStage) } - ms.PopupMgr.Push(st) - st.SetPopupMgr(ms) // sets all pointers + ms.Popups.Push(st) + st.SetPopups(ms) // sets all pointers maxSz := msc.SceneGeom.Size @@ -131,7 +131,7 @@ func (st *Stage) RunPopup() *Stage { if st.Main == nil { return } - st.PopupMgr.DeleteStage(st) + st.Popups.DeleteStage(st) }) } @@ -142,7 +142,7 @@ func (st *Stage) RunPopup() *Stage { // This version is for Asynchronous usage outside the main event loop, // for example in a delayed callback AfterFunc etc. func (st *Stage) ClosePopupAsync() { - rc := st.MainMgr.RenderContext + rc := st.Mains.RenderContext rc.Lock() defer rc.Unlock() st.ClosePopup() @@ -151,10 +151,10 @@ func (st *Stage) ClosePopupAsync() { // ClosePopup closes this stage as a popup, returning whether it was closed. func (st *Stage) ClosePopup() bool { // NOTE: this is critical for Completer to not crash due to async closing - if st.Main == nil || st.PopupMgr == nil || st.MainMgr == nil { + if st.Main == nil || st.Popups == nil || st.Mains == nil { return false } - return st.PopupMgr.DeleteStage(st) + return st.Popups.DeleteStage(st) } // ClosePopupAndBelowAsync closes this stage as a popup, @@ -163,7 +163,7 @@ func (st *Stage) ClosePopup() bool { // for example in a delayed callback AfterFunc etc. // It returns whether it successfully closed popups. func (st *Stage) ClosePopupAndBelowAsync() bool { - rc := st.MainMgr.RenderContext + rc := st.Mains.RenderContext rc.Lock() defer rc.Unlock() return st.ClosePopupAndBelow() @@ -174,10 +174,10 @@ func (st *Stage) ClosePopupAndBelowAsync() bool { // It returns whether it successfully closed popups. func (st *Stage) ClosePopupAndBelow() bool { // NOTE: this is critical for Completer to not crash due to async closing - if st.Main == nil || st.PopupMgr == nil || st.MainMgr == nil { + if st.Main == nil || st.Popups == nil || st.Mains == nil { return false } - return st.PopupMgr.DeleteStageAndBelow(st) + return st.Popups.DeleteStageAndBelow(st) } func (st *Stage) PopupHandleEvent(e events.Event) { @@ -193,10 +193,10 @@ func (st *Stage) PopupHandleEvent(e events.Event) { } ////////////////////////////////////////////////////////////////////////////// -// StageMgr for Popup +// [Stages] for popups // TopIsModal returns true if there is a Top PopupStage and it is Modal. -func (pm *StageMgr) TopIsModal() bool { +func (pm *Stages) TopIsModal() bool { top := pm.Top() if top == nil { return false @@ -206,7 +206,7 @@ func (pm *StageMgr) TopIsModal() bool { // PopupHandleEvent processes Popup events. // requires outer RenderContext mutex. -func (pm *StageMgr) PopupHandleEvent(e events.Event) { +func (pm *Stages) PopupHandleEvent(e events.Event) { top := pm.Top() if top == nil { return diff --git a/core/render.go b/core/render.go index 0afc06b81d..63234b6232 100644 --- a/core/render.go +++ b/core/render.go @@ -57,7 +57,7 @@ import ( // For nodes with dynamic content that doesn't require styling or config, // a simple NeedsRender call will drive re-rendering. // -// Updating is _always_ driven top-down by RenderWin at FPS sampling rate, +// Updating is _always_ driven top-down by RenderWindow at FPS sampling rate, // in the DoUpdate() call on the Scene. // Three types of updates can be triggered, in order of least impact // and highest frequency first: @@ -303,7 +303,7 @@ var SceneShowIters = 2 // DoUpdate checks scene Needs flags to do whatever updating is required. // returns false if already updating. -// This is the main update call made by the RenderWin at FPS frequency. +// This is the main update call made by the RenderWindow at FPS frequency. func (sc *Scene) DoUpdate() bool { if sc.Is(ScUpdating) { // fmt.Println("scene bail on updt") @@ -563,7 +563,7 @@ func (wb *WidgetBase) PointToRelPos(pt image.Point) image.Point { return pt.Sub(wb.Geom.ContentBBox.Min) } -// WinBBox returns the RenderWin based bounding box for the widget +// WinBBox returns the RenderWindow based bounding box for the widget // by adding the Scene position to the ScBBox func (wb *WidgetBase) WinBBox() image.Rectangle { if !wb.HasSc() { @@ -572,7 +572,7 @@ func (wb *WidgetBase) WinBBox() image.Rectangle { return wb.Geom.TotalBBox.Add(wb.Scene.SceneGeom.Pos) } -// WinPos returns the RenderWin based position within the +// WinPos returns the RenderWindow based position within the // bounding box of the widget, where the x, y coordinates // are the proportion across the bounding box to use: // 0 = left / top, 1 = right / bottom diff --git a/core/renderwindow.go b/core/renderwindow.go index 8e8ac641a4..a34597cac7 100644 --- a/core/renderwindow.go +++ b/core/renderwindow.go @@ -51,15 +51,15 @@ var RenderWindowGlobalMu sync.Mutex // RenderWindow provides an outer "actual" window where everything is rendered, // and is the point of entry for all events coming in from user actions. // -// RenderWindow contents are all managed by the StageMgr that -// handles Main Stage elements such as WindowStage and DialogStage, which in -// turn manage their own stack of Popup Stage elements such as Menu, Tooltip, etc. +// RenderWindow contents are all managed by the [Stages] stack that +// handles main [Stage] elements such as [WindowStage] and [DialogStage], which in +// turn manage their own stack of popup stage elements such as menus and tooltips. // The contents of each Stage is provided by a Scene, containing Widgets, // and the Stage Pixels image is drawn to the RenderWindow in the RenderWindow method. // // Rendering is handled by the [system.Drawer]. It is akin to a window manager overlaying Go image bitmaps -// on top of each other in the proper order, based on the StageMgr stacking order. -// Sprites are managed by the Main Stage, as layered textures of the same size, +// on top of each other in the proper order, based on the [Stages] stacking order. +// Sprites are managed by the main stage, as layered textures of the same size, // to enable unlimited number packed into a few descriptors for standard sizes. type RenderWindow struct { // Flags are the flags associated with the window. @@ -76,9 +76,9 @@ type RenderWindow struct { // all the os-specific functions, including delivering events etc SystemWindow system.Window `json:"-" xml:"-"` - // MainStageMgr controlling the Main Stage elements in this window. - // The Render Context in this manager is the original source for all Stages. - MainStageMgr StageMgr + // Mains is the stack of main stages in this render window. + // The [RenderContext] in this manager is the original source for all Stages. + Mains Stages // RenderScenes are the Scene elements that draw directly to the window, // arranged in order, and continuously updated during Render. @@ -114,7 +114,7 @@ const ( // WindowResizing is atomic flag indicating window is resizing WindowResizing - // WindowGotFocus indicates that have we received RenderWin focus + // WindowGotFocus indicates that have we received RenderWindow focus WindowGotFocus // WindowSentShow have we sent the show event yet? Only ever sent ONCE @@ -152,7 +152,7 @@ func NewRenderWindow(name, title string, opts *system.NewWindowOptions) *RenderW var err error w.SystemWindow, err = system.TheApp.NewWindow(opts) if err != nil { - fmt.Printf("Cogent Core NewRenderWin error: %v \n", err) + fmt.Printf("Cogent Core NewRenderWindow error: %v \n", err) return nil } w.SystemWindow.SetName(title) @@ -163,7 +163,7 @@ func NewRenderWindow(name, title string, opts *system.NewWindowOptions) *RenderW defer rc.Unlock() w.SetFlag(true, WindowClosing) // ensure that everyone is closed first - for _, kv := range w.MainStageMgr.Stack.Order { + for _, kv := range w.Mains.Stack.Order { if kv.Value == nil || kv.Value.Scene == nil || kv.Value.Scene.This() == nil { continue } @@ -190,10 +190,10 @@ func NewRenderWindow(name, title string, opts *system.NewWindowOptions) *RenderW return w } -// MainScene returns the current MainStageMgr Top Scene, -// which is the current Window or FullWindow Dialog occupying the RenderWin. +// MainScene returns the current [RenderWindow.Mains] top Scene, +// which is the current window or full window dialog occupying the RenderWindow. func (w *RenderWindow) MainScene() *Scene { - top := w.MainStageMgr.Top() + top := w.Mains.Top() if top == nil { return nil } @@ -234,7 +234,7 @@ func ActivateExistingDialogWindow(data any) bool { return true } -// SetName sets name of this window and also the RenderWin, and applies any window +// SetName sets name of this window and also the RenderWindow, and applies any window // geometry settings associated with the new name if it is different from before func (w *RenderWindow) SetName(name string) { curnm := w.Name @@ -268,7 +268,7 @@ func (w *RenderWindow) SetTitle(title string) { } // SetStageTitle sets the title of the underlying SystemWin to the given stage title -// combined with the RenderWin title. +// combined with the RenderWindow title. func (w *RenderWindow) SetStageTitle(title string) { if title != w.Title { title = title + " • " + w.Title @@ -354,7 +354,7 @@ func (w *RenderWindow) Resized() { fmt.Printf("Win: %v skipped same-size Resized: %v\n", w.Name, curRg) } // still need to apply style even if size is same - for _, kv := range w.MainStageMgr.Stack.Order { + for _, kv := range w.Mains.Stack.Order { sc := kv.Value.Scene sc.ApplyStyleScene() } @@ -379,7 +379,7 @@ func (w *RenderWindow) Resized() { rc.SetFlag(true, RenderVisible) rc.LogicalDPI = w.LogicalDPI() // fmt.Printf("resize dpi: %v\n", w.LogicalDPI()) - w.MainStageMgr.Resize(rg) + w.Mains.Resize(rg) if DebugSettings.WinGeomTrace { log.Printf("WindowGeometry: recording from Resize\n") } @@ -389,7 +389,7 @@ func (w *RenderWindow) Resized() { // Raise requests that the window be at the top of the stack of windows, // and receive focus. If it is iconified, it will be de-iconified. This // is the only supported mechanism for de-iconifying. This also sets -// CurRenderWin to the window. +// CurrentRenderWindow to the window. func (w *RenderWindow) Raise() { w.SystemWindow.Raise() CurrentRenderWindow = w @@ -436,7 +436,7 @@ func (w *RenderWindow) Closed() { // IsClosed reports if the window has been closed func (w *RenderWindow) IsClosed() bool { - return w.SystemWindow.IsClosed() || w.MainStageMgr.Stack.Len() == 0 + return w.SystemWindow.IsClosed() || w.Mains.Stack.Len() == 0 } // SetCloseReqFunc sets the function that is called whenever there is a @@ -495,13 +495,13 @@ func (w *RenderWindow) SendCustomEvent(data any) { func (w *RenderWindow) SendWinFocusEvent(act events.WinActions) { // se := window.NewEvent(act) // se.Init() - // w.MainStageMgr.HandleEvent(se) + // w.Mains.HandleEvent(se) } ///////////////////////////////////////////////////////////////////////////// // Main Method: EventLoop -// EventLoop runs the event processing loop for the RenderWin -- grabs system +// EventLoop runs the event processing loop for the RenderWindow -- grabs system // events for the window and dispatches them to receiving nodes, and manages // other state etc (popups, etc). func (w *RenderWindow) EventLoop() { @@ -529,7 +529,7 @@ func (w *RenderWindow) EventLoop() { } WindowWait.Done() // our last act must be self destruction! - w.MainStageMgr.DeleteAll() + w.Mains.DeleteAll() } // HandleEvent processes given events.Event. @@ -556,7 +556,7 @@ func (w *RenderWindow) HandleEvent(e events.Event) { return } // fmt.Printf("got event type: %v: %v\n", et.BitIndexString(), evi) - w.MainStageMgr.MainHandleEvent(e) + w.Mains.MainHandleEvent(e) rc.Unlock() } @@ -656,7 +656,7 @@ const ( MaxSpritesPerTexture = 128 ) -// RenderParams are the key RenderWin params that determine if +// RenderParams are the key RenderWindow params that determine if // a scene needs to be restyled since last render, if these params change. type RenderParams struct { // LogicalDPI is the current logical dots-per-inch resolution of the @@ -706,7 +706,7 @@ type RenderContext struct { Geom math32.Geom2DInt // Mu is mutex for locking out rendering and any destructive updates. - // It is locked at the RenderWin level during rendering and + // It is locked at the RenderWindow level during rendering and // event processing to provide exclusive blocking of external updates. // Use AsyncLock from any outside routine to grab the lock before // doing modifications. @@ -731,7 +731,7 @@ func NewRenderContext() *RenderContext { return rc } -// Lock is called by RenderWin during RenderWindow and HandleEvent +// Lock is called by RenderWindow during RenderWindow and HandleEvent // when updating all widgets and rendering the screen. // Any outside access to window contents / scene must acquire this // lock first. In general, use AsyncLock to do this. @@ -764,7 +764,7 @@ func (rc *RenderContext) String() string { // RenderScenes are a list of Scene and direct rendering widgets, // compiled in rendering order, whose Pixels images are composed -// directly to the RenderWin window. +// directly to the RenderWindow window. type RenderScenes struct { // starting index for this set of Scenes @@ -884,13 +884,13 @@ func (sc *Scene) DirectRenderDraw(drw system.Drawer, idx int, flipY bool) { } ////////////////////////////////////////////////////////////////////// -// RenderWin methods +// RenderWindow methods func (w *RenderWindow) RenderContext() *RenderContext { - return w.MainStageMgr.RenderContext + return w.Mains.RenderContext } -// RenderWindow performs all rendering based on current StageMgr config. +// RenderWindow performs all rendering based on current Stages config. // It sets the Write lock on RenderContext Mutex, so nothing else can update // during this time. All other updates are done with a Read lock so they // won't interfere with each other. @@ -903,8 +903,8 @@ func (w *RenderWindow) RenderWindow() { }() rebuild := rc.HasFlag(RenderRebuild) - stageMods, sceneMods := w.MainStageMgr.UpdateAll() // handles all Scene / Widget updates! - top := w.MainStageMgr.Top() + stageMods, sceneMods := w.Mains.UpdateAll() // handles all Scene / Widget updates! + top := w.Mains.Top() if top == nil { return } @@ -953,7 +953,7 @@ func (w *RenderWindow) DrawScenes() { rs.SetImages(drw) // ensure all updated images copied - top := w.MainStageMgr.Top() + top := w.Mains.Top() if top.Sprites.Modified { top.Sprites.ConfigSprites(drw) } @@ -1015,7 +1015,7 @@ func (w *RenderWindow) GatherScenes() bool { rs.Reset() scIndex := make(map[Widget]int) - sm := &w.MainStageMgr + sm := &w.Mains n := sm.Stack.Len() if n == 0 { slog.Error("GatherScenes stack empty") @@ -1057,7 +1057,7 @@ func (w *RenderWindow) GatherScenes() bool { top.Sprites.Modified = true // ensure configured // then add the popups for the top main stage - for _, kv := range top.PopupMgr.Stack.Order { + for _, kv := range top.Popups.Stack.Order { st := kv.Value rs.Add(st.Scene, scIndex) if DebugSettings.WinRenderTrace { @@ -1069,14 +1069,14 @@ func (w *RenderWindow) GatherScenes() bool { } func (w *RenderWindow) SendShowEvents() { - w.MainStageMgr.SendShowEvents() + w.Mains.SendShowEvents() } //////////////////////////////////////////////////////////////////////////// // Scrim // A Scrim is just a dummy Widget used for rendering a Scrim. -// Only used for its type. Everything else managed by RenderWin. +// Only used for its type. Everything else managed by RenderWindow. type Scrim struct { WidgetBase } diff --git a/core/scene.go b/core/scene.go index 20897a0373..2c6564730c 100644 --- a/core/scene.go +++ b/core/scene.go @@ -26,14 +26,12 @@ import ( // - layimpl.go for layout // - style.go for style -// Scene contains a Widget tree, rooted in an embedded Frame layout, -// which renders into its Pixels image. -// The Scene is set in a Stage (pointer retained in Scene). -// Stage has a StageMgr manager for controlling things like Popups -// (Menus and Dialogs, etc). +// Scene contains a [Widget] tree, rooted in an embedded [Frame] layout, +// which renders into its [Scene.Pixels] image. The [Scene] is set in a +// [Stage], which the [Scene] has a pointer to. // -// Each Scene and Widget tree contains state specific to its particular usage -// within a given Stage and overall rendering context, representing the unit +// Each [Scene] contains state specific to its particular usage +// within a given [Stage] and overall rendering context, representing the unit // of rendering in the Cogent Core framework. // //core:no-new @@ -188,7 +186,7 @@ func (sc *Scene) HandleEvents() { CurrentRenderWindow.SetStageTitle(sc.Stage.Title) }) sc.OnClose(func(e events.Event) { - sm := sc.MainStageMgr() + sm := sc.Stage.Mains if sm == nil { return } @@ -210,33 +208,25 @@ func (sc *Scene) RenderContext() *RenderContext { if sc.Stage == nil { return nil } - sm := sc.MainStageMgr() + sm := sc.Stage.Mains if sm == nil { return nil } return sm.RenderContext } -// RenderWin returns the current render window for this scene. +// RenderWindow returns the current render window for this scene. // In general it is best to go through RenderContext instead of the window. // This will be nil prior to actual rendering. -func (sc *Scene) RenderWin() *RenderWindow { +func (sc *Scene) RenderWindow() *RenderWindow { if sc.Stage == nil { return nil } - sm := sc.MainStageMgr() + sm := sc.Stage.Mains if sm == nil { return nil } - return sm.RenderWin -} - -// MainStageMgr returns the Main StageMgr that typically lives in a RenderWin -// and manages all of the MainStage elements (Windows, Dialogs etc), -// which in turn manage their popups. This Scene could be in a popup -// or in a main stage. -func (sc *Scene) MainStageMgr() *StageMgr { - return sc.Stage.MainMgr + return sm.RenderWindow } // FitInWindow fits Scene geometry (pos, size) into given window geom. @@ -303,13 +293,13 @@ func (sc *Scene) Close() bool { if e.IsHandled() { return false } - mm := sc.Stage.MainMgr + mm := sc.Stage.Mains if mm == nil { return false // todo: needed, but not sure why } mm.DeleteStage(sc.Stage) - if sc.Stage.NewWindow && !TheApp.Platform().IsMobile() && !mm.RenderWin.Is(WindowClosing) && !mm.RenderWin.Is(WindowStopEventLoop) && !TheApp.IsQuitting() { - mm.RenderWin.CloseReq() + if sc.Stage.NewWindow && !TheApp.Platform().IsMobile() && !mm.RenderWindow.Is(WindowClosing) && !mm.RenderWindow.Is(WindowStopEventLoop) && !TheApp.IsQuitting() { + mm.RenderWindow.CloseReq() } return true } @@ -334,7 +324,7 @@ func (sc *Scene) UpdateTitle(title string) { if sc.Scene != nil { sc.Stage.Title = title } - if rw := sc.RenderWin(); rw != nil { + if rw := sc.RenderWindow(); rw != nil { rw.SetTitle(title) } if sc.Body != nil { @@ -417,7 +407,7 @@ const ( // ScImageUpdated indicates that the Scene's image has been updated // e.g., due to a render or a resize. This is reset by the - // global RenderWin rendering pass, so it knows whether it needs to + // global RenderWindow rendering pass, so it knows whether it needs to // copy the image up to the GPU or not. ScImageUpdated diff --git a/core/settings.go b/core/settings.go index a1f8de6b26..9aaf167f50 100644 --- a/core/settings.go +++ b/core/settings.go @@ -208,7 +208,7 @@ func SaveAllSettings() error { func UpdateAll() { //types:add gradient.Cache = nil // the cache is invalid now for _, w := range AllRenderWindows { - rctx := w.MainStageMgr.RenderContext + rctx := w.Mains.RenderContext rctx.LogicalDPI = w.LogicalDPI() rctx.SetFlag(true, RenderRebuild) // trigger full rebuild } diff --git a/core/sprite.go b/core/sprite.go index 732b889718..0a17537c34 100644 --- a/core/sprite.go +++ b/core/sprite.go @@ -265,8 +265,8 @@ func (ss *Sprites) DrawSprites(drw system.Drawer) { // SpriteEvent processes given event for any active sprites // func (ss *Sprites) SelSpriteEvent(evi events.Event) { -// // w.StageMgr.RenderContext.Mu.Lock() -// // defer w.StageMgr.RenderContext.Mu.Unlock() +// // w.Stages.RenderContext.Mu.Lock() +// // defer w.Stages.RenderContext.Mu.Unlock() // // et := evi.Type() // diff --git a/core/stage.go b/core/stage.go index 49e915cd6f..407a9e0347 100644 --- a/core/stage.go +++ b/core/stage.go @@ -20,20 +20,20 @@ import ( // Decor widgets that control display. // PopupStage are Menu, Tooltip, Snackbar, Chooser that are transitory // and simple, without additional decor. -// MainStages live in a StageMgr associated with a RenderWin window, -// and manage their own set of PopupStages via a PopupStageMgr. +// MainStages live in a [Stages] associated with a RenderWindow window, +// and manage their own set of PopupStages via another [Stages]. type StageTypes int32 //enums:enum const ( // WindowStage is a MainStage that displays a Scene in a full window. // One of these must be created first, as the primary App contents, - // and it typically persists throughout. It fills the RenderWin window. + // and it typically persists throughout. It fills the RenderWindow window. // Additional Windows can be created either within the same RenderWin - // (Mobile) or in separate RenderWin windows (Desktop, NewWindow). + // (Mobile) or in separate RenderWindow windows (Desktop, NewWindow). WindowStage StageTypes = iota // DialogStage is a MainStage that displays Scene in a smaller dialog window - // on top of a Window, or in its own RenderWin (on Desktop only). + // on top of a Window, or in its own RenderWindow (on Desktop only). // It can be Modal or not. DialogStage @@ -113,7 +113,7 @@ type Stage struct { //types:add -setters IgnoreEvents bool // NewWindow, if true, opens a WindowStage or DialogStage in its own - // separate operating system window (RenderWin). This is true by + // separate operating system window (RenderWindow). This is true by // default for WindowStage on non-mobile platforms, otherwise false. NewWindow bool @@ -140,28 +140,28 @@ type Stage struct { //types:add -setters // after a timeout duration. Timeout time.Duration - // Pos is the target position for Scene to be placed within RenderWin. + // Pos is the target position for Scene to be placed within RenderWindow. Pos image.Point - // Data is item represented by this main stage -- used for recycling windows + // Data is item represented by this main stage; used for recycling windows Data any - // If a Popup Stage, this is the Main Stage that owns it (via its PopupMgr) - // If a Main Stage, it points to itself. + // If a popup stage, this is the main stage that owns it (via its Popups). + // If a main stage, it points to itself. Main *Stage - // For Main stages, this is the manager for the popups within it (created - // specifically for the main stage). - // For Popups, this is the pointer to the PopupMgr within the - // Main Stage managing it. - PopupMgr *StageMgr `set:"-"` + // For main stages, this is the stack of the popups within it + // (created specifically for the main stage). + // For popups, this is the pointer to the Popups within the + // main stage managing it. + Popups *Stages `set:"-"` - // For all stages, this is the Main stage manager that lives in a RenderWin - // and manages the Main Scenes. - MainMgr *StageMgr `set:"-"` + // For all stages, this is the main [Stages] that lives in a [RenderWindow] + // and manages the main stages. + Mains *Stages `set:"-"` - // rendering context which has info about the RenderWin onto which we render. - // This should be used instead of the RenderWin itself for all relevant + // rendering context which has info about the RenderWindow onto which we render. + // This should be used instead of the RenderWindow itself for all relevant // rendering information. This is only available once a Stage is Run, // and must always be checked for nil. RenderContext *RenderContext @@ -211,21 +211,21 @@ func (st *Stage) SetScene(sc *Scene) *Stage { return st } -// SetMainMgr sets the MainMgr to given Main StageMgr (on RenderWin) +// SetMains sets the [Stage.Mains] to the given stack of main stages, // and also sets the RenderContext from that. -func (st *Stage) SetMainMgr(sm *StageMgr) *Stage { - st.MainMgr = sm +func (st *Stage) SetMains(sm *Stages) *Stage { + st.Mains = sm st.RenderContext = sm.RenderContext return st } -// SetPopupMgr sets the PopupMgr and MainMgr from the given *Main* Stage -// to which this PopupStage belongs. -func (st *Stage) SetPopupMgr(mainSt *Stage) *Stage { +// SetPopups sets the [Stage.Popups] and [Stage.Mains] from the given main +// stage to which this popup stage belongs. +func (st *Stage) SetPopups(mainSt *Stage) *Stage { st.Main = mainSt - st.MainMgr = mainSt.MainMgr - st.PopupMgr = mainSt.PopupMgr - st.RenderContext = st.MainMgr.RenderContext + st.Mains = mainSt.Mains + st.Popups = mainSt.Popups + st.RenderContext = st.Mains.RenderContext return st } @@ -238,7 +238,7 @@ func (st *Stage) SetType(typ StageTypes) *Stage { st.NewWindow = true } st.FullWindow = true - st.Modal = true // note: there is no global modal option between RenderWin windows + st.Modal = true // note: there is no global modal option between RenderWindow windows case DialogStage: st.Modal = true st.Scrim = true @@ -318,8 +318,8 @@ func (st *Stage) DoUpdate() (stageMods, sceneMods bool) { if st.Scene == nil { return } - if st.Type.IsMain() && st.PopupMgr != nil { - stageMods, sceneMods = st.PopupMgr.UpdateAll() + if st.Type.IsMain() && st.Popups != nil { + stageMods, sceneMods = st.Popups.UpdateAll() } scMods := st.Scene.DoUpdate() sceneMods = sceneMods || scMods @@ -329,19 +329,19 @@ func (st *Stage) DoUpdate() (stageMods, sceneMods bool) { return } -// Raise moves the Stage to the top of its main [StageMgr] +// Raise moves the Stage to the top of its main [Stages] // and raises the [RenderWindow] it is in if necessary. func (st *Stage) Raise() { - if st.MainMgr.RenderWin != CurrentRenderWindow { - st.MainMgr.RenderWin.Raise() + if st.Mains.RenderWindow != CurrentRenderWindow { + st.Mains.RenderWindow.Raise() } - st.MainMgr.MoveToTop(st) + st.Mains.MoveToTop(st) CurrentRenderWindow.SetStageTitle(st.Title) } func (st *Stage) Delete() { - if st.Type.IsMain() && st.PopupMgr != nil { - st.PopupMgr.DeleteAll() + if st.Type.IsMain() && st.Popups != nil { + st.Popups.DeleteAll() st.Sprites.Reset() } if st.Scene != nil { @@ -349,7 +349,7 @@ func (st *Stage) Delete() { } st.Scene = nil st.Main = nil - st.PopupMgr = nil - st.MainMgr = nil + st.Popups = nil + st.Mains = nil st.RenderContext = nil } diff --git a/core/stagemgr.go b/core/stages.go similarity index 84% rename from core/stagemgr.go rename to core/stages.go index 36672a622d..6973496613 100644 --- a/core/stagemgr.go +++ b/core/stages.go @@ -13,28 +13,28 @@ import ( "cogentcore.org/core/ordmap" ) -// StageMgr manages a stack of Stage elements -type StageMgr struct { //types:add +// Stages manages a stack of [Stages]. +type Stages struct { //types:add // stack of stages managed by this stage manager. Stack ordmap.Map[string, *Stage] `set:"-"` // Modified is set to true whenever the stack has been modified. - // This is cleared by the RenderWin each render cycle. + // This is cleared by the RenderWindow each render cycle. Modified bool // rendering context provides key rendering information and locking - // for the RenderWin in which the stages are running. - // the MainStageMgr within the RenderWin + // for the RenderWindow in which the stages are running. RenderContext *RenderContext // render window to which we are rendering. // rely on the RenderContext wherever possible. - RenderWin *RenderWindow + RenderWindow *RenderWindow // growing stack of viewing history of all stages. History []*Stage `set:"-"` - // Main is the Main Stage that owns this StageMgr, only set for Popup stages + // Main is the main stage that owns this [Stages]. + // This is only set for popup stages. Main *Stage // mutex protecting reading / updating of the Stack. @@ -43,7 +43,7 @@ type StageMgr struct { //types:add } // Top returns the top-most Stage in the Stack, under Read Lock -func (sm *StageMgr) Top() *Stage { +func (sm *Stages) Top() *Stage { sm.Mu.RLock() defer sm.Mu.RUnlock() @@ -56,7 +56,7 @@ func (sm *StageMgr) Top() *Stage { // TopOfType returns the top-most Stage in the Stack // of the given type, under Read Lock -func (sm *StageMgr) TopOfType(typ StageTypes) *Stage { +func (sm *Stages) TopOfType(typ StageTypes) *Stage { sm.Mu.RLock() defer sm.Mu.RUnlock() @@ -72,7 +72,7 @@ func (sm *StageMgr) TopOfType(typ StageTypes) *Stage { // TopNotType returns the top-most Stage in the Stack // that is NOT the given type, under Read Lock -func (sm *StageMgr) TopNotType(typ StageTypes) *Stage { +func (sm *Stages) TopNotType(typ StageTypes) *Stage { sm.Mu.RLock() defer sm.Mu.RUnlock() @@ -87,7 +87,7 @@ func (sm *StageMgr) TopNotType(typ StageTypes) *Stage { } // UniqueName returns unique name for given item -func (sm *StageMgr) UniqueName(nm string) string { +func (sm *Stages) UniqueName(nm string) string { ctr := 0 for _, kv := range sm.Stack.Order { if kv.Key == nm { @@ -101,7 +101,7 @@ func (sm *StageMgr) UniqueName(nm string) string { } // Push pushes a new Stage to top, under Write lock -func (sm *StageMgr) Push(st *Stage) { +func (sm *Stages) Push(st *Stage) { sm.Mu.Lock() defer sm.Mu.Unlock() @@ -111,7 +111,7 @@ func (sm *StageMgr) Push(st *Stage) { // Pop pops current Stage off the stack, returning it or nil if none. // It runs under Write lock. -func (sm *StageMgr) Pop() *Stage { +func (sm *Stages) Pop() *Stage { sm.Mu.Lock() defer sm.Mu.Unlock() @@ -129,7 +129,7 @@ func (sm *StageMgr) Pop() *Stage { // DeleteStage deletes given stage (removing from stack, calling Delete // on Stage), returning true if found. // It runs under Write lock. -func (sm *StageMgr) DeleteStage(st *Stage) bool { +func (sm *Stages) DeleteStage(st *Stage) bool { sm.Mu.Lock() defer sm.Mu.Unlock() @@ -150,7 +150,7 @@ func (sm *StageMgr) DeleteStage(st *Stage) bool { // calling Delete on Stage), returning true if found. // And also deletes all stages of the same type immediately below it. // It runs under Write lock. -func (sm *StageMgr) DeleteStageAndBelow(st *Stage) bool { +func (sm *Stages) DeleteStageAndBelow(st *Stage) bool { sm.Mu.Lock() defer sm.Mu.Unlock() @@ -179,7 +179,7 @@ func (sm *StageMgr) DeleteStageAndBelow(st *Stage) bool { // MoveToTop moves the given stage to the top of the stack, // returning true if found. It runs under Write lock. -func (sm *StageMgr) MoveToTop(st *Stage) bool { +func (sm *Stages) MoveToTop(st *Stage) bool { sm.Mu.Lock() defer sm.Mu.Unlock() @@ -199,7 +199,7 @@ func (sm *StageMgr) MoveToTop(st *Stage) bool { // PopType pops the top-most Stage of the given type of the stack, // returning it or nil if none. It runs under Write lock. -func (sm *StageMgr) PopType(typ StageTypes) *Stage { +func (sm *Stages) PopType(typ StageTypes) *Stage { sm.Mu.Lock() defer sm.Mu.Unlock() @@ -216,7 +216,7 @@ func (sm *StageMgr) PopType(typ StageTypes) *Stage { } // PopDelete pops current top--most Stage off the stack and calls Delete on it. -func (sm *StageMgr) PopDelete() { +func (sm *Stages) PopDelete() { st := sm.Pop() if st != nil { st.Delete() @@ -225,7 +225,7 @@ func (sm *StageMgr) PopDelete() { // PopDeleteType pops the top-most Stage of the given type off the stack // and calls Delete on it. -func (sm *StageMgr) PopDeleteType(typ StageTypes) { +func (sm *Stages) PopDeleteType(typ StageTypes) { st := sm.PopType(typ) if st != nil { st.Delete() @@ -235,7 +235,7 @@ func (sm *StageMgr) PopDeleteType(typ StageTypes) { // DeleteAll deletes all of the stages. // For when Stage with Popups is Deleted, or when a RenderWindow is closed. // requires outer RenderContext mutex! -func (sm *StageMgr) DeleteAll() { +func (sm *Stages) DeleteAll() { sm.Mu.Lock() defer sm.Mu.Unlock() @@ -253,7 +253,7 @@ func (sm *StageMgr) DeleteAll() { // Resize calls Resize on all stages within based on the given // window render geom. -func (sm *StageMgr) Resize(rg math32.Geom2DInt) { +func (sm *Stages) Resize(rg math32.Geom2DInt) { for _, kv := range sm.Stack.Order { st := kv.Value if st.Type == WindowStage || (st.Type == DialogStage && st.FullWindow) { @@ -269,9 +269,9 @@ func (sm *StageMgr) Resize(rg math32.Geom2DInt) { // and sceneMods = true if any Scenes have been modified. // Stage calls DoUpdate on its Scene, ensuring everything is updated at the // Widget level. If nothing is needed, nothing is done. -// This is called only during RenderWin.RenderWindow, +// This is called only during RenderWindow.RenderWindow, // under the global RenderContext.Mu Write lock so nothing else can happen. -func (sm *StageMgr) UpdateAll() (stageMods, sceneMods bool) { +func (sm *Stages) UpdateAll() (stageMods, sceneMods bool) { sm.Mu.Lock() defer sm.Mu.Unlock() @@ -291,7 +291,7 @@ func (sm *StageMgr) UpdateAll() (stageMods, sceneMods bool) { return } -func (sm *StageMgr) SendShowEvents() { +func (sm *Stages) SendShowEvents() { for _, kv := range sm.Stack.Order { st := kv.Value if st.Scene == nil { diff --git a/core/testing.go b/core/testing.go index 9b407bc07d..1a7806ca7b 100644 --- a/core/testing.go +++ b/core/testing.go @@ -70,7 +70,7 @@ func (b *Body) RunAndShowNewWindow() { // of the body necessary. It it used internally in test infrastructure, and // it should typically not be used by end users. func (b *Body) WaitNoEvents() { - rw := b.Scene.RenderWin() + rw := b.Scene.RenderWindow() rw.NoEventsChan = make(chan struct{}) <-rw.NoEventsChan rw.NoEventsChan = nil diff --git a/core/typegen.go b/core/typegen.go index 90fc4e5341..dd2247b9b8 100644 --- a/core/typegen.go +++ b/core/typegen.go @@ -448,12 +448,13 @@ func (t *Layout) New() tree.Node { return &Layout{} } func (t *Layout) SetTooltip(v string) *Layout { t.Tooltip = v; return t } // StretchType is the [types.Type] for [Stretch] -var StretchType = types.AddType(&types.Type{Name: "cogentcore.org/core/core.Stretch", IDName: "stretch", Doc: "Stretch adds a stretchy element that grows to fill all\navailable space. You can set [styles.Style.Grow] to change\nhow much it grows relative to other growing elements.", Embeds: []types.Field{{Name: "WidgetBase"}}, Instance: &Stretch{}}) +var StretchType = types.AddType(&types.Type{Name: "cogentcore.org/core/core.Stretch", IDName: "stretch", Doc: "Stretch adds a stretchy element that grows to fill all\navailable space. You can set [styles.Style.Grow] to change\nhow much it grows relative to other growing elements.\nIt does not render anything.", Embeds: []types.Field{{Name: "WidgetBase"}}, Instance: &Stretch{}}) // NewStretch adds a new [Stretch] with the given name to the given parent: // Stretch adds a stretchy element that grows to fill all // available space. You can set [styles.Style.Grow] to change // how much it grows relative to other growing elements. +// It does not render anything. func NewStretch(parent tree.Node, name ...string) *Stretch { return parent.NewChild(StretchType, name...).(*Stretch) } @@ -468,12 +469,13 @@ func (t *Stretch) New() tree.Node { return &Stretch{} } func (t *Stretch) SetTooltip(v string) *Stretch { t.Tooltip = v; return t } // SpaceType is the [types.Type] for [Space] -var SpaceType = types.AddType(&types.Type{Name: "cogentcore.org/core/core.Space", IDName: "space", Doc: "Space is a fixed size blank space, with\na default width of 1ch and a height of 1em.\nYou can set [styles.Style.Min] to change its size.", Embeds: []types.Field{{Name: "WidgetBase"}}, Instance: &Space{}}) +var SpaceType = types.AddType(&types.Type{Name: "cogentcore.org/core/core.Space", IDName: "space", Doc: "Space is a fixed size blank space, with\na default width of 1ch and a height of 1em.\nYou can set [styles.Style.Min] to change its size.\nIt does not render anything.", Embeds: []types.Field{{Name: "WidgetBase"}}, Instance: &Space{}}) // NewSpace adds a new [Space] with the given name to the given parent: // Space is a fixed size blank space, with // a default width of 1ch and a height of 1em. // You can set [styles.Style.Min] to change its size. +// It does not render anything. func NewSpace(parent tree.Node, name ...string) *Space { return parent.NewChild(SpaceType, name...).(*Space) } @@ -541,11 +543,11 @@ func (t *Meter) SetWidth(v units.Value) *Meter { t.Width = v; return t } func (t *Meter) SetTooltip(v string) *Meter { t.Tooltip = v; return t } // ScrimType is the [types.Type] for [Scrim] -var ScrimType = types.AddType(&types.Type{Name: "cogentcore.org/core/core.Scrim", IDName: "scrim", Doc: "A Scrim is just a dummy Widget used for rendering a Scrim.\nOnly used for its type. Everything else managed by RenderWin.", Embeds: []types.Field{{Name: "WidgetBase"}}, Instance: &Scrim{}}) +var ScrimType = types.AddType(&types.Type{Name: "cogentcore.org/core/core.Scrim", IDName: "scrim", Doc: "A Scrim is just a dummy Widget used for rendering a Scrim.\nOnly used for its type. Everything else managed by RenderWindow.", Embeds: []types.Field{{Name: "WidgetBase"}}, Instance: &Scrim{}}) // NewScrim adds a new [Scrim] with the given name to the given parent: // A Scrim is just a dummy Widget used for rendering a Scrim. -// Only used for its type. Everything else managed by RenderWin. +// Only used for its type. Everything else managed by RenderWindow. func NewScrim(parent tree.Node, name ...string) *Scrim { return parent.NewChild(ScrimType, name...).(*Scrim) } @@ -560,7 +562,7 @@ func (t *Scrim) New() tree.Node { return &Scrim{} } func (t *Scrim) SetTooltip(v string) *Scrim { t.Tooltip = v; return t } // SceneType is the [types.Type] for [Scene] -var SceneType = types.AddType(&types.Type{Name: "cogentcore.org/core/core.Scene", IDName: "scene", Doc: "Scene contains a Widget tree, rooted in an embedded Frame layout,\nwhich renders into its Pixels image.\nThe Scene is set in a Stage (pointer retained in Scene).\nStage has a StageMgr manager for controlling things like Popups\n(Menus and Dialogs, etc).\n\nEach Scene and Widget tree contains state specific to its particular usage\nwithin a given Stage and overall rendering context, representing the unit\nof rendering in the Cogent Core framework.", Directives: []types.Directive{{Tool: "core", Directive: "no-new"}, {Tool: "core", Directive: "embedder"}}, Embeds: []types.Field{{Name: "Frame"}}, Fields: []types.Field{{Name: "Bars", Doc: "Bars contains functions for constructing the control bars for this Scene,\nattached to different sides of a Scene (e.g., TopAppBar at Top,\nNavBar at Bottom, etc). Functions are called in forward order\nso first added are called first."}, {Name: "BarsInherit", Doc: "BarsInherit determines which of the Bars side functions are inherited\nfrom the context widget, for FullWindow Dialogs"}, {Name: "AppBars", Doc: "AppBars contains functions for configuring a top-level App toolbar,\n(e.g., TopAppBar) for elements contained within this Scene,\nthat should be represented in any app-level toolbar constructed\nfor this Scene."}, {Name: "Body", Doc: "Body provides the main contents of scenes that use control Bars\nto allow the main window contents to be specified separately\nfrom that dynamic control content. When constructing scenes using\na Body, you can operate directly on the [Body], which has wrappers\nfor most major Scene functions."}, {Name: "Data", Doc: "Data is the optional data value being represented by this scene.\nUsed e.g., for recycling views of a given item instead of creating new one."}, {Name: "SceneGeom", Doc: "Size and position relative to overall rendering context."}, {Name: "PaintContext", Doc: "paint context for rendering"}, {Name: "Pixels", Doc: "live pixels that we render into"}, {Name: "EventMgr", Doc: "event manager for this scene"}, {Name: "Stage", Doc: "current stage in which this Scene is set"}, {Name: "RenderBBoxHue", Doc: "RenderBBoxHue is current hue for rendering bounding box in ScRenderBBoxes mode"}, {Name: "SelectedWidget", Doc: "the currently selected/hovered widget through the inspect editor selection mode\nthat should be highlighted with a background color"}, {Name: "SelectedWidgetChan", Doc: "the channel on which the selected widget through the inspect editor\nselection mode is transmitted to the inspect editor after the user is done selecting"}, {Name: "LastRender", Doc: "LastRender captures key params from last render.\nIf different then a new ApplyStyleScene is needed."}, {Name: "StyleMu", Doc: "StyleMu is RW mutex protecting access to Style-related global vars"}, {Name: "ShowIter", Doc: "ShowIter counts up at start of showing a Scene\nto trigger Show event and other steps at start of first show"}, {Name: "ReRender", Doc: "ReRender items are re-rendered after the current pass"}, {Name: "hasShown", Doc: "hasShown is whether this scene has already been shown.\nThis is used to ensure that [events.Show] is only sent once."}, {Name: "DirectRenders", Doc: "DirectRenders are widgets that render directly to the RenderWin\ninstead of rendering into the Scene Pixels image."}}, Instance: &Scene{}}) +var SceneType = types.AddType(&types.Type{Name: "cogentcore.org/core/core.Scene", IDName: "scene", Doc: "Scene contains a [Widget] tree, rooted in an embedded [Frame] layout,\nwhich renders into its [Scene.Pixels] image. The [Scene] is set in a\n[Stage], which the [Scene] has a pointer to.\n\nEach [Scene] contains state specific to its particular usage\nwithin a given [Stage] and overall rendering context, representing the unit\nof rendering in the Cogent Core framework.", Directives: []types.Directive{{Tool: "core", Directive: "no-new"}, {Tool: "core", Directive: "embedder"}}, Embeds: []types.Field{{Name: "Frame"}}, Fields: []types.Field{{Name: "Bars", Doc: "Bars contains functions for constructing the control bars for this Scene,\nattached to different sides of a Scene (e.g., TopAppBar at Top,\nNavBar at Bottom, etc). Functions are called in forward order\nso first added are called first."}, {Name: "BarsInherit", Doc: "BarsInherit determines which of the Bars side functions are inherited\nfrom the context widget, for FullWindow Dialogs"}, {Name: "AppBars", Doc: "AppBars contains functions for configuring a top-level App toolbar,\n(e.g., TopAppBar) for elements contained within this Scene,\nthat should be represented in any app-level toolbar constructed\nfor this Scene."}, {Name: "Body", Doc: "Body provides the main contents of scenes that use control Bars\nto allow the main window contents to be specified separately\nfrom that dynamic control content. When constructing scenes using\na Body, you can operate directly on the [Body], which has wrappers\nfor most major Scene functions."}, {Name: "Data", Doc: "Data is the optional data value being represented by this scene.\nUsed e.g., for recycling views of a given item instead of creating new one."}, {Name: "SceneGeom", Doc: "Size and position relative to overall rendering context."}, {Name: "PaintContext", Doc: "paint context for rendering"}, {Name: "Pixels", Doc: "live pixels that we render into"}, {Name: "EventMgr", Doc: "event manager for this scene"}, {Name: "Stage", Doc: "current stage in which this Scene is set"}, {Name: "RenderBBoxHue", Doc: "RenderBBoxHue is current hue for rendering bounding box in ScRenderBBoxes mode"}, {Name: "SelectedWidget", Doc: "the currently selected/hovered widget through the inspect editor selection mode\nthat should be highlighted with a background color"}, {Name: "SelectedWidgetChan", Doc: "the channel on which the selected widget through the inspect editor\nselection mode is transmitted to the inspect editor after the user is done selecting"}, {Name: "LastRender", Doc: "LastRender captures key params from last render.\nIf different then a new ApplyStyleScene is needed."}, {Name: "StyleMu", Doc: "StyleMu is RW mutex protecting access to Style-related global vars"}, {Name: "ShowIter", Doc: "ShowIter counts up at start of showing a Scene\nto trigger Show event and other steps at start of first show"}, {Name: "ReRender", Doc: "ReRender items are re-rendered after the current pass"}, {Name: "hasShown", Doc: "hasShown is whether this scene has already been shown.\nThis is used to ensure that [events.Show] is only sent once."}, {Name: "DirectRenders", Doc: "DirectRenders are widgets that render directly to the RenderWin\ninstead of rendering into the Scene Pixels image."}}, Instance: &Scene{}}) // NodeType returns the [*types.Type] of [Scene] func (t *Scene) NodeType() *types.Type { return SceneType } @@ -954,7 +956,7 @@ func (t *Splits) AsSplits() *Splits { return t } // SetTooltip sets the [Splits.Tooltip] func (t *Splits) SetTooltip(v string) *Splits { t.Tooltip = v; return t } -var _ = types.AddType(&types.Type{Name: "cogentcore.org/core/core.Stage", IDName: "stage", Doc: "Stage is a container and manager for displaying a Scene\nin different functional ways, defined by StageTypes, in two categories:\nMain types (WindowStage and DialogStage) and Popup types\n(Menu, Tooltip, Snackbar, Chooser).", Directives: []types.Directive{{Tool: "types", Directive: "add", Args: []string{"-setters"}}}, Fields: []types.Field{{Name: "Type", Doc: "type of Stage: determines behavior and Styling"}, {Name: "Scene", Doc: "Scene contents of this Stage (what it displays)."}, {Name: "Context", Doc: "widget in another scene that requested this stage to be created\nand provides context (stage)"}, {Name: "Name", Doc: "Name is the name of the Stage, which is generally auto-set\nbased on the Scene Name."}, {Name: "Title", Doc: "Title is the title of the Stage, which is generally auto-set\nbased on the Scene Title. Used for title of WindowStage and\nDialogStage types."}, {Name: "Modal", Doc: "Modal, if true, blocks input to all other stages."}, {Name: "Scrim", Doc: "Scrim, if true, places a darkening scrim over other stages,\nif not a full window."}, {Name: "ClickOff", Doc: "ClickOff, if true, dismisses the Stage if user clicks anywhere\noff the Stage."}, {Name: "IgnoreEvents", Doc: "IgnoreEvents is whether to send no events to the stage and\njust pass them down to lower stages."}, {Name: "NewWindow", Doc: "NewWindow, if true, opens a WindowStage or DialogStage in its own\nseparate operating system window (RenderWin). This is true by\ndefault for WindowStage on non-mobile platforms, otherwise false."}, {Name: "FullWindow", Doc: "FullWindow, if NewWindow is false, makes DialogStages and\nWindowStages take up the entire window they are created in."}, {Name: "CloseOnBack", Doc: "CloseOnBack is whether to close the stage when the back button\nis pressed in the app bar. Otherwise, it goes back to the next\nstage but keeps this one open. This is on by default for\nDialogStages and off for WindowStages."}, {Name: "Closeable", Doc: "Closeable, if true, includes a close button for closing dialogs."}, {Name: "Movable", Doc: "Movable, if true, adds a handle titlebar Decor for moving dialogs."}, {Name: "Resizable", Doc: "Resizable, if true, adds a resize handle Decor for resizing dialogs."}, {Name: "Timeout", Doc: "Timeout, if greater than 0, results in a popup stages disappearing\nafter a timeout duration."}, {Name: "Pos", Doc: "Pos is the target position for Scene to be placed within RenderWin."}, {Name: "Data", Doc: "Data is item represented by this main stage -- used for recycling windows"}, {Name: "Main", Doc: "If a Popup Stage, this is the Main Stage that owns it (via its PopupMgr)\nIf a Main Stage, it points to itself."}, {Name: "PopupMgr", Doc: "For Main stages, this is the manager for the popups within it (created\nspecifically for the main stage).\nFor Popups, this is the pointer to the PopupMgr within the\nMain Stage managing it."}, {Name: "MainMgr", Doc: "For all stages, this is the Main stage manager that lives in a RenderWin\nand manages the Main Scenes."}, {Name: "RenderContext", Doc: "rendering context which has info about the RenderWin onto which we render.\nThis should be used instead of the RenderWin itself for all relevant\nrendering information. This is only available once a Stage is Run,\nand must always be checked for nil."}, {Name: "Sprites", Doc: "sprites are named images that are rendered last overlaying everything else."}, {Name: "SpriteDragging", Doc: "name of sprite that is being dragged -- sprite event function is responsible for setting this."}}}) +var _ = types.AddType(&types.Type{Name: "cogentcore.org/core/core.Stage", IDName: "stage", Doc: "Stage is a container and manager for displaying a Scene\nin different functional ways, defined by StageTypes, in two categories:\nMain types (WindowStage and DialogStage) and Popup types\n(Menu, Tooltip, Snackbar, Chooser).", Directives: []types.Directive{{Tool: "types", Directive: "add", Args: []string{"-setters"}}}, Fields: []types.Field{{Name: "Type", Doc: "type of Stage: determines behavior and Styling"}, {Name: "Scene", Doc: "Scene contents of this Stage (what it displays)."}, {Name: "Context", Doc: "widget in another scene that requested this stage to be created\nand provides context (stage)"}, {Name: "Name", Doc: "Name is the name of the Stage, which is generally auto-set\nbased on the Scene Name."}, {Name: "Title", Doc: "Title is the title of the Stage, which is generally auto-set\nbased on the Scene Title. Used for title of WindowStage and\nDialogStage types."}, {Name: "Modal", Doc: "Modal, if true, blocks input to all other stages."}, {Name: "Scrim", Doc: "Scrim, if true, places a darkening scrim over other stages,\nif not a full window."}, {Name: "ClickOff", Doc: "ClickOff, if true, dismisses the Stage if user clicks anywhere\noff the Stage."}, {Name: "IgnoreEvents", Doc: "IgnoreEvents is whether to send no events to the stage and\njust pass them down to lower stages."}, {Name: "NewWindow", Doc: "NewWindow, if true, opens a WindowStage or DialogStage in its own\nseparate operating system window (RenderWindow). This is true by\ndefault for WindowStage on non-mobile platforms, otherwise false."}, {Name: "FullWindow", Doc: "FullWindow, if NewWindow is false, makes DialogStages and\nWindowStages take up the entire window they are created in."}, {Name: "CloseOnBack", Doc: "CloseOnBack is whether to close the stage when the back button\nis pressed in the app bar. Otherwise, it goes back to the next\nstage but keeps this one open. This is on by default for\nDialogStages and off for WindowStages."}, {Name: "Closeable", Doc: "Closeable, if true, includes a close button for closing dialogs."}, {Name: "Movable", Doc: "Movable, if true, adds a handle titlebar Decor for moving dialogs."}, {Name: "Resizable", Doc: "Resizable, if true, adds a resize handle Decor for resizing dialogs."}, {Name: "Timeout", Doc: "Timeout, if greater than 0, results in a popup stages disappearing\nafter a timeout duration."}, {Name: "Pos", Doc: "Pos is the target position for Scene to be placed within RenderWindow."}, {Name: "Data", Doc: "Data is item represented by this main stage; used for recycling windows"}, {Name: "Main", Doc: "If a popup stage, this is the main stage that owns it (via its Popups).\nIf a main stage, it points to itself."}, {Name: "Popups", Doc: "For main stages, this is the stack of the popups within it\n(created specifically for the main stage).\nFor popups, this is the pointer to the Popups within the\nmain stage managing it."}, {Name: "Mains", Doc: "For all stages, this is the main [Stages] that lives in a [RenderWindow]\nand manages the main stages."}, {Name: "RenderContext", Doc: "rendering context which has info about the RenderWindow onto which we render.\nThis should be used instead of the RenderWindow itself for all relevant\nrendering information. This is only available once a Stage is Run,\nand must always be checked for nil."}, {Name: "Sprites", Doc: "sprites are named images that are rendered last overlaying everything else."}, {Name: "SpriteDragging", Doc: "name of sprite that is being dragged -- sprite event function is responsible for setting this."}}}) // SetContext sets the [Stage.Context]: // widget in another scene that requested this stage to be created @@ -989,7 +991,7 @@ func (t *Stage) SetIgnoreEvents(v bool) *Stage { t.IgnoreEvents = v; return t } // SetNewWindow sets the [Stage.NewWindow]: // NewWindow, if true, opens a WindowStage or DialogStage in its own -// separate operating system window (RenderWin). This is true by +// separate operating system window (RenderWindow). This is true by // default for WindowStage on non-mobile platforms, otherwise false. func (t *Stage) SetNewWindow(v bool) *Stage { t.NewWindow = v; return t } @@ -1023,21 +1025,21 @@ func (t *Stage) SetResizable(v bool) *Stage { t.Resizable = v; return t } func (t *Stage) SetTimeout(v time.Duration) *Stage { t.Timeout = v; return t } // SetPos sets the [Stage.Pos]: -// Pos is the target position for Scene to be placed within RenderWin. +// Pos is the target position for Scene to be placed within RenderWindow. func (t *Stage) SetPos(v image.Point) *Stage { t.Pos = v; return t } // SetData sets the [Stage.Data]: -// Data is item represented by this main stage -- used for recycling windows +// Data is item represented by this main stage; used for recycling windows func (t *Stage) SetData(v any) *Stage { t.Data = v; return t } // SetMain sets the [Stage.Main]: -// If a Popup Stage, this is the Main Stage that owns it (via its PopupMgr) -// If a Main Stage, it points to itself. +// If a popup stage, this is the main stage that owns it (via its Popups). +// If a main stage, it points to itself. func (t *Stage) SetMain(v *Stage) *Stage { t.Main = v; return t } // SetRenderContext sets the [Stage.RenderContext]: -// rendering context which has info about the RenderWin onto which we render. -// This should be used instead of the RenderWin itself for all relevant +// rendering context which has info about the RenderWindow onto which we render. +// This should be used instead of the RenderWindow itself for all relevant // rendering information. This is only available once a Stage is Run, // and must always be checked for nil. func (t *Stage) SetRenderContext(v *RenderContext) *Stage { t.RenderContext = v; return t } @@ -1050,7 +1052,7 @@ func (t *Stage) SetSprites(v Sprites) *Stage { t.Sprites = v; return t } // name of sprite that is being dragged -- sprite event function is responsible for setting this. func (t *Stage) SetSpriteDragging(v string) *Stage { t.SpriteDragging = v; return t } -var _ = types.AddType(&types.Type{Name: "cogentcore.org/core/core.StageMgr", IDName: "stage-mgr", Doc: "StageMgr manages a stack of Stage elements", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Fields: []types.Field{{Name: "Stack", Doc: "stack of stages managed by this stage manager."}, {Name: "Modified", Doc: "Modified is set to true whenever the stack has been modified.\nThis is cleared by the RenderWin each render cycle."}, {Name: "RenderContext", Doc: "rendering context provides key rendering information and locking\nfor the RenderWin in which the stages are running.\nthe MainStageMgr within the RenderWin"}, {Name: "RenderWin", Doc: "render window to which we are rendering.\nrely on the RenderContext wherever possible."}, {Name: "History", Doc: "growing stack of viewing history of all stages."}, {Name: "Main", Doc: "Main is the Main Stage that owns this StageMgr, only set for Popup stages"}, {Name: "Mu", Doc: "mutex protecting reading / updating of the Stack.\nDestructive stack updating gets a Write lock, else Read."}}}) +var _ = types.AddType(&types.Type{Name: "cogentcore.org/core/core.Stages", IDName: "stages", Doc: "Stages manages a stack of [Stages].", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Fields: []types.Field{{Name: "Stack", Doc: "stack of stages managed by this stage manager."}, {Name: "Modified", Doc: "Modified is set to true whenever the stack has been modified.\nThis is cleared by the RenderWindow each render cycle."}, {Name: "RenderContext", Doc: "rendering context provides key rendering information and locking\nfor the RenderWindow in which the stages are running."}, {Name: "RenderWindow", Doc: "render window to which we are rendering.\nrely on the RenderContext wherever possible."}, {Name: "History", Doc: "growing stack of viewing history of all stages."}, {Name: "Main", Doc: "Main is the main stage that owns this [Stages].\nThis is only set for popup stages."}, {Name: "Mu", Doc: "mutex protecting reading / updating of the Stack.\nDestructive stack updating gets a Write lock, else Read."}}}) // SVGType is the [types.Type] for [SVG] var SVGType = types.AddType(&types.Type{Name: "cogentcore.org/core/core.SVG", IDName: "svg", Doc: "SVG is a Widget that renders an [svg.SVG] object.\nIf it is not [states.ReadOnly], the user can pan and zoom the display.\nBy default, it is [states.ReadOnly]. See [views.ConfigSVGToolbar] for a\ntoolbar with panning, selecting, and I/O buttons.", Methods: []types.Method{{Name: "Open", Doc: "Open opens an XML-formatted SVG file", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"filename"}, Returns: []string{"error"}}, {Name: "SaveSVG", Doc: "SaveSVG saves the current SVG to an XML-encoded standard SVG file.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"filename"}, Returns: []string{"error"}}, {Name: "SavePNG", Doc: "SavePNG saves the current rendered SVG image to an PNG image file.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"filename"}, Returns: []string{"error"}}}, Embeds: []types.Field{{Name: "WidgetBase"}}, Fields: []types.Field{{Name: "SVG", Doc: "SVG is the SVG object associated with the element."}}, Instance: &SVG{}}) diff --git a/core/widget.go b/core/widget.go index ad98049f49..f23a5bd7ad 100644 --- a/core/widget.go +++ b/core/widget.go @@ -196,7 +196,7 @@ type Widget interface { // drw.SetFrameImage with a [vgpu.FrameBuffer] DirectRenderImage(drw system.Drawer, idx int) - // DirectRenderDraw draws the current image at index onto the RenderWin window, + // DirectRenderDraw draws the current image at index onto the RenderWindow window, // typically using drw.Copy, drw.Scale, or drw.Fill. // flipY is the default setting for whether the Y axis needs to be flipped during drawing, // which is typically passed along to the Copy or Scale methods. @@ -469,7 +469,7 @@ func (wb *WidgetBase) IsVisible() bool { func (wb *WidgetBase) DirectRenderImage(drw system.Drawer, idx int) { } -// DirectRenderDraw draws the current image at index onto the RenderWin window, +// DirectRenderDraw draws the current image at index onto the RenderWindow window, // typically using drw.Copy, drw.Scale, or drw.Fill. // flipY is the default setting for whether the Y axis needs to be flipped during drawing, // which is typically passed along to the Copy or Scale methods. diff --git a/core/windowgeometry.go b/core/windowgeometry.go index 6f492779bb..39416ebab3 100644 --- a/core/windowgeometry.go +++ b/core/windowgeometry.go @@ -150,7 +150,7 @@ func (mgr *WindowGeometrySaver) SaveLastSave() { os.WriteFile(pnm, b, 0644) } -// Open RenderWin Geom settings from Cogent Core standard settings directory +// Open RenderWindow Geom settings from Cogent Core standard settings directory // called under mutex or at start func (mgr *WindowGeometrySaver) Open() error { mgr.Init() @@ -183,7 +183,7 @@ func (mgr *WindowGeometrySaver) Open() error { return err } -// Save RenderWin Geom Settings to Cogent Core standard prefs directory +// Save RenderWindow Geom Settings to Cogent Core standard prefs directory // assumed to be under mutex and lock still func (mgr *WindowGeometrySaver) Save() error { if mgr.Geometries == nil { diff --git a/core/windowlists.go b/core/windowlists.go index 10205cea18..a0ceeff21d 100644 --- a/core/windowlists.go +++ b/core/windowlists.go @@ -71,9 +71,9 @@ func (wl *RenderWindowList) FindData(data any) (*RenderWindow, bool) { return nil, false } -// FindRenderWin finds window with given system.RenderWin on list -- returns +// FindRenderWindow finds window with given system.RenderWindow on list -- returns // window and true if found, nil, false otherwise. -func (wl *RenderWindowList) FindRenderWin(osw system.Window) (*RenderWindow, bool) { +func (wl *RenderWindowList) FindRenderWindow(osw system.Window) (*RenderWindow, bool) { RenderWindowGlobalMu.Lock() defer RenderWindowGlobalMu.Unlock() for _, wi := range *wl { diff --git a/docs/content/2-widgets/choosers.md b/docs/content/2-widgets/choosers.md index 4d287aef56..1e2ca93a0f 100644 --- a/docs/content/2-widgets/choosers.md +++ b/docs/content/2-widgets/choosers.md @@ -66,4 +66,4 @@ ch := core.NewChooser(parent).SetStrings("Newest", "Oldest", "Popular") ch.OnChange(func(e events.Event) { core.MessageSnackbar(parent, fmt.Sprintf("Sorting by %v", ch.CurrentItem.Value)) }) -``` \ No newline at end of file +``` diff --git a/examples/filetree/filetree.go b/examples/filetree/filetree.go index 4f6f00517d..8d300a316a 100644 --- a/examples/filetree/filetree.go +++ b/examples/filetree/filetree.go @@ -122,7 +122,7 @@ func (fb *FileBrowse) OpenPath(path core.Filename) { //types:add fb.SetName(pnm) fb.UpdateProject() fb.Files.OpenPath(root) - // win := fb.ParentRenderWin() + // win := fb.ParentRenderWindow() // if win != nil { // winm := "browser-" + pnm // win.SetName(winm) diff --git a/examples/svg/svg.go b/examples/svg/svg.go index 9194dc6ab9..8869039305 100644 --- a/examples/svg/svg.go +++ b/examples/svg/svg.go @@ -35,7 +35,7 @@ func OpenSVG(fnm string) { TheSVG.SetFullReRender() fmt.Printf("Opening: %v\n", CurFilename) TheSVG.OpenXML(core.Filename(CurFilename)) - SetZoom(TheSVG.ParentRenderWin().LogicalDPI() / 96.0) + SetZoom(TheSVG.ParentRenderWindow().LogicalDPI() / 96.0) SetTrans(0, 0) TheSVG.UpdateEnd(updt) } @@ -53,7 +53,7 @@ func main() { core.SetAppName("svg") - win := core.NewMainRenderWin("core-svg-viewer", "Cogent Core SVG Viewer", width, height) + win := core.NewMainRenderWindow("core-svg-viewer", "Cogent Core SVG Viewer", width, height) vp := win.WinScene() updt := vp.UpdateStart() @@ -188,10 +188,10 @@ func main() { fmen.Menu.AddSeparator("csep") fmen.Menu.AddButton(core.ActOpts{Label: "Close RenderWin", Shortcut: "Command+W"}, win.This(), func(recv, send tree.Node, sig int64, data any) { - win.RenderWin.Close() + win.RenderWindow.Close() }) - win.SetCloseCleanFunc(func(w *core.RenderWin) { + win.SetCloseCleanFunc(func(w *core.RenderWindow) { go core.Quit() // once main window is closed, quit }) diff --git a/video/video.go b/video/video.go index 5847209f89..854950ee89 100644 --- a/video/video.go +++ b/video/video.go @@ -79,7 +79,7 @@ func (v *Video) DirectRenderImage(drw system.Drawer, idx int) { drw.SetGoImage(idx, 0, frame, system.NoFlipY) } -// DirectRenderDraw draws the current image to RenderWin drawer +// DirectRenderDraw draws the current image to RenderWindow drawer func (v *Video) DirectRenderDraw(drw system.Drawer, idx int, flipY bool) { if !v.IsVisible() { return diff --git a/xyzview/scene.go b/xyzview/scene.go index e142ef851e..6f4384e674 100644 --- a/xyzview/scene.go +++ b/xyzview/scene.go @@ -97,7 +97,7 @@ func (sw *Scene) Config() { } // ConfigFrame configures the framebuffer for GPU rendering, -// using the RenderWin GPU and Device. +// using the RenderWindow GPU and Device. func (sw *Scene) ConfigFrame() { zp := image.Point{} sz := sw.Geom.Size.Actual.Content.ToPointFloor() @@ -116,7 +116,7 @@ func (sw *Scene) ConfigFrame() { doConfig = true } - win := sw.WidgetBase.Scene.EventMgr.RenderWin() + win := sw.WidgetBase.Scene.EventMgr.RenderWindow() if win == nil { return } @@ -152,7 +152,7 @@ func (sw *Scene) DirectRenderImage(drw system.Drawer, idx int) { drw.SetFrameImage(idx, sw.XYZ.Frame.Frames[0]) } -// DirectRenderDraw draws the current image to RenderWin drawer +// DirectRenderDraw draws the current image to RenderWindow drawer func (sw *Scene) DirectRenderDraw(drw system.Drawer, idx int, flipY bool) { if !sw.IsVisible() { return