Skip to content

Commit

Permalink
feat: Improve typesetting of the game information
Browse files Browse the repository at this point in the history
The typesetting is improved but not perfect yet.
It should be better in the future.
  • Loading branch information
marktwtn committed Jan 12, 2023
1 parent 808a396 commit 3534e3d
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"fmt"
"strconv"
"unicode/utf8"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
Expand Down Expand Up @@ -98,7 +100,7 @@ func main() {
}
var new_box_for_scroll = container.NewVBox()
for index, wishitem := range wishitems {
var wishitem_info = wishitem.Get_name() + " " + wishitem.Get_discount_price_str() + " " + wishitem.Get_discount_percent_str()
var wishitem_info = fmt.Sprintf("%8s %-8s %s", wishitem.Get_discount_price_str(), wishitem.Get_discount_percent_str(), wishitem.Get_name())
var check = widget.NewCheckWithData(wishitem_info, check_list[index])
new_box_for_scroll.Add(check)
}
Expand Down Expand Up @@ -224,25 +226,15 @@ func write_data(writer fyne.URIWriteCloser, combinations []Combination) {
var selected_info = ""
var selected_total_price uint = 0
for _, wishitem := range wishitems_with_selected {
selected_info += wishitem.Get_name()
selected_info += " "
selected_info += wishitem.Get_discount_price_str()
selected_info += " "
selected_info += wishitem.Get_discount_percent_str()
selected_info += "\n"
selected_info += fmt.Sprintf("%-[1]*s %8s %s\n", 50-(len(wishitem.Get_name())-utf8.RuneCountInString(wishitem.Get_name()))/2, wishitem.Get_name(), wishitem.Get_discount_price_str(), wishitem.Get_discount_percent_str())
selected_total_price += wishitem.Get_discount_price()
}
for _, combination := range combinations {
var info string = "組合:\n"
info += selected_info
for _, index := range combination.wishitems_index {
var wishitem = wishitems_without_selected[index]
info += wishitem.Get_name()
info += " "
info += wishitem.Get_discount_price_str()
info += " "
info += wishitem.Get_discount_percent_str()
info += "\n"
info += fmt.Sprintf("%-[1]*s %8s %s\n", 50-(len(wishitem.Get_name())-utf8.RuneCountInString(wishitem.Get_name()))/2, wishitem.Get_name(), wishitem.Get_discount_price_str(), wishitem.Get_discount_percent_str())
}
info += strconv.Itoa(int(selected_total_price+combination.total_price)) + "元"
info += "\n\n"
Expand Down

0 comments on commit 3534e3d

Please sign in to comment.