Skip to content

Commit

Permalink
feat: add transparent background option
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMarble committed Jan 25, 2022
1 parent fee7db2 commit 8c50488
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions internal/zmk-layout-viewer/layout-viewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,25 @@ func Generate(board string, file string, trasnparent bool, output string) error

for _, layer := range ast.Sections[len(ast.Sections)-1].Device.Keymap.Layers {
for _, layout := range l {
drawLayer(layer, &layout, output)
err = drawLayer(layer, &layout, output, trasnparent)
if err != nil {
return err
}
}
}
} else {
for _, layout := range l {
drawLayer(nil, &layout, output)
err = drawLayer(nil, &layout, output, trasnparent)
if err != nil {
return err
}
}
}

return nil
}

func drawLayer(layer *keymap.Layer, layout *keyboard.Layout, output string) error {
func drawLayer(layer *keymap.Layer, layout *keyboard.Layout, output string, transparent bool) error {
mx := maxX(layout.Layout) + 1
my := maxY(layout.Layout) + 1

Expand All @@ -71,8 +77,10 @@ func drawLayer(layer *keymap.Layer, layout *keyboard.Layout, output string) erro
return err
}

dc.SetHexColor("#bfb6af")
dc.Clear()
if !transparent {
dc.SetHexColor("#bfb6af")
dc.Clear()
}

if layer != nil {
dc.SetRGB(0., 0., 0.)
Expand All @@ -96,11 +104,17 @@ func drawLayer(layer *keymap.Layer, layout *keyboard.Layout, output string) erro
}
if layer != nil {
log.Info().Str("output", fmt.Sprintf("%v/%v.png", output, layer.Name)).Msg("Layout generaged!")
dc.SavePNG(fmt.Sprintf("%v/%v.png", output, layer.Name))
err = dc.SavePNG(fmt.Sprintf("%v/%v.png", output, layer.Name))
if err != nil {
return err
}
} else {
log.Info().Str("output", fmt.Sprintf("%v/layout.png", output)).Msg("Layout generated!")

dc.SavePNG(fmt.Sprintf("%v/layout.png", output))
err = dc.SavePNG(fmt.Sprintf("%v/layout.png", output))
if err != nil {
return err
}
}
return nil
}
Expand Down

0 comments on commit 8c50488

Please sign in to comment.