This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
tomo-old/theme.go

429 lines
10 KiB
Go
Raw Normal View History

2023-03-30 23:06:29 -06:00
package tomo
2023-01-08 23:03:19 -07:00
2023-02-02 22:57:18 -07:00
import "image"
import "image/color"
2023-01-08 23:03:19 -07:00
import "golang.org/x/image/font"
2023-03-04 14:18:43 -07:00
import "git.tebibyte.media/sashakoshka/tomo/data"
2023-01-08 23:03:19 -07:00
import "git.tebibyte.media/sashakoshka/tomo/artist"
2023-04-02 17:01:06 -06:00
// Color lits a number of cannonical colors, each with its own ID.
type Color int; const (
// The sixteen ANSI terminal colors:
ColorBlack Color = iota
ColorRed
ColorGreen
ColorYellow
ColorBlue
ColorPurple
ColorCyan
ColorWhite
ColorBrightBlack
ColorBrightRed
ColorBrightGreen
ColorBrightYellow
ColorBrightBlue
ColorBrightPurple
ColorBrightCyan
ColorBrightWhite
2023-04-02 17:01:06 -06:00
// ColorForeground is the text/icon color of the theme.
ColorForeground
2023-04-20 16:53:42 -06:00
// ColorMidground is a generic raised element color.
ColorMidground
2023-04-02 17:01:06 -06:00
// ColorBackground is the background color of the theme.
ColorBackground
2023-04-20 16:53:42 -06:00
// ColorShadow is a generic shadow color.
ColorShadow
// ColorShine is a generic highlight color.
ColorShine
2023-04-02 17:01:06 -06:00
// ColorAccent is the accent color of the theme.
ColorAccent
)
2023-01-08 23:03:19 -07:00
2023-02-02 22:57:18 -07:00
// Pattern lists a number of cannonical pattern types, each with its own ID.
type Pattern int; const (
2023-02-26 20:20:17 -07:00
// PatternBackground is the window background of the theme. It appears
// in things like containers and behind text.
PatternBackground Pattern = iota
2023-02-02 22:57:18 -07:00
// PatternDead is a pattern that is displayed on a "dead area" where no
// controls exist, but there still must be some indication of visual
// structure (such as in the corner between two scroll bars).
PatternDead
// PatternRaised is a generic raised pattern.
PatternRaised
// PatternSunken is a generic sunken pattern.
PatternSunken
// PatternPinboard is similar to PatternSunken, but it is textured.
PatternPinboard
// PatternButton is a button pattern.
PatternButton
// PatternInput is a pattern for input fields, editable text areas, etc.
PatternInput
// PatternGutter is a track for things to slide on.
PatternGutter
// PatternHandle is a handle that slides along a gutter.
PatternHandle
// PatternLine is an engraved line that separates things.
PatternLine
2023-02-28 17:00:34 -07:00
// PatternMercury is a fill pattern for progress bars, meters, etc.
PatternMercury
2023-04-02 19:15:16 -06:00
// PatternTableHead is a table row or column heading background.
PatternTableHead
// PatternTableCell is a table cell background.
PatternTableCell
2023-04-20 16:40:05 -06:00
// PatternLamp is an indicator light pattern.
PatternLamp
2023-02-02 22:57:18 -07:00
)
2023-04-02 17:01:06 -06:00
// IconSize is a type representing valid icon sizes.
type IconSize int
2023-04-01 23:56:19 -06:00
2023-04-02 17:01:06 -06:00
const (
IconSizeSmall IconSize = 16
IconSizeLarge IconSize = 48
2023-02-26 20:20:17 -07:00
)
2023-03-04 18:10:53 -07:00
// Icon lists a number of cannonical icons, each with its own ID.
type Icon int
// IconNone specifies no icon.
2023-04-25 16:00:16 -06:00
const IconNone Icon = -1
const (
2023-03-04 18:10:53 -07:00
// Place icons
IconHome Icon = iota
Icon3DObjects
IconPictures
IconVideos
IconMusic
IconArchives
IconBooks
IconDocuments
IconFonts
IconPrograms
IconLibraries
IconDownloads
IconRepositories
2023-04-02 15:55:24 -06:00
IconSettings
IconHistory)
2023-03-04 18:10:53 -07:00
2023-03-04 20:07:59 -07:00
const (
2023-03-04 18:10:53 -07:00
// Object icons
2023-03-04 20:07:59 -07:00
IconFile Icon = iota + 0x80
2023-03-04 18:10:53 -07:00
IconDirectory
IconPopulatedDirectory
IconStorage
IconMagneticTape
IconFloppyDisk
IconHDD
IconSSD
IconFlashDrive
IconMemoryCard
IconRomDisk
IconRamDisk
IconCD
IconDVD
IconNetwork
IconInternet
IconDevice
IconServer
IconNetworkSwitch
IconRouter
IconDesktop
IconLaptop
IconTablet
IconPhone
IconCamera
IconPeripheral
IconKeyboard
IconMouse
IconTrackpad
IconPenTablet
IconMonitor
IconSpeaker
IconMicrophone
IconWebcam
IconGameController
IconPort
IconNetworkPort
IconUSBPort
IconParallelPort
IconSerialPort
IconPS2Port
2023-03-04 20:07:59 -07:00
IconMonitorPort)
2023-03-04 18:10:53 -07:00
2023-03-04 20:07:59 -07:00
const (
2023-03-04 18:10:53 -07:00
// Action icons
2023-03-04 21:09:46 -07:00
IconOpen Icon = iota + 0x100
2023-03-04 18:10:53 -07:00
IconSave
IconSaveAs
IconNew
IconNewFolder
IconDelete
IconCut
IconCopy
IconPaste
IconAdd
IconRemove
IconAddBookmark
IconRemoveBookmark
IconAddFavorite
IconRemoveFavorite
2023-03-04 18:48:46 -07:00
2023-03-04 18:10:53 -07:00
IconPlay
IconPause
IconStop
IconFastForward
IconRewind
IconToEnd
IconToBeginning
IconRecord
IconVolumeUp
IconVolumeDown
IconMute
IconBackward
IconForward
2023-04-02 15:55:24 -06:00
IconUpward
IconRefresh
2023-03-04 18:10:53 -07:00
IconYes
IconNo
2023-04-02 15:55:24 -06:00
IconUndo
IconRedo
IconRun
IconSearch
IconClose
IconQuit
IconIconify
IconShade
IconMaximize
IconRestore
IconReplace
IconUnite
IconDiffer
IconInvert
2023-04-21 14:47:15 -06:00
IconIntersect
2023-04-25 15:19:43 -06:00
IconExpand
IconPin
IconUnpin)
2023-03-04 18:10:53 -07:00
2023-03-04 20:07:59 -07:00
const (
2023-03-04 18:10:53 -07:00
// Status icons
2023-03-04 21:09:46 -07:00
IconInformation Icon = iota + 0x180
2023-03-04 18:10:53 -07:00
IconQuestion
IconWarning
2023-03-04 20:07:59 -07:00
IconError)
2023-03-04 18:10:53 -07:00
2023-03-04 20:07:59 -07:00
const (
2023-03-04 18:10:53 -07:00
// Tool icons
2023-04-02 15:55:24 -06:00
IconCursor Icon = iota + 0x200
IconMeasure
IconSelect
IconSelectRectangle
IconSelectEllipse
IconSelectGeometric
IconSelectFreeform
IconSelectLasso
IconSelectFuzzy
IconTransform
IconTranslate
IconRotate
IconScale
IconWarp
IconDistort
IconPencil
IconBrush
IconEraser
IconFill
IconText)
2023-04-02 17:01:06 -06:00
// FontSize specifies the general size of a font face in a semantic way.
type FontSize int; const (
// FontSizeNormal is the default font size that should be used for most
// things.
FontSizeNormal FontSize = iota
// FontSizeLarge is a larger font size suitable for things like section
// headings.
FontSizeLarge
// FontSizeHuge is a very large font size suitable for things like
// titles, wizard step names, digital clocks, etc.
FontSizeHuge
// FontSizeSmall is a smaller font size. Try not to use this unless it
// makes a lot of sense to do so, because it can negatively impact
// accessibility. It is useful for things like copyright notices at the
// bottom of some window that the average user doesn't actually care
// about.
FontSizeSmall
)
2023-04-05 00:12:17 -06:00
2023-04-02 17:01:06 -06:00
// FontStyle specifies stylistic alterations to a font face.
type FontStyle int; const (
FontStyleRegular FontStyle = 0
FontStyleBold FontStyle = 1
FontStyleItalic FontStyle = 2
2023-04-05 00:12:17 -06:00
FontStyleMonospace FontStyle = 4
2023-04-02 17:01:06 -06:00
FontStyleBoldItalic FontStyle = 1 | 2
)
2023-03-04 18:10:53 -07:00
// Hints specifies rendering hints for a particular pattern. Elements can take
// these into account in order to gain extra performance.
type Hints struct {
// StaticInset defines an inset rectangular area in the middle of the
// pattern that does not change between PatternStates. If the inset is
// zero on all sides, this hint does not apply.
StaticInset artist.Inset
// Uniform specifies a singular color for the entire pattern. If the
// alpha channel is zero, this hint does not apply.
Uniform color.RGBA
}
2023-02-02 22:57:18 -07:00
// Theme represents a visual style configuration,
type Theme interface {
// FontFace returns the proper font for a given style, size, and case.
FontFace (FontStyle, FontSize, Case) font.Face
// Icon returns an appropriate icon given an icon name, size, and case.
2023-03-04 20:07:59 -07:00
Icon (Icon, IconSize, Case) artist.Icon
2023-03-04 14:18:43 -07:00
// Icon returns an appropriate icon given a file mime type, size, and,
// case.
2023-03-04 18:48:46 -07:00
MimeIcon (data.Mime, IconSize, Case) artist.Icon
2023-02-02 22:57:18 -07:00
// Pattern returns an appropriate pattern given a pattern name, case,
// and state.
2023-02-26 20:20:17 -07:00
Pattern (Pattern, State, Case) artist.Pattern
// Color returns an appropriate pattern given a color name, case, and
// state.
Color (Color, State, Case) color.RGBA
2023-02-02 22:57:18 -07:00
// Padding returns how much space should be between the bounds of a
// pattern whatever an element draws inside of it.
Padding (Pattern, Case) artist.Inset
// Margin returns the left/right (x) and top/bottom (y) margins that
// should be put between any self-contained objects drawn within this
// pattern (if applicable).
Margin (Pattern, Case) image.Point
2023-01-08 23:03:19 -07:00
2023-02-02 22:57:18 -07:00
// Sink returns a vector that should be added to an element's inner
// content when it is pressed down (if applicable) to simulate a 3D
// sinking effect.
Sink (Pattern, Case) image.Point
// Hints returns rendering optimization hints for a particular pattern.
// These are optional, but following them may result in improved
// performance.
Hints (Pattern, Case) Hints
2023-01-08 23:03:19 -07:00
}
2023-03-30 23:06:29 -06:00
// Case sepecifies what kind of element is using a pattern. It contains a
// namespace parameter, an element parameter, and an optional component trail.
// All parameter values should be written in camel case. Themes can change their
// styling based on the case for fine-grained control over the look and feel of
// specific elements.
type Case struct {
// Namespace refers to the package that the element comes from. This is
// so different element packages can have elements with the same name
// while still allowing themes to differentiate between them.
Namespace string
// Element refers to the name of the element. This should (generally) be
// the type name of the element. For example: Button, Input, Container,
// etc.
Element string
// Component specifies the specific part of the element that is being
// referred to. This parameter is entirely optional.
Component string
}
// C can be used as shorthand to generate a case struct. The component parameter
// may be left out of this argument list for brevity. Arguments passed after
// component will be ignored.
func C (namespace, element string, component ...string) Case {
if component == nil { component = []string { "" } }
return Case {
Namespace: namespace,
Element: element,
Component: component[0],
}
}
// Match determines if a case matches the specified parameters. A blank string
// will act as a wildcard.
func (c Case) Match (namespace, element, component string) bool {
if namespace == "" { namespace = c.Namespace }
if element == "" { element = c.Element }
if component == "" { component = c.Component }
return namespace == c.Namespace &&
element == c.Element &&
component == c.Component
}
// State lists parameters which can change the appearance of some patterns and
// colors. For example, passing a State with Selected set to true may result in
// a pattern that has a colored border within it.
type State struct {
// On should be set to true if the element that is using this pattern is
// in some sort of selected or "on" state, such as if a checkbox is
// checked, a file is selected, or a switch is toggled on. This is only
// necessary if the element in question is capable of being toggled or
// selected.
On bool
// Focused should be set to true if the element that is using this
// pattern is currently focused.
Focused bool
// Pressed should be set to true if the element that is using this
// pattern is being pressed down by the mouse. This is only necessary if
// the element in question processes mouse button events.
Pressed bool
// Disabled should be set to true if the element that is using this
// pattern is locked and cannot be interacted with. Disabled variations
// of patterns are typically flattened and greyed-out.
Disabled bool
}