tinygo-org / tinyfont

Text library for TinyGo displays
https://tinygo.org
BSD 3-Clause "New" or "Revised" License
49 stars 12 forks source link

Unify func #7

Closed sago35 closed 4 years ago

sago35 commented 4 years ago

WriteLineRotated and WriteLineColorsRotated are almost the same, so we unified them. WriteLineRotated slows down a little, but don't worry about it.

sago35 commented 4 years ago

I'll fix #7 once #5 has been merged.

deadprogram commented 4 years ago

This is now ready for resolving the merge conflict, @sago35

sago35 commented 4 years ago

This PR eliminates code duplication and reduces the flash size by 432 bytes.

$ git rev-parse HEAD
b8da1441d54def37b64de3c81170ac91e9a44e2e

$ tinygo-docker build -o app.uf2 -target pyportal -size short ./examples/pyportal
   code    data     bss |   flash     ram
  10648   32692    6636 |   43340   39328

$ git checkout dev
Switched to branch 'dev'
M       examples/pyportal/main.go
Your branch is up to date with 'upstream/dev'.

$ git rev-parse HEAD
000943e4e7c009f356fedd93738bd8fcb7a2c475

$ tinygo build -o app.uf2 -target pyportal -size short ./examples/pyportal
   code    data     bss |   flash     ram
  11080   32692    6636 |   43772   39328

testcode:

$ git diff
diff --git a/examples/pyportal/main.go b/examples/pyportal/main.go
index a0f0973..633835a 100644
--- a/examples/pyportal/main.go
+++ b/examples/pyportal/main.go
@@ -32,7 +32,7 @@ func main() {
                mycolors[k] = getRainbowRGB(uint8(k * 14))
        }
        tinyfont.WriteLineColors(display, &freesans.Bold18pt7b, 10, 35, "HELLO", mycolors)
-       tinyfont.WriteLineColorsRotated(display, &freemono.Bold18pt7b, 150, 100, "Gophers", mycolors[6:], tinyfont.ROTATION_180)
+       tinyfont.WriteLineRotated(display, &freemono.Bold18pt7b, 150, 100, "Gophers", mycolors[6], tinyfont.ROTATION_180)
        tinyfont.WriteLineColorsRotated(display, &freeserif.Bold9pt7b, 150, 90, "TinyGo", mycolors[12:], tinyfont.ROTATION_270)
        tinyfont.WriteLineColorsRotated(display, &tinyfont.Org01, 10, 40, "TinyGo", mycolors[18:], tinyfont.ROTATION_90)
sago35 commented 4 years ago

Please review. @deadprogram

deadprogram commented 4 years ago

I'd like to know what you think about this @conejoninja

conejoninja commented 4 years ago

It looks good, so merging. Thanks for your massive work on tinyfont.