New example (small change): text/codepoints_loading

This commit is contained in:
Per Hultqvist 2024-11-10 16:17:45 +01:00
parent 9108b3b7b0
commit 7e465e47e2

View file

@ -14,6 +14,7 @@ package main
import ( import (
"fmt" "fmt"
"slices"
rl "github.com/gen2brain/raylib-go/raylib" rl "github.com/gen2brain/raylib-go/raylib"
) )
@ -35,7 +36,8 @@ func main() {
allCodepoints := []rune(text) allCodepoints := []rune(text)
// Removed duplicate codepoints to generate smaller font atlas // Removed duplicate codepoints to generate smaller font atlas
codepoints := CodepointRemoveDuplicates(allCodepoints) slices.Sort(allCodepoints)
codepoints := slices.Compact(allCodepoints)
codepointsCount := len(codepoints) codepointsCount := len(codepoints)
// Load font containing all the provided codepoint glyphs // Load font containing all the provided codepoint glyphs
@ -91,18 +93,3 @@ func main() {
rl.UnloadFont(font) // Unload font rl.UnloadFont(font) // Unload font
rl.CloseWindow() // Close window and OpenGL context rl.CloseWindow() // Close window and OpenGL context
} }
// CodepointRemoveDuplicates removes codepoint duplicates if requested
func CodepointRemoveDuplicates[T comparable](sliceList []T) []T {
allKeys := make(map[T]bool)
var list []T
for _, item := range sliceList {
if _, value := allKeys[item]; !value {
allKeys[item] = true
list = append(list, item)
}
}
return list
}