egui

package
v2.0.0-dev0.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2024 License: BSD-3-Clause Imports: 22 Imported by: 18

README

Docs: GoDoc

egui handles all the GUI elements for a typical simulation, reducing boilerplate code in models.

The ra25 example has a fully updated implementation of this new GUI infrastructure.

Examples

Here's the start of the main ConfigGUI method:

// ConfigGUI configures the Cogent Core GUI interface for this simulation.
func (ss *Sim) ConfigGUI() *core.Window {
	title := "Leabra Random Associator"
	ss.GUI.MakeWindow(ss, "ra25", title, `This demonstrates a basic Leabra model. See <a href="https://github.com/emer/emergent">emergent on GitHub</a>.</p>`)
	ss.GUI.CycleUpdateInterval = 10
	ss.GUI.NetView.SetNet(ss.Net)

    // optionally reconfigure the netview:
	ss.GUI.NetView.Scene().Camera.Pose.Pos.Set(0, 1, 2.75) 
	ss.GUI.NetView.Scene().Camera.LookAt(math32.Vec3(0, 0, 0), math32.Vec3(0, 1, 0)) 
	ss.GUI.AddPlots(title, &ss.Logs) // automatically adds all configured plots

Toolbar Items

The ToolbarItem class provides toolbar configuration options, taking the place of core.ActOpts from existing code that operates directly at the GoGi level. The main differences are

  • The standard UpdateFunc options of either making the action active or inactive while the sim is running are now handled using Active: equi.ActiveStopped or egui.ActiveRunning or egui.ActiveAlways

  • The action function is just a simple Func: func() { with no args -- use context capture of closures to access any relevant state.

  • Use ss.GUI.UpdateWindow() inside any action function instead of vp.SetNeedsFullRender()

Here is a typical item:

    ss.GUI.AddToolbarItem(egui.ToolbarItem{Label: "Init", Icon: "update",
        Tooltip: "Initialize everything including network weights, and start over.  Also applies current params.",
        Active:  egui.ActiveStopped,
        Func: func() {
            ss.Init()
            ss.GUI.UpdateWindow()
        },
    })

For actions that take any significant amount of time, call the function in a separate routine using go, and use the GUI based variables:

    ss.GUI.AddToolbarItem(egui.ToolbarItem{Label: "Train",
        Icon:    "run",
        Tooltip: "Starts the network training, picking up from wherever it may have left off.  If not stopped, training will complete the specified number of Runs through the full number of Epochs of training, with testing automatically occuring at the specified interval.",
        Active:  egui.ActiveStopped,
        Func: func() {
            if !ss.GUI.IsRunning {
                ss.GUI.IsRunning = true
                ss.GUI.ToolBar.UpdateActions()
                go ss.Train()
            }
        },
    })

Here's an ActiveRunning case:

    ss.GUI.AddToolbarItem(egui.ToolbarItem{Label: "Stop",
        Icon:    "stop",
        Tooltip: "Interrupts running.  Hitting Train again will pick back up where it left off.",
        Active:  egui.ActiveRunning,
        Func: func() {
            ss.Stop()
        },
    })

Spike Rasters

	stb := ss.GUI.TabView.AddNewTab(core.KiT_Layout, "Spike Rasters").(*core.Layout)
	stb.Lay = core.LayoutVert
	stb.SetStretchMax()
	for _, lnm := range ss.Stats.Rasters {
		sr := ss.Stats.F32Tensor("Raster_" + lnm)
		ss.GUI.ConfigRasterGrid(stb, lnm, sr)
	}

Tensor Grid (e.g., of an Image)

	tg := ss.GUI.TabView.AddNewTab(etview.KiT_TensorGrid, "Image").(*etview.TensorGrid)
	tg.SetStretchMax()
	ss.GUI.SetGrid("Image", tg)
	tg.SetTensor(&ss.TrainEnv.Img.Tsr)

Activation-based Receptive Fields

	ss.GUI.AddActRFGridTabs(&ss.Stats.ActRFs)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigPlotFromLog

func ConfigPlotFromLog(title string, plt *eplot.Plot2D, lg *elog.Logs, key etime.ScopeKey)

Types

type GUI

type GUI struct {

	// how many cycles between updates of cycle-level plots
	CycleUpdateInterval int

	// true if the GUI is configured and running
	Active bool `view:"-"`

	// true if sim is running
	IsRunning bool `view:"-"`

	// flag to stop running
	StopNow bool `view:"-"`

	// plots by scope
	Plots map[etime.ScopeKey]*eplot.Plot2D

	// plots by scope
	TableViews map[etime.ScopeKey]*etview.TableView

	// tensor grid views by name -- used e.g., for Rasters or ActRFs -- use Grid(name) to access
	Grids map[string]*etview.TensorGrid

	// the view update for managing updates of netview
	ViewUpdate *netview.ViewUpdate `view:"-"`

	// net data for recording in nogui mode, if !nil
	NetData *netview.NetData `view:"-"`

	// displays Sim fields on left
	StructView *views.StructView `view:"-"`

	// tabs for different view elements: plots, rasters
	Tabs *core.Tabs `view:"-"`

	// Body is the content of the sim window
	Body *core.Body `view:"-"`
}

GUI manages all standard elements of a simulation Graphical User Interface

func (*GUI) AddActRFGridTabs

func (gui *GUI) AddActRFGridTabs(arfs *actrf.RFs)

AddActRFGridTabs adds tabs for each of the ActRFs.

func (*GUI) AddLooperCtrl

func (gui *GUI) AddLooperCtrl(tb *core.Toolbar, loops *looper.Manager, modes []etime.Modes)

AddLooperCtrl adds toolbar control for looper.Stack with Run, Step controls.

func (*GUI) AddNetView

func (gui *GUI) AddNetView(tabName string) *netview.NetView

AddNetView adds NetView in tab with given name

func (*GUI) AddPlots

func (gui *GUI) AddPlots(title string, lg *elog.Logs)

AddPlots adds plots based on the unique tables we have, currently assumes they should always be plotted

func (*GUI) AddTableView

func (gui *GUI) AddTableView(lg *elog.Logs, mode etime.Modes, time etime.Times)

AddTableView adds a table view of given log, typically particularly useful for Debug logs.

func (*GUI) AddToolbarItem

func (gui *GUI) AddToolbarItem(tb *core.Toolbar, item ToolbarItem)

AddToolbarItem adds a toolbar item but also checks when it be active in the UI

func (*GUI) ConfigRasterGrid

func (gui *GUI) ConfigRasterGrid(lay *core.Layout, laynm string, rast *etensor.Float32) *etview.TensorGrid

ConfigRasterGrid configures a raster grid for given layer name. Uses Raster_laynm and given Tensor that has the raster data.

func (*GUI) FinalizeGUI

func (gui *GUI) FinalizeGUI(closePrompt bool)

FinalizeGUI wraps the end functionality of the GUI

func (*GUI) GoUpdateWindow

func (gui *GUI) GoUpdateWindow()

GoUpdateWindow triggers an update on window body, for calling from a separate goroutine.

func (*GUI) Grid

func (gui *GUI) Grid(name string) *etview.TensorGrid

Grid gets tensor grid view of given name, creating if not yet made

func (*GUI) InitNetData

func (gui *GUI) InitNetData(net emer.Network, nrecs int)

InitNetData initializes the NetData object to record NetView data when the GUI is not active

func (*GUI) MakeBody

func (gui *GUI) MakeBody(sim any, appname, title, about string)

MakeBody returns default window Body content

func (*GUI) NetDataRecord

func (gui *GUI) NetDataRecord(netViewText string)

NetDataRecord records current netview data if InitNetData has been called and NetData exists.

func (*GUI) NewPlotTab

func (gui *GUI) NewPlotTab(key etime.ScopeKey, tabLabel string) *eplot.Plot2D

NewPlotTab adds a new plot with given key for Plots lookup and using given tab label. For ad-hoc plots, you can construct a ScopeKey from any two strings using etime.ScopeStr.

func (*GUI) Plot

func (gui *GUI) Plot(mode etime.Modes, time etime.Times) *eplot.Plot2D

Plot returns plot for mode, time scope

func (*GUI) PlotScope

func (gui *GUI) PlotScope(scope etime.ScopeKey) *eplot.Plot2D

PlotScope returns plot for given scope

func (*GUI) SaveActRFGrid

func (gui *GUI) SaveActRFGrid(tg *etview.TensorGrid, name string)

SaveActRFGrid stores the given TensorGrid in Grids under given name, and configures the grid view for ActRF viewing.

func (*GUI) SaveNetData

func (gui *GUI) SaveNetData(extra string)

SaveNetData saves NetData NetView data (if !nil) to a file named by the network name plus _extra name plus ".netdata.gz"

func (*GUI) SetGrid

func (gui *GUI) SetGrid(name string, tg *etview.TensorGrid)

SetGrid sets tensor grid view to given name

func (*GUI) SetPlot

func (gui *GUI) SetPlot(scope etime.ScopeKey, plt *eplot.Plot2D)

SetPlot stores given plot in Plots map

func (*GUI) Stopped

func (gui *GUI) Stopped()

Stopped is called when a run method stops running, from a separate goroutine (do not call from main event loop). Updates the IsRunning flag and toolbar.

func (*GUI) TableView

func (gui *GUI) TableView(mode etime.Modes, time etime.Times) *etview.TableView

TableView returns TableView for mode, time scope

func (*GUI) UpdateCyclePlot

func (gui *GUI) UpdateCyclePlot(mode etime.Modes, cycle int) *eplot.Plot2D

UpdateCyclePlot updates cycle plot for given mode. only updates every CycleUpdateInterval

func (*GUI) UpdateNetView

func (gui *GUI) UpdateNetView()

UpdateNetView updates the gui visualization of the network.

func (*GUI) UpdateNetViewWhenStopped

func (gui *GUI) UpdateNetViewWhenStopped()

UpdateNetViewWhenStopped updates the gui visualization of the network. when stopped either via stepping or user hitting stop button.

func (*GUI) UpdatePlot

func (gui *GUI) UpdatePlot(mode etime.Modes, time etime.Times) *eplot.Plot2D

UpdatePlot updates plot for given mode, time scope

func (*GUI) UpdatePlotScope

func (gui *GUI) UpdatePlotScope(scope etime.ScopeKey) *eplot.Plot2D

UpdatePlotScope updates plot at given scope

func (*GUI) UpdateTableView

func (gui *GUI) UpdateTableView(mode etime.Modes, time etime.Times) *etview.TableView

UpdateTableView updates TableView for given mode, time scope

func (*GUI) UpdateWindow

func (gui *GUI) UpdateWindow()

UpdateWindow triggers an update on window body, to be called from within the normal event processing loop. See GoUpdateWindow for version to call from separate goroutine.

func (*GUI) ViewActRFs

func (gui *GUI) ViewActRFs(atf *actrf.RFs)

ViewActRFs displays act rfs into tensor Grid views previously configured

type ToolGhosting

type ToolGhosting int32 //enums:enum

ToolGhosting the mode enum

const (
	ActiveStopped ToolGhosting = iota

	ActiveRunning

	ActiveAlways
)

The evaluation modes for when a tool bar can be clicked

const ToolGhostingN ToolGhosting = 3

ToolGhostingN is the highest valid value for type ToolGhosting, plus one.

func ToolGhostingValues

func ToolGhostingValues() []ToolGhosting

ToolGhostingValues returns all possible values for the type ToolGhosting.

func (ToolGhosting) Desc

func (i ToolGhosting) Desc() string

Desc returns the description of the ToolGhosting value.

func (ToolGhosting) Int64

func (i ToolGhosting) Int64() int64

Int64 returns the ToolGhosting value as an int64.

func (ToolGhosting) MarshalText

func (i ToolGhosting) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*ToolGhosting) SetInt64

func (i *ToolGhosting) SetInt64(in int64)

SetInt64 sets the ToolGhosting value from an int64.

func (*ToolGhosting) SetString

func (i *ToolGhosting) SetString(s string) error

SetString sets the ToolGhosting value from its string representation, and returns an error if the string is invalid.

func (ToolGhosting) String

func (i ToolGhosting) String() string

String returns the string representation of this ToolGhosting value.

func (*ToolGhosting) UnmarshalText

func (i *ToolGhosting) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (ToolGhosting) Values

func (i ToolGhosting) Values() []enums.Enum

Values returns all possible values for the type ToolGhosting.

type ToolbarItem

type ToolbarItem struct {
	Label   string
	Icon    icons.Icon
	Tooltip string
	Active  ToolGhosting
	Func    func()
}

ToolbarItem holds the configuration values for a toolbar item

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL