Created a convenience constructor for Inset
This commit is contained in:
parent
6a08d0f317
commit
8447b06641
@ -15,6 +15,28 @@ type Side int; const (
|
|||||||
// the left at index three. These values may be negative.
|
// the left at index three. These values may be negative.
|
||||||
type Inset [4]int
|
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
|
// 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
|
// 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
|
// expanded outward. If the rectangle's dimensions cannot be reduced any
|
||||||
|
@ -56,7 +56,7 @@ func NewDirectory (
|
|||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
element = &Directory { }
|
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.Core, element.core = core.NewCore(element, element.redoAll)
|
||||||
element.Propagator = core.NewPropagator(element, element.core)
|
element.Propagator = core.NewPropagator(element, element.core)
|
||||||
err = element.SetLocation(location, within)
|
err = element.SetLocation(location, within)
|
||||||
|
@ -254,28 +254,28 @@ func (Default) Padding (id Pattern, c Case) artist.Inset {
|
|||||||
switch id {
|
switch id {
|
||||||
case PatternRaised:
|
case PatternRaised:
|
||||||
if c.Match("basic", "listEntry", "") {
|
if c.Match("basic", "listEntry", "") {
|
||||||
return artist.Inset { 4, 8, 4, 8 }
|
return artist.I(4, 8)
|
||||||
} else {
|
} else {
|
||||||
return artist.Inset { 8, 8, 8, 8 }
|
return artist.I(8)
|
||||||
}
|
}
|
||||||
case PatternSunken:
|
case PatternSunken:
|
||||||
if c.Match("basic", "list", "") {
|
if c.Match("basic", "list", "") {
|
||||||
return artist.Inset { 4, 0, 3, 0 }
|
return artist.I(4, 0, 3)
|
||||||
} else if c.Match("basic", "progressBar", "") {
|
} else if c.Match("basic", "progressBar", "") {
|
||||||
return artist.Inset { 2, 1, 1, 2 }
|
return artist.I(2, 1, 1, 2)
|
||||||
} else {
|
} else {
|
||||||
return artist.Inset { 8, 8, 8, 8 }
|
return artist.I(8)
|
||||||
}
|
}
|
||||||
case PatternPinboard:
|
case PatternPinboard:
|
||||||
if c.Match("fun", "piano", "") {
|
if c.Match("fun", "piano", "") {
|
||||||
return artist.Inset { 2, 2, 2, 2 }
|
return artist.I(2)
|
||||||
} else {
|
} else {
|
||||||
return artist.Inset { 8, 8, 8, 8 }
|
return artist.I(8)
|
||||||
}
|
}
|
||||||
case PatternGutter: return artist.Inset { }
|
case PatternGutter: return artist.I(0)
|
||||||
case PatternLine: return artist.Inset { 1, 1, 1, 1 }
|
case PatternLine: return artist.I(1)
|
||||||
case PatternMercury: return artist.Inset { 5, 5, 5, 5 }
|
case PatternMercury: return artist.I(5)
|
||||||
default: return artist.Inset { 8, 8, 8, 8 }
|
default: return artist.I(8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user