mirror of
https://github.com/nwg-piotr/nwg-drawer.git
synced 2024-08-16 17:20:22 +03:00
fix cutting utf-8 strings #82
This commit is contained in:
parent
8ff2d5c89c
commit
cedcf8619f
16
tools.go
16
tools.go
@ -691,3 +691,19 @@ func mapOutputs() (map[string]*gdk.Monitor, error) {
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// KAdot / https://stackoverflow.com/a/38537764/4040598 - thanks!
|
||||
func substring(s string, start int, end int) string {
|
||||
startStrIdx := 0
|
||||
i := 0
|
||||
for j := range s {
|
||||
if i == start {
|
||||
startStrIdx = j
|
||||
}
|
||||
if i == end {
|
||||
return s[startStrIdx:j]
|
||||
}
|
||||
i++
|
||||
}
|
||||
return s[startStrIdx:]
|
||||
}
|
||||
|
@ -58,9 +58,8 @@ func setUpPinnedFlowBox() *gtk.FlowBox {
|
||||
name = entry.Name
|
||||
}
|
||||
if len(name) > 20 {
|
||||
r := []rune(name)
|
||||
name = string(r[:17])
|
||||
name = fmt.Sprintf("%s…", name)
|
||||
r := substring(name, 0, 17)
|
||||
name = fmt.Sprintf("%s…", string(r))
|
||||
}
|
||||
btn.SetLabel(name)
|
||||
|
||||
@ -252,9 +251,8 @@ func flowBoxButton(entry desktopEntry) *gtk.Button {
|
||||
button.SetImagePosition(gtk.POS_TOP)
|
||||
name := entry.NameLoc
|
||||
if len(name) > 20 {
|
||||
r := []rune(name[:17])
|
||||
name = string(r)
|
||||
name = fmt.Sprintf("%s…", name)
|
||||
r := substring(name, 0, 17)
|
||||
name = fmt.Sprintf("%s…", string(r))
|
||||
}
|
||||
button.SetLabel(name)
|
||||
|
||||
@ -263,9 +261,8 @@ func flowBoxButton(entry desktopEntry) *gtk.Button {
|
||||
terminal := entry.Terminal
|
||||
desc := entry.CommentLoc
|
||||
if len(desc) > 120 {
|
||||
r := []rune(desc[:117])
|
||||
desc = string(r)
|
||||
desc = fmt.Sprintf("%s…", desc)
|
||||
r := substring(desc, 0, 117)
|
||||
desc = fmt.Sprintf("%s…", string(r))
|
||||
}
|
||||
button.Connect("button-release-event", func(btn *gtk.Button, e *gdk.Event) bool {
|
||||
btnEvent := gdk.EventButtonNewFromEvent(e)
|
||||
|
Loading…
Reference in New Issue
Block a user