Hiding button text actually works now
This commit is contained in:
parent
865dd20724
commit
d38bd1cbf5
@ -156,7 +156,6 @@ func (element *Button) updateMinimumSize () {
|
|||||||
minimumSize = element.drawer.LayoutBounds()
|
minimumSize = element.drawer.LayoutBounds()
|
||||||
}
|
}
|
||||||
|
|
||||||
minimumSize = padding.Inverse().Apply(minimumSize)
|
|
||||||
minimumSize = minimumSize.Sub(minimumSize.Min)
|
minimumSize = minimumSize.Sub(minimumSize.Min)
|
||||||
|
|
||||||
if element.hasIcon {
|
if element.hasIcon {
|
||||||
@ -172,6 +171,8 @@ func (element *Button) updateMinimumSize () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
minimumSize = padding.Inverse().Apply(minimumSize)
|
||||||
element.core.SetMinimumSize(minimumSize.Dx(), minimumSize.Dy())
|
element.core.SetMinimumSize(minimumSize.Dx(), minimumSize.Dy())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,14 +211,15 @@ func (element *Button) drawText () {
|
|||||||
foreground := element.theme.Color(theme.ColorForeground, state)
|
foreground := element.theme.Color(theme.ColorForeground, state)
|
||||||
sink := element.theme.Sink(theme.PatternButton)
|
sink := element.theme.Sink(theme.PatternButton)
|
||||||
margin := element.theme.Margin(theme.PatternButton)
|
margin := element.theme.Margin(theme.PatternButton)
|
||||||
var offset image.Point
|
|
||||||
|
offset := image.Pt (
|
||||||
|
bounds.Dx() / 2,
|
||||||
|
bounds.Dy() / 2).Add(bounds.Min)
|
||||||
|
|
||||||
if element.showText {
|
if element.showText {
|
||||||
textBounds := element.drawer.LayoutBounds()
|
textBounds := element.drawer.LayoutBounds()
|
||||||
offset = image.Point {
|
offset.X -= textBounds.Dx() / 2
|
||||||
X: bounds.Min.X + (bounds.Dx() - textBounds.Dx()) / 2,
|
offset.Y -= textBounds.Dy() / 2
|
||||||
Y: bounds.Min.Y + (bounds.Dy() - textBounds.Dy()) / 2,
|
|
||||||
}
|
|
||||||
offset.Y -= textBounds.Min.Y
|
offset.Y -= textBounds.Min.Y
|
||||||
offset.X -= textBounds.Min.X
|
offset.X -= textBounds.Min.X
|
||||||
|
|
||||||
@ -231,25 +233,27 @@ func (element *Button) drawText () {
|
|||||||
if icon != nil {
|
if icon != nil {
|
||||||
iconBounds := icon.Bounds()
|
iconBounds := icon.Bounds()
|
||||||
addedWidth := iconBounds.Dx()
|
addedWidth := iconBounds.Dx()
|
||||||
|
iconOffset := offset
|
||||||
|
|
||||||
if element.showText {
|
if element.showText {
|
||||||
addedWidth += margin.X
|
addedWidth += margin.X
|
||||||
}
|
}
|
||||||
|
|
||||||
iconOffset := offset
|
|
||||||
iconOffset.X -= addedWidth / 2
|
iconOffset.X -= addedWidth / 2
|
||||||
iconOffset.Y =
|
iconOffset.Y =
|
||||||
bounds.Min.Y +
|
bounds.Min.Y +
|
||||||
(bounds.Dy() -
|
(bounds.Dy() -
|
||||||
iconBounds.Dy()) / 2
|
iconBounds.Dy()) / 2
|
||||||
if element.pressed {
|
if element.pressed {
|
||||||
iconOffset.Y += sink.Y
|
iconOffset = iconOffset.Add(sink)
|
||||||
}
|
}
|
||||||
offset.X += addedWidth / 2
|
offset.X += addedWidth / 2
|
||||||
|
|
||||||
icon.Draw(element.core, foreground, iconOffset)
|
icon.Draw(element.core, foreground, iconOffset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
element.drawer.Draw(element.core, foreground, offset)
|
if element.showText {
|
||||||
|
element.drawer.Draw(element.core, foreground, offset)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,12 @@ func run () {
|
|||||||
container.Adopt(icons(theme.IconHome, theme.IconRepositories), true)
|
container.Adopt(icons(theme.IconHome, theme.IconRepositories), true)
|
||||||
container.Adopt(icons(theme.IconFile, theme.IconCD), true)
|
container.Adopt(icons(theme.IconFile, theme.IconCD), true)
|
||||||
container.Adopt(icons(theme.IconOpen, theme.IconRemoveBookmark), true)
|
container.Adopt(icons(theme.IconOpen, theme.IconRemoveBookmark), true)
|
||||||
|
|
||||||
|
closeButton := basicElements.NewButton("Ok")
|
||||||
|
closeButton.SetIcon(theme.IconYes)
|
||||||
|
closeButton.ShowText(false)
|
||||||
|
closeButton.OnClick(tomo.Stop)
|
||||||
|
container.Adopt(closeButton, false)
|
||||||
|
|
||||||
window.OnClose(tomo.Stop)
|
window.OnClose(tomo.Stop)
|
||||||
window.Show()
|
window.Show()
|
||||||
|
Reference in New Issue
Block a user