Apply go fix modernizations
This commit is contained in:
@@ -98,7 +98,7 @@ func main() {
|
|||||||
draw.Draw(img, img.Bounds(), &image.Uniform{bg}, image.Point{}, draw.Src)
|
draw.Draw(img, img.Bounds(), &image.Uniform{bg}, image.Point{}, draw.Src)
|
||||||
charW := font.MeasureString(stripFont, "0").Ceil()
|
charW := font.MeasureString(stripFont, "0").Ceil()
|
||||||
pad := 8
|
pad := 8
|
||||||
for e := 0; e < count; e++ {
|
for e := range count {
|
||||||
ci := p.Start + e
|
ci := p.Start + e
|
||||||
ch := channels[ci]
|
ch := channels[ci]
|
||||||
cc := ch.Color
|
cc := ch.Color
|
||||||
@@ -107,10 +107,7 @@ func main() {
|
|||||||
valStr := fmt.Sprintf("%03d %02x", ch.Value, ch.Value)
|
valStr := fmt.Sprintf("%03d %02x", ch.Value, ch.Value)
|
||||||
nameW := font.MeasureString(stripFont, ch.Name).Ceil()
|
nameW := font.MeasureString(stripFont, ch.Name).Ceil()
|
||||||
valW := font.MeasureString(stripFont, valStr).Ceil()
|
valW := font.MeasureString(stripFont, valStr).Ceil()
|
||||||
textW := nameW
|
textW := max(valW, nameW)
|
||||||
if valW > textW {
|
|
||||||
textW = valW
|
|
||||||
}
|
|
||||||
x0 := mid - textW/2 - pad
|
x0 := mid - textW/2 - pad
|
||||||
x1 := mid + textW/2 + pad
|
x1 := mid + textW/2 + pad
|
||||||
|
|
||||||
@@ -155,8 +152,8 @@ func main() {
|
|||||||
if i == page {
|
if i == page {
|
||||||
img := image.NewRGBA(image.Rect(0, 0, sz, sz))
|
img := image.NewRGBA(image.Rect(0, 0, sz, sz))
|
||||||
draw.Draw(img, img.Bounds(), txt, image.Point{}, draw.Src)
|
draw.Draw(img, img.Bounds(), txt, image.Point{}, draw.Src)
|
||||||
for y := 0; y < sz; y++ {
|
for y := range sz {
|
||||||
for x := 0; x < sz; x++ {
|
for x := range sz {
|
||||||
if x < b || x >= sz-b || y < b || y >= sz-b {
|
if x < b || x >= sz-b || y < b || y >= sz-b {
|
||||||
img.Set(x, y, color.RGBA{255, 255, 255, 255})
|
img.Set(x, y, color.RGBA{255, 255, 255, 255})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
type Show struct {
|
type Show struct {
|
||||||
@@ -30,11 +32,12 @@ type Trigger struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Trigger) String() string {
|
func (t *Trigger) String() string {
|
||||||
s := fmt.Sprintf("%s/%s ->", t.Source.Block, t.Source.Signal)
|
var s strings.Builder
|
||||||
|
s.WriteString(fmt.Sprintf("%s/%s ->", t.Source.Block, t.Source.Signal))
|
||||||
for _, target := range t.Targets {
|
for _, target := range t.Targets {
|
||||||
s += fmt.Sprintf(" %s/%s", target.Block, target.Hook)
|
s.WriteString(fmt.Sprintf(" %s/%s", target.Block, target.Hook))
|
||||||
}
|
}
|
||||||
return s
|
return s.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
type TriggerSource struct {
|
type TriggerSource struct {
|
||||||
|
|||||||
@@ -49,12 +49,7 @@ func (t *TimelineTrack) cellTypeAt(index int, types ...CellType) bool {
|
|||||||
if index < 0 || index >= len(t.Cells) {
|
if index < 0 || index >= len(t.Cells) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, typ := range types {
|
return slices.Contains(types, t.Cells[index].Type)
|
||||||
if t.Cells[index].Type == typ {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TimelineCell) String() string {
|
func (c *TimelineCell) String() string {
|
||||||
@@ -98,14 +93,15 @@ func (g exclusiveGroup) satisfied(tracks []*TimelineTrack) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g exclusiveGroup) String() string {
|
func (g exclusiveGroup) String() string {
|
||||||
s := "exclusive("
|
var s strings.Builder
|
||||||
|
s.WriteString("exclusive(")
|
||||||
for i, m := range g.members {
|
for i, m := range g.members {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
s += ", "
|
s.WriteString(", ")
|
||||||
}
|
}
|
||||||
s += m.String()
|
s.WriteString(m.String())
|
||||||
}
|
}
|
||||||
return s + ")"
|
return s.String() + ")"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tl *Timeline) debugf(format string, args ...any) {
|
func (tl *Timeline) debugf(format string, args ...any) {
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := uint8(0); i < 8; i++ {
|
for i := range uint8(8) {
|
||||||
updateLCD(out, i)
|
updateLCD(out, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,13 +38,13 @@ var ModelXL = Model{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var ModelPlus = Model{
|
var ModelPlus = Model{
|
||||||
Name: "Plus",
|
Name: "Plus",
|
||||||
Keys: 8,
|
Keys: 8,
|
||||||
KeyRows: 2,
|
KeyRows: 2,
|
||||||
KeyCols: 4,
|
KeyCols: 4,
|
||||||
KeySize: 120,
|
KeySize: 120,
|
||||||
Encoders: 4,
|
Encoders: 4,
|
||||||
LCDWidth: 800,
|
LCDWidth: 800,
|
||||||
LCDHeight: 100,
|
LCDHeight: 100,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,10 +101,10 @@ func OpenModel(m *Model) (*Device, error) {
|
|||||||
return &Device{dev: dev, model: m}, nil
|
return &Device{dev: dev, model: m}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) Model() *Model { return d.model }
|
func (d *Device) Model() *Model { return d.model }
|
||||||
func (d *Device) Close() error { return d.dev.Close() }
|
func (d *Device) Close() error { return d.dev.Close() }
|
||||||
func (d *Device) SerialNumber() string { return d.dev.SerialNumber() }
|
func (d *Device) SerialNumber() string { return d.dev.SerialNumber() }
|
||||||
func (d *Device) Product() string { return d.dev.Product() }
|
func (d *Device) Product() string { return d.dev.Product() }
|
||||||
|
|
||||||
func (d *Device) FirmwareVersion() (string, error) {
|
func (d *Device) FirmwareVersion() (string, error) {
|
||||||
buf, err := d.dev.GetFeatureReport(5)
|
buf, err := d.dev.GetFeatureReport(5)
|
||||||
@@ -150,8 +150,8 @@ func (d *Device) SetKeyImage(key int, img image.Image) error {
|
|||||||
var src image.Image = scaled
|
var src image.Image = scaled
|
||||||
if d.model.FlipKeys {
|
if d.model.FlipKeys {
|
||||||
flipped := image.NewRGBA(scaled.Bounds())
|
flipped := image.NewRGBA(scaled.Bounds())
|
||||||
for y := 0; y < sz; y++ {
|
for y := range sz {
|
||||||
for x := 0; x < sz; x++ {
|
for x := range sz {
|
||||||
flipped.Set(sz-1-x, sz-1-y, scaled.At(x, y))
|
flipped.Set(sz-1-x, sz-1-y, scaled.At(x, y))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,11 +108,11 @@ type TextSpan struct {
|
|||||||
func DrawOutlinedSpans(img *image.RGBA, face font.Face, defaultOutline color.Color, thickness int, lines ...[]TextSpan) {
|
func DrawOutlinedSpans(img *image.RGBA, face font.Face, defaultOutline color.Color, thickness int, lines ...[]TextSpan) {
|
||||||
var full []string
|
var full []string
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
s := ""
|
var s strings.Builder
|
||||||
for _, span := range line {
|
for _, span := range line {
|
||||||
s += span.Text
|
s.WriteString(span.Text)
|
||||||
}
|
}
|
||||||
full = append(full, s)
|
full = append(full, s.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
metrics := face.Metrics()
|
metrics := face.Metrics()
|
||||||
|
|||||||
Reference in New Issue
Block a user