Created a convenience constructor for Inset

This commit is contained in:
Sasha Koshka 2023-03-23 18:05:30 -04:00
parent 6a08d0f317
commit 8447b06641
3 changed files with 34 additions and 12 deletions

View File

@ -15,6 +15,28 @@ type Side int; const (
// the left at index three. These values may be negative.
type Inset [4]int
// I allows you to create an inset in a CSS-ish way:
//
// - One argument: all sides are set to this value
// - Two arguments: the top and bottom sides are set to the first value, and
// the left and right sides are set to the second value.
// - Three arguments: the top side is set by the first value, the left and
// right sides are set by the second vaue, and the bottom side is set by the
// third value.
// - Four arguments: each value corresponds to a side.
//
// This function will panic if an argument count that isn't one of these is
// given.
func I (sides ...int) Inset {
switch len(sides) {
case 1: return Inset { sides[0], sides[0], sides[0], sides[0] }
case 2: return Inset { sides[0], sides[1], sides[0], sides[1] }
case 3: return Inset { sides[0], sides[1], sides[2], sides[1] }
case 4: return Inset { sides[0], sides[1], sides[2], sides[3] }
default: panic("I: illegal argument count.")
}
}
// Apply returns the given rectangle, shrunk on all four sides by the given
// inset. If a measurment of the inset is negative, that side will instead be
// expanded outward. If the rectangle's dimensions cannot be reduced any

View File

@ -56,7 +56,7 @@ func NewDirectory (
err error,
) {
element = &Directory { }
element.theme.Case = theme.C("files", "Directory")
element.theme.Case = theme.C("files", "directory")
element.Core, element.core = core.NewCore(element, element.redoAll)
element.Propagator = core.NewPropagator(element, element.core)
err = element.SetLocation(location, within)

View File

@ -254,28 +254,28 @@ func (Default) Padding (id Pattern, c Case) artist.Inset {
switch id {
case PatternRaised:
if c.Match("basic", "listEntry", "") {
return artist.Inset { 4, 8, 4, 8 }
return artist.I(4, 8)
} else {
return artist.Inset { 8, 8, 8, 8 }
return artist.I(8)
}
case PatternSunken:
if c.Match("basic", "list", "") {
return artist.Inset { 4, 0, 3, 0 }
return artist.I(4, 0, 3)
} else if c.Match("basic", "progressBar", "") {
return artist.Inset { 2, 1, 1, 2 }
return artist.I(2, 1, 1, 2)
} else {
return artist.Inset { 8, 8, 8, 8 }
return artist.I(8)
}
case PatternPinboard:
if c.Match("fun", "piano", "") {
return artist.Inset { 2, 2, 2, 2 }
return artist.I(2)
} else {
return artist.Inset { 8, 8, 8, 8 }
return artist.I(8)
}
case PatternGutter: return artist.Inset { }
case PatternLine: return artist.Inset { 1, 1, 1, 1 }
case PatternMercury: return artist.Inset { 5, 5, 5, 5 }
default: return artist.Inset { 8, 8, 8, 8 }
case PatternGutter: return artist.I(0)
case PatternLine: return artist.I(1)
case PatternMercury: return artist.I(5)
default: return artist.I(8)
}
}