Made icons a bit better
There is a new IconNone and an IconUpward, and buttons don't expand awkwardly when they have an icon.
This commit is contained in:
parent
bf667aded9
commit
221647a265
@ -100,19 +100,18 @@ func (element *Button) SetText (text string) {
|
||||
element.drawAndPush()
|
||||
}
|
||||
|
||||
// SetIcon sets the icon of the button.
|
||||
// SetIcon sets the icon of the button. Passing theme.IconNone removes the
|
||||
// current icon if it exists.
|
||||
func (element *Button) SetIcon (id theme.Icon) {
|
||||
if element.hasIcon && element.iconId == id { return }
|
||||
element.hasIcon = true
|
||||
element.iconId = id
|
||||
element.updateMinimumSize()
|
||||
element.drawAndPush()
|
||||
}
|
||||
|
||||
// ClearIcon removes the button's icon, if it exists.
|
||||
func (element *Button) ClearIcon () {
|
||||
if !element.hasIcon { return }
|
||||
element.hasIcon = false
|
||||
if id == theme.IconNone {
|
||||
element.hasIcon = false
|
||||
element.updateMinimumSize()
|
||||
element.drawAndPush()
|
||||
} else {
|
||||
if element.hasIcon && element.iconId == id { return }
|
||||
element.hasIcon = true
|
||||
element.iconId = id
|
||||
}
|
||||
element.updateMinimumSize()
|
||||
element.drawAndPush()
|
||||
}
|
||||
@ -145,26 +144,21 @@ func (element *Button) SetConfig (new config.Config) {
|
||||
}
|
||||
|
||||
func (element *Button) updateMinimumSize () {
|
||||
padding := element.theme.Padding(theme.PatternButton)
|
||||
margin := element.theme.Margin(theme.PatternButton)
|
||||
var minimumSize image.Rectangle
|
||||
padding := element.theme.Padding(theme.PatternButton)
|
||||
margin := element.theme.Margin(theme.PatternButton)
|
||||
|
||||
if element.showText {
|
||||
minimumSize = element.drawer.LayoutBounds()
|
||||
}
|
||||
|
||||
minimumSize = minimumSize.Sub(minimumSize.Min)
|
||||
textBounds := element.drawer.LayoutBounds()
|
||||
minimumSize := textBounds.Sub(textBounds.Min)
|
||||
|
||||
if element.hasIcon {
|
||||
icon := element.theme.Icon(element.iconId, theme.IconSizeSmall)
|
||||
if icon != nil {
|
||||
bounds := icon.Bounds()
|
||||
minimumSize.Max.X += bounds.Dx()
|
||||
if element.showText {
|
||||
minimumSize.Max.X += bounds.Dx()
|
||||
minimumSize.Max.X += margin.X
|
||||
}
|
||||
if minimumSize.Max.Y < bounds.Dy() {
|
||||
minimumSize.Max.Y = bounds.Dy()
|
||||
} else {
|
||||
minimumSize.Max.X = bounds.Dx()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
@ -64,6 +64,9 @@ type Color int; const (
|
||||
|
||||
// Icon lists a number of cannonical icons, each with its own ID.
|
||||
type Icon int; const (
|
||||
// IconNone specifies no icon.
|
||||
IconNone = -1
|
||||
|
||||
// Place icons
|
||||
IconHome Icon = iota
|
||||
Icon3DObjects
|
||||
@ -168,7 +171,9 @@ const (
|
||||
IconHistory
|
||||
|
||||
IconYes
|
||||
IconNo)
|
||||
IconNo
|
||||
|
||||
IconUpward)
|
||||
|
||||
const (
|
||||
// Status icons
|
||||
|
Reference in New Issue
Block a user