Skip to content

Commit

Permalink
better Class setting: just AddClass with var-arg
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Apr 5, 2024
1 parent 7626834 commit 50e40bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
6 changes: 2 additions & 4 deletions emer/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ type Layer interface {
// SetName sets name of layer
SetName(nm string)

// SetClass sets CSS-style class name(s) for this layer (space-separated if multiple)
SetClass(cls string)

// AddClass adds a CSS-style class name(s) for this layer,
// ensuring that it is not a duplicate, and properly space separated.
AddClass(cls string)
// Returns Layer so it can be chained to set other properties too
AddClass(cls ...string) Layer

// IsOff returns true if layer has been turned Off (lesioned) -- for experimentation
IsOff() bool
Expand Down
7 changes: 2 additions & 5 deletions emer/prjn.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,10 @@ type Prjn interface {
// Connect sets the basic connection parameters for this projection (send, recv, pattern, and type)
// Connect(send, recv Layer, pat prjn.Pattern, typ PrjnType)

// SetClass sets CSS-style class name(s) for this projection (space-separated if multiple)
// Returns Prjn so it can be chained to set other properties too
SetClass(cls string) Prjn

// AddClass adds a CSS-style class name(s) for this prjn,
// ensuring that it is not a duplicate, and properly space separated.
AddClass(cls string)
// Returns Prjn so it can be chained to set other properties too
AddClass(cls ...string) Prjn

// Label satisfies the gi.Labeler interface for getting the name of objects generically
Label() string
Expand Down
11 changes: 6 additions & 5 deletions params/styler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ type StylerObj interface {
Object() any
}

// AddClass adds given class to current class string,
// AddClass adds given class(es) to current class string,
// ensuring it is not a duplicate of existing, and properly
// adding spaces
func AddClass(cur, class string) string {
if ClassMatch(cur, class) {
func AddClass(cur string, class ...string) string {
cls := strings.Join(class, " ")
if ClassMatch(cur, cls) {
return cur
}
cur = strings.TrimSpace(cur)
if len(cur) == 0 {
return class
return cls
}
return cur + " " + class
return cur + " " + cls
}

0 comments on commit 50e40bf

Please sign in to comment.