From 925e011465aa0e1a813c7b0dac20d4a7156e5963 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 10 Aug 2024 01:39:23 -0400 Subject: [PATCH] Add IconSet, FaceSet to style package --- style/faceset.go | 13 +++++++++++++ style/iconset.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 style/faceset.go create mode 100644 style/iconset.go diff --git a/style/faceset.go b/style/faceset.go new file mode 100644 index 0000000..0535875 --- /dev/null +++ b/style/faceset.go @@ -0,0 +1,13 @@ +package style + +import "golang.org/x/image/font" +import "git.tebibyte.media/tomo/tomo" + +// FaceSet holds a set of font faces. +type FaceSet interface { + // Face returns the font face which most closely matches the given + // tomo.Face. The face must be closed when it is done being used. If no + // suitable face could be found, This behavior must return a fallback + // face (such as basicfont.Face7x13) instead of nil. + Face (tomo.Face) font.Face +} diff --git a/style/iconset.go b/style/iconset.go new file mode 100644 index 0000000..350f4fe --- /dev/null +++ b/style/iconset.go @@ -0,0 +1,28 @@ +package style + +import "git.tebibyte.media/tomo/tomo" +import "git.tebibyte.media/tomo/tomo/data" +import "git.tebibyte.media/tomo/tomo/canvas" + +// IconSet holds a set of icon textures. +type IconSet interface { + // A word on textures: + // + // Because textures can be linked to some resource that is outside of + // the control of Go's garbage collector, methods of IconSet must not + // allocate new copies of a texture each time they are called. It is + // fine to lazily load textures and save them for later use, but the + // same texture must never be allocated multiple times as this could + // cause a memory leak. + // + // As such, textures returned by these methods must be protected. + + // Icon returns a texture of the corresponding icon ID. If there is no + // suitable option, it should return nil. + Icon (tomo.Icon, tomo.IconSize) canvas.Texture + + // MimeIcon returns a texture of an icon corresponding to a MIME type. + // If there is no suitable specific option, it should return a more + // generic icon or a plain file icon. + MimeIcon (data.Mime, tomo.IconSize) canvas.Texture +}