Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
410cdac
provide framework to support embedded readme in sims
angelajt Jan 15, 2025
f6492bd
WIP embedding images in README
angelajt Jan 15, 2025
4dd81bd
merge embedimages to leabra, clean up MakeBody
angelajt Jan 24, 2025
32e1d21
update to use emer/etensor and other temporary packages
kkoreilly Jan 28, 2025
1e71a5c
fix build errors
kkoreilly Jan 28, 2025
2e2122d
Merge branch 'leabra' into leabra
kkoreilly Jan 28, 2025
400250a
cleanup, use GetURLFromFS
angelajt Jan 30, 2025
86f46c0
remove toolchain from go.mod
angelajt Feb 1, 2025
a824ad2
move readme window to the side
angelajt Feb 1, 2025
eb21c6c
change SetTileSplits to SetSplits
angelajt Feb 1, 2025
5531243
Merge pull request #134 from angelajt/leabra
kkoreilly Feb 1, 2025
45097f6
wrapping implemented
Feb 1, 2025
324d8bd
Replaced final stylers to stylers: tbar and vbar
Feb 3, 2025
41ffed0
Merge pull request #135 from Qu1ncyRy4n/leabra
kkoreilly Feb 3, 2025
06471c1
working button, not on sidebar
Feb 14, 2025
82f1278
Beyond next widget capability
Qu1ncyRy4n Feb 21, 2025
1dbe131
Working Label-separate button highlights
Qu1ncyRy4n Feb 21, 2025
3ef42d6
Working pathed bhl + logic simplification
Qu1ncyRy4n Feb 22, 2025
8f4cbee
Notes removed, ready for PR
Qu1ncyRy4n Feb 28, 2025
b942816
removed debug comments, added fn desc
Qu1ncyRy4n Feb 28, 2025
c55ff0c
description added
Qu1ncyRy4n Feb 28, 2025
0feb88d
some requested changes made, need specification on urls
Qu1ncyRy4n Mar 4, 2025
0a83dd2
url and error handling implemented
Qu1ncyRy4n Mar 4, 2025
de4da65
Merge branch 'leabra' into button-highlighting
Qu1ncyRy4n Mar 4, 2025
693a601
nesting if-hasprefix removed
Qu1ncyRy4n Mar 4, 2025
02b79b6
goimport, if focusset, cut text fixes
Qu1ncyRy4n Mar 7, 2025
1fc133d
Merge pull request #136 from Qu1ncyRy4n/button-highlighting
kkoreilly Mar 7, 2025
872823f
implement answer boxes for questions, copy button
angelajt May 16, 2025
251cc74
change question to sim-question
angelajt Jul 9, 2025
ac11bbc
remove styler for text editor
angelajt Jul 9, 2025
d118e0b
change button to sentence case, md formatting for answers
angelajt Jul 9, 2025
c99504b
Merge pull request #137 from angelajt/question_boxes
kkoreilly Jul 9, 2025
d279c30
egui: remove erroneous extra space in AddTableView
kkoreilly Jul 9, 2025
cc9d7e5
revert etensor import path
kkoreilly Jul 21, 2025
b8717de
merge from main into leabra-merge
kkoreilly Jul 21, 2025
e2e022c
egui: fix errors with leabra-merge
kkoreilly Jul 21, 2025
8c5da6b
egui: fix splits for addReadme
kkoreilly Jul 21, 2025
52708b2
egui: more updating
kkoreilly Jul 21, 2025
727125a
egui: fix splits for non-readme
kkoreilly Jul 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 131 additions & 4 deletions egui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@ package egui
//go:generate core generate -add-types

