Added a Component parameter to theme cases
This commit is contained in:
		
							parent
							
								
									d3d3cddfef
								
							
						
					
					
						commit
						6a08d0f317
					
				@ -313,7 +313,7 @@ func (element *Piano) drawFlat (
 | 
				
			|||||||
) {
 | 
					) {
 | 
				
			||||||
	state.Pressed = pressed
 | 
						state.Pressed = pressed
 | 
				
			||||||
	pattern := element.theme.Theme.Pattern (
 | 
						pattern := element.theme.Theme.Pattern (
 | 
				
			||||||
		theme.PatternButton, state, theme.C("fun", "flatKey"))
 | 
							theme.PatternButton, state, theme.C("fun", "piano", "flatKey"))
 | 
				
			||||||
	pattern.Draw(element.core, bounds)
 | 
						pattern.Draw(element.core, bounds)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -324,6 +324,6 @@ func (element *Piano) drawSharp (
 | 
				
			|||||||
) {
 | 
					) {
 | 
				
			||||||
	state.Pressed = pressed
 | 
						state.Pressed = pressed
 | 
				
			||||||
	pattern := element.theme.Theme.Pattern (
 | 
						pattern := element.theme.Theme.Pattern (
 | 
				
			||||||
		theme.PatternButton, state, theme.C("fun", "sharpKey"))
 | 
							theme.PatternButton, state, theme.C("fun", "piano", "sharpKey"))
 | 
				
			||||||
	pattern.Draw(element.core, bounds)
 | 
						pattern.Draw(element.core, bounds)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -210,26 +210,30 @@ func (Default) Pattern (id Pattern, state State, c Case) artist.Pattern {
 | 
				
			|||||||
	case PatternBackground: return patterns.Uhex(0xaaaaaaFF)
 | 
						case PatternBackground: return patterns.Uhex(0xaaaaaaFF)
 | 
				
			||||||
	case PatternDead:       return defaultTextures[0][offset]
 | 
						case PatternDead:       return defaultTextures[0][offset]
 | 
				
			||||||
	case PatternRaised:
 | 
						case PatternRaised:
 | 
				
			||||||
		if c == C("basic", "listEntry") {
 | 
							if c.Match("basic", "listEntry", "") {
 | 
				
			||||||
			return defaultTextures[10][offset]
 | 
								return defaultTextures[10][offset]
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			return defaultTextures[1][offset]
 | 
								return defaultTextures[1][offset]
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case PatternSunken:     return defaultTextures[2][offset]
 | 
						case PatternSunken:   return defaultTextures[2][offset]
 | 
				
			||||||
	case PatternPinboard:   return defaultTextures[3][offset]
 | 
						case PatternPinboard: return defaultTextures[3][offset]
 | 
				
			||||||
	case PatternButton:
 | 
						case PatternButton:
 | 
				
			||||||
		switch c {
 | 
							switch {
 | 
				
			||||||
		case C("basic", "checkbox"): return defaultTextures[9][offset]
 | 
							case c.Match("basic", "checkbox", ""):  
 | 
				
			||||||
		case C("fun", "flatKey"):    return defaultTextures[11][offset]
 | 
								return defaultTextures[9][offset]
 | 
				
			||||||
		case C("fun", "sharpKey"):   return defaultTextures[12][offset]
 | 
							case c.Match("fun", "piano", "flatKey"):
 | 
				
			||||||
		default:                     return defaultTextures[4][offset]
 | 
								return defaultTextures[11][offset]
 | 
				
			||||||
 | 
							case c.Match("fun", "piano", "sharpKey"):
 | 
				
			||||||
 | 
								return defaultTextures[12][offset]
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								return defaultTextures[4][offset]
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case PatternInput:      return defaultTextures[5][offset]
 | 
						case PatternInput:   return defaultTextures[5][offset]
 | 
				
			||||||
	case PatternGutter:     return defaultTextures[6][offset]
 | 
						case PatternGutter:  return defaultTextures[6][offset]
 | 
				
			||||||
	case PatternHandle:     return defaultTextures[7][offset]
 | 
						case PatternHandle:  return defaultTextures[7][offset]
 | 
				
			||||||
	case PatternLine:       return defaultTextures[8][offset]
 | 
						case PatternLine:    return defaultTextures[8][offset]
 | 
				
			||||||
	case PatternMercury:    return defaultTextures[13][offset]
 | 
						case PatternMercury: return defaultTextures[13][offset]
 | 
				
			||||||
	default:                return patterns.Uhex(0xFF00FFFF)
 | 
						default:             return patterns.Uhex(0xFF00FFFF)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -249,21 +253,21 @@ func (Default) Color (id Color, state State, c Case) color.RGBA {
 | 
				
			|||||||
func (Default) Padding (id Pattern, c Case) artist.Inset {
 | 
					func (Default) Padding (id Pattern, c Case) artist.Inset {
 | 
				
			||||||
	switch id {
 | 
						switch id {
 | 
				
			||||||
	case PatternRaised:
 | 
						case PatternRaised:
 | 
				
			||||||
		if c == C("basic", "listEntry") {
 | 
							if c.Match("basic", "listEntry", "") {
 | 
				
			||||||
			return artist.Inset { 4, 8, 4, 8 }
 | 
								return artist.Inset { 4, 8, 4, 8 }
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			return artist.Inset { 8, 8, 8, 8 }
 | 
								return artist.Inset { 8, 8, 8, 8 }
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case PatternSunken:
 | 
						case PatternSunken:
 | 
				
			||||||
		if c == C("basic", "list") {
 | 
							if c.Match("basic", "list", "") {
 | 
				
			||||||
			return artist.Inset { 4, 0, 3, 0 }
 | 
								return artist.Inset { 4, 0, 3, 0 }
 | 
				
			||||||
		} else if c == C("basic", "progressBar") {
 | 
							} else if c.Match("basic", "progressBar", "") {
 | 
				
			||||||
			return artist.Inset { 2, 1, 1, 2 }
 | 
								return artist.Inset { 2, 1, 1, 2 }
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			return artist.Inset { 8, 8, 8, 8 }
 | 
								return artist.Inset { 8, 8, 8, 8 }
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case PatternPinboard:
 | 
						case PatternPinboard:
 | 
				
			||||||
		if c == C("fun", "piano") {
 | 
							if c.Match("fun", "piano", "") {
 | 
				
			||||||
			return artist.Inset { 2, 2, 2, 2 }
 | 
								return artist.Inset { 2, 2, 2, 2 }
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			return artist.Inset { 8, 8, 8, 8 }
 | 
								return artist.Inset { 8, 8, 8, 8 }
 | 
				
			||||||
 | 
				
			|||||||
@ -1,29 +1,59 @@
 | 
				
			|||||||
package theme
 | 
					package theme
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Case sepecifies what kind of element is using a pattern. It contains a
 | 
					// Case sepecifies what kind of element is using a pattern. It contains a
 | 
				
			||||||
// namespace parameter and an element parameter. The element parameter does not
 | 
					// namespace parameter, an element parameter, and an optional component trail.
 | 
				
			||||||
// necissarily need to match an element name, but if it can, it should. Both
 | 
					// All parameter values should be written in camel case. Themes can change their
 | 
				
			||||||
// parameters should be written in camel case. Themes can change their styling
 | 
					// styling based on the case for fine-grained control over the look and feel of
 | 
				
			||||||
// based on this parameter for fine-grained control over the look and feel of
 | 
					 | 
				
			||||||
// specific elements.
 | 
					// specific elements.
 | 
				
			||||||
type Case struct { Namespace, Element string } 
 | 
					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 as used in State.
 | 
					// C can be used as shorthand to generate a case struct. The component parameter
 | 
				
			||||||
func C (namespace, element string) (c Case) {
 | 
					// 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 {
 | 
						return Case {
 | 
				
			||||||
		Namespace: namespace,
 | 
							Namespace: namespace,
 | 
				
			||||||
		Element: element,
 | 
							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
 | 
					// 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
 | 
					// colors. For example, passing a State with Selected set to true may result in
 | 
				
			||||||
// a pattern that has a colored border within it.
 | 
					// a pattern that has a colored border within it.
 | 
				
			||||||
type State struct {
 | 
					type State struct {
 | 
				
			||||||
	// On should be set to true if the element that is using this pattern is
 | 
						// 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
 | 
						// in some sort of selected or "on" state, such as if a checkbox is
 | 
				
			||||||
	// checked or a switch is toggled on. This is only necessary if the
 | 
						// checked, a file is selected, or a switch is toggled on. This is only
 | 
				
			||||||
	// element in question is capable of being toggled or selected.
 | 
						// necessary if the element in question is capable of being toggled or
 | 
				
			||||||
 | 
						// selected.
 | 
				
			||||||
	On bool
 | 
						On bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Focused should be set to true if the element that is using this
 | 
						// Focused should be set to true if the element that is using this
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user