import (
"embed"
"fmt"
"io/fs"
"net/http"
"strings"
"sync"

"cogentcore.org/core/base/errors"
"cogentcore.org/core/base/fileinfo/mimedata"
"cogentcore.org/core/base/labels"
"cogentcore.org/core/core"
"cogentcore.org/core/enums"
"cogentcore.org/core/events"
"cogentcore.org/core/htmlcore"
"cogentcore.org/core/styles"
"cogentcore.org/core/styles/abilities"
"cogentcore.org/core/system"
"cogentcore.org/core/text/textcore"
"cogentcore.org/core/tree"
_ "cogentcore.org/lab/gosl/slbool/slboolcore" // include to get gui views
"cogentcore.org/lab/lab"
Expand All @@ -40,6 +51,9 @@ type GUI struct {
// Body is the entire content of the sim window.
Body *core.Body `display:"-"`

// Readme is the sim readme frame
Readme *core.Frame `display:"-"`

// OnStop is called when running is stopped through the GUI,
// via the Stopped method. It should update the network view for example.
OnStop func(mode, level enums.Enum)
Expand Down Expand Up @@ -136,8 +150,8 @@ func NewGUIBody(b tree.Node, sim any, fsroot fs.FS, appname, title, about string
// a [core.Form] editor of the given sim object, and a filetree for the data filesystem
// rooted at fsroot, and with given app name, title, and about information.
// The first arg is an optional existing [core.Body] to make into: if nil then
// a new body is made first.
func (gui *GUI) MakeBody(b tree.Node, sim any, fsroot fs.FS, appname, title, about string) {
// a new body is made first. It takes an optional fs with a README.md file.
func (gui *GUI) MakeBody(b tree.Node, sim any, fsroot fs.FS, appname, title, about string, readme ...embed.FS) {
gui.StopLevel = etime.NoTime // corresponds to the first level typically
core.NoSentenceCaseFor = append(core.NoSentenceCaseFor, "github.com/emer")
if b == nil {
Expand Down Expand Up @@ -183,8 +197,121 @@ func (gui *GUI) MakeBody(b tree.Node, sim any, fsroot fs.FS, appname, title, abo
gui.CycleUpdateInterval = 10
gui.UpdateFiles()
gui.Files.Tabber = tabs
split.SetTiles(core.TileSplit, core.TileSpan)
split.SetSplits(.2, .5, .8)

if len(readme) > 0 {
gui.addReadme(readme[0], split)
} else {
split.SetTiles(core.TileSplit, core.TileSpan)
split.SetSplits(.2, .5, .8)
}
}

func (gui *GUI) addReadme(readmefs embed.FS, split *core.Splits) {
gui.Readme = core.NewFrame(split)
gui.Readme.Name = "readme"

split.SetTiles(core.TileSplit, core.TileSpan, core.TileSpan)
split.SetSplits(.2, .5, .5, .3)

ctx := htmlcore.NewContext()

ctx.GetURL = func(rawURL string) (*http.Response, error) {
return htmlcore.GetURLFromFS(readmefs, rawURL)
}

ctx.AddWikilinkHandler(gui.readmeWikilink("sim"))

ctx.OpenURL = gui.readmeOpenURL

eds := []*textcore.Editor{}

ctx.ElementHandlers["sim-question"] = func(ctx *htmlcore.Context) bool {
ed := textcore.NewEditor(ctx.BlockParent)
ed.Lines.Settings.LineNumbers = false
eds = append(eds, ed)
id := htmlcore.GetAttr(ctx.Node, "id")
ed.SetName(id)
return true
}

core.NewButton(gui.Readme).SetText("Copy answers").OnClick(func(e events.Event) {
clipboard := gui.Readme.Clipboard()
var ab strings.Builder
for _, ed := range eds {
ab.WriteString("## Question " + ed.Name + "\n" + ed.Lines.String() + "\n")
}
answers := ab.String()
md := mimedata.NewText(answers)
clipboard.Write(md)
core.MessageSnackbar(gui.Body, "Answers copied to clipboard")
})

readme, err := readmefs.ReadFile("README.md")

if errors.Log(err) == nil {
htmlcore.ReadMDString(ctx, gui.Readme, string(readme))
}
}

func (gui *GUI) readmeWikilink(prefix string) htmlcore.WikilinkHandler {
return func(text string) (url string, label string) {
if !strings.HasPrefix(text, prefix+":") {
return "", ""
}
text = strings.TrimPrefix(text, prefix+":")
url = prefix + "://" + text
if strings.Contains(text, "/") {
_, text, _ = strings.Cut(text, "/")
}
return url, text
}
}

// readmeOpenURL Parses URL, highlights linked button or opens URL
func (gui *GUI) readmeOpenURL(url string) {
focusSet := false
if !strings.HasPrefix(url, "sim://") {
system.TheApp.OpenURL(url)
return
}

text := strings.TrimPrefix(url, "sim://")
var pathPrefix string = ""
hasPath := false
if strings.Contains(text, "/") {
pathPrefix, text, hasPath = strings.Cut(text, "/")
}

gui.Body.Scene.WidgetWalkDown(func(cw core.Widget, cwb *core.WidgetBase) bool {
if focusSet {
return tree.Break
}
if !hasPath && !cwb.IsDisplayable() {
return tree.Break
}
if hasPath && !strings.Contains(cw.AsTree().Path(), pathPrefix) {
return tree.Continue
}
label := labels.ToLabel(cw)
if !strings.EqualFold(label, text) {
return tree.Continue
}
if cwb.AbilityIs(abilities.Focusable) {
cwb.SetFocus()
focusSet = true
return tree.Break
}
next := core.AsWidget(tree.Next(cwb))
if next.AbilityIs(abilities.Focusable) {
next.SetFocus()
focusSet = true
return tree.Break
}
return tree.Continue
})
if !focusSet {
core.ErrorSnackbar(gui.Body, fmt.Errorf("invalid sim url %q", url))
}
}

// AddNetView adds NetView in tab with given name
Expand Down
2 changes: 1 addition & 1 deletion egui/plots.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (gui *GUI) AddTableView(lg *elog.Logs, mode etime.Modes, time etime.Times)
return nil
}

tt, _ := gui.Tabs.NewTab(mode.String() + " " + time.String() + " ")
tt, _ := gui.Tabs.NewTab(mode.String() + " " + time.String())
tv := tensorcore.NewTable(tt)
gui.TableViews[key] = tv
tv.SetReadOnly(true)
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ require (
github.com/cogentcore/webgpu v0.23.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dlclark/regexp2 v1.11.0 // indirect
github.com/ericchiang/css v1.3.0 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
github.com/go-text/typesetting v0.3.1-0.20250402122313-7a0f05577ff5 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/h2non/filetype v1.1.3 // indirect
github.com/hack-pad/go-indexeddb v0.3.2 // indirect
Expand Down
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/ericchiang/css v1.3.0 h1:e0vS+vpujMjtT3/SYu7qTHn1LVzXWcLCCDjlfq3YlLY=
github.com/ericchiang/css v1.3.0/go.mod h1:sVSdL+MFR9Q4cKJMQzpIkHIDOLiK+7Wmjjhq7D+MubA=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
Expand All @@ -49,6 +51,9 @@ github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066 h1:qCuYC
github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b h1:EY/KpStFl60qA17CptGXhwfZ+k1sFNJIUNR8DdbcuUk=
github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
Expand Down Expand Up @@ -127,19 +132,26 @@ golang.org/x/image v0.25.0 h1:Y6uW6rH1y5y/LK1J8BPWZtr6yZ7hrsy6hFrXjgsc2fQ=
golang.org/x/image v0.25.0/go.mod h1:tCAmOEGthTtkalusGp1g3xa2gke8J6c2N565dTyl9Rs=
golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=
golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
5 changes: 4 additions & 1 deletion netview/netview.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (nv *NetView) Init() {
})

tree.AddChildAt(nv, "tbar", func(w *core.Toolbar) {
w.FinalStyler(func(s *styles.Style) {
w.Styler(func(s *styles.Style) {
s.Wrap = true
})
w.Maker(nv.MakeToolbar)
Expand Down Expand Up @@ -139,6 +139,9 @@ func (nv *NetView) Init() {
})
})
tree.AddChildAt(nv, "vbar", func(w *core.Toolbar) {
w.Styler(func(s *styles.Style) {
s.Wrap = true
})
w.Maker(nv.MakeViewbar)
})
}
Expand Down