| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638 |
- // auto-generated
- // **** THIS FILE IS AUTO-GENERATED, PLEASE DO NOT EDIT IT **** //
- package binding
- import (
- "fmt"
- "fyne.io/fyne/v2"
- )
- type stringFromBool struct {
- base
- format string
- from Bool
- }
- // BoolToString creates a binding that connects a Bool data item to a String.
- // Changes to the Bool will be pushed to the String and setting the string will parse and set the
- // Bool if the parse was successful.
- //
- // Since: 2.0
- func BoolToString(v Bool) String {
- str := &stringFromBool{from: v}
- v.AddListener(str)
- return str
- }
- // BoolToStringWithFormat creates a binding that connects a Bool data item to a String and is
- // presented using the specified format. Changes to the Bool will be pushed to the String and setting
- // the string will parse and set the Bool if the string matches the format and its parse was successful.
- //
- // Since: 2.0
- func BoolToStringWithFormat(v Bool, format string) String {
- if format == "%t" { // Same as not using custom formatting.
- return BoolToString(v)
- }
- str := &stringFromBool{from: v, format: format}
- v.AddListener(str)
- return str
- }
- func (s *stringFromBool) Get() (string, error) {
- val, err := s.from.Get()
- if err != nil {
- return "", err
- }
- if s.format != "" {
- return fmt.Sprintf(s.format, val), nil
- }
- return formatBool(val), nil
- }
- func (s *stringFromBool) Set(str string) error {
- var val bool
- if s.format != "" {
- safe := stripFormatPrecision(s.format)
- n, err := fmt.Sscanf(str, safe+" ", &val) // " " denotes match to end of string
- if err != nil {
- return err
- }
- if n != 1 {
- return errParseFailed
- }
- } else {
- new, err := parseBool(str)
- if err != nil {
- return err
- }
- val = new
- }
- old, err := s.from.Get()
- if err != nil {
- return err
- }
- if val == old {
- return nil
- }
- if err = s.from.Set(val); err != nil {
- return err
- }
- s.DataChanged()
- return nil
- }
- func (s *stringFromBool) DataChanged() {
- s.lock.RLock()
- defer s.lock.RUnlock()
- s.trigger()
- }
- type stringFromFloat struct {
- base
- format string
- from Float
- }
- // FloatToString creates a binding that connects a Float data item to a String.
- // Changes to the Float will be pushed to the String and setting the string will parse and set the
- // Float if the parse was successful.
- //
- // Since: 2.0
- func FloatToString(v Float) String {
- str := &stringFromFloat{from: v}
- v.AddListener(str)
- return str
- }
- // FloatToStringWithFormat creates a binding that connects a Float data item to a String and is
- // presented using the specified format. Changes to the Float will be pushed to the String and setting
- // the string will parse and set the Float if the string matches the format and its parse was successful.
- //
- // Since: 2.0
- func FloatToStringWithFormat(v Float, format string) String {
- if format == "%f" { // Same as not using custom formatting.
- return FloatToString(v)
- }
- str := &stringFromFloat{from: v, format: format}
- v.AddListener(str)
- return str
- }
- func (s *stringFromFloat) Get() (string, error) {
- val, err := s.from.Get()
- if err != nil {
- return "", err
- }
- if s.format != "" {
- return fmt.Sprintf(s.format, val), nil
- }
- return formatFloat(val), nil
- }
- func (s *stringFromFloat) Set(str string) error {
- var val float64
- if s.format != "" {
- safe := stripFormatPrecision(s.format)
- n, err := fmt.Sscanf(str, safe+" ", &val) // " " denotes match to end of string
- if err != nil {
- return err
- }
- if n != 1 {
- return errParseFailed
- }
- } else {
- new, err := parseFloat(str)
- if err != nil {
- return err
- }
- val = new
- }
- old, err := s.from.Get()
- if err != nil {
- return err
- }
- if val == old {
- return nil
- }
- if err = s.from.Set(val); err != nil {
- return err
- }
- s.DataChanged()
- return nil
- }
- func (s *stringFromFloat) DataChanged() {
- s.lock.RLock()
- defer s.lock.RUnlock()
- s.trigger()
- }
- type stringFromInt struct {
- base
- format string
- from Int
- }
- // IntToString creates a binding that connects a Int data item to a String.
- // Changes to the Int will be pushed to the String and setting the string will parse and set the
- // Int if the parse was successful.
- //
- // Since: 2.0
- func IntToString(v Int) String {
- str := &stringFromInt{from: v}
- v.AddListener(str)
- return str
- }
- // IntToStringWithFormat creates a binding that connects a Int data item to a String and is
- // presented using the specified format. Changes to the Int will be pushed to the String and setting
- // the string will parse and set the Int if the string matches the format and its parse was successful.
- //
- // Since: 2.0
- func IntToStringWithFormat(v Int, format string) String {
- if format == "%d" { // Same as not using custom formatting.
- return IntToString(v)
- }
- str := &stringFromInt{from: v, format: format}
- v.AddListener(str)
- return str
- }
- func (s *stringFromInt) Get() (string, error) {
- val, err := s.from.Get()
- if err != nil {
- return "", err
- }
- if s.format != "" {
- return fmt.Sprintf(s.format, val), nil
- }
- return formatInt(val), nil
- }
- func (s *stringFromInt) Set(str string) error {
- var val int
- if s.format != "" {
- safe := stripFormatPrecision(s.format)
- n, err := fmt.Sscanf(str, safe+" ", &val) // " " denotes match to end of string
- if err != nil {
- return err
- }
- if n != 1 {
- return errParseFailed
- }
- } else {
- new, err := parseInt(str)
- if err != nil {
- return err
- }
- val = new
- }
- old, err := s.from.Get()
- if err != nil {
- return err
- }
- if val == old {
- return nil
- }
- if err = s.from.Set(val); err != nil {
- return err
- }
- s.DataChanged()
- return nil
- }
- func (s *stringFromInt) DataChanged() {
- s.lock.RLock()
- defer s.lock.RUnlock()
- s.trigger()
- }
- type stringFromURI struct {
- base
- from URI
- }
- // URIToString creates a binding that connects a URI data item to a String.
- // Changes to the URI will be pushed to the String and setting the string will parse and set the
- // URI if the parse was successful.
- //
- // Since: 2.1
- func URIToString(v URI) String {
- str := &stringFromURI{from: v}
- v.AddListener(str)
- return str
- }
- func (s *stringFromURI) Get() (string, error) {
- val, err := s.from.Get()
- if err != nil {
- return "", err
- }
- return uriToString(val)
- }
- func (s *stringFromURI) Set(str string) error {
- val, err := uriFromString(str)
- if err != nil {
- return err
- }
- old, err := s.from.Get()
- if err != nil {
- return err
- }
- if val == old {
- return nil
- }
- if err = s.from.Set(val); err != nil {
- return err
- }
- s.DataChanged()
- return nil
- }
- func (s *stringFromURI) DataChanged() {
- s.lock.RLock()
- defer s.lock.RUnlock()
- s.trigger()
- }
- type stringToBool struct {
- base
- format string
- from String
- }
- // StringToBool creates a binding that connects a String data item to a Bool.
- // Changes to the String will be parsed and pushed to the Bool if the parse was successful, and setting
- // the Bool update the String binding.
- //
- // Since: 2.0
- func StringToBool(str String) Bool {
- v := &stringToBool{from: str}
- str.AddListener(v)
- return v
- }
- // StringToBoolWithFormat creates a binding that connects a String data item to a Bool and is
- // presented using the specified format. Changes to the Bool will be parsed and if the format matches and
- // the parse is successful it will be pushed to the String. Setting the Bool will push a formatted value
- // into the String.
- //
- // Since: 2.0
- func StringToBoolWithFormat(str String, format string) Bool {
- if format == "%t" { // Same as not using custom format.
- return StringToBool(str)
- }
- v := &stringToBool{from: str, format: format}
- str.AddListener(v)
- return v
- }
- func (s *stringToBool) Get() (bool, error) {
- str, err := s.from.Get()
- if str == "" || err != nil {
- return false, err
- }
- var val bool
- if s.format != "" {
- n, err := fmt.Sscanf(str, s.format+" ", &val) // " " denotes match to end of string
- if err != nil {
- return false, err
- }
- if n != 1 {
- return false, errParseFailed
- }
- } else {
- new, err := parseBool(str)
- if err != nil {
- return false, err
- }
- val = new
- }
- return val, nil
- }
- func (s *stringToBool) Set(val bool) error {
- var str string
- if s.format != "" {
- str = fmt.Sprintf(s.format, val)
- } else {
- str = formatBool(val)
- }
- old, err := s.from.Get()
- if str == old {
- return err
- }
- if err = s.from.Set(str); err != nil {
- return err
- }
- s.DataChanged()
- return nil
- }
- func (s *stringToBool) DataChanged() {
- s.lock.RLock()
- defer s.lock.RUnlock()
- s.trigger()
- }
- type stringToFloat struct {
- base
- format string
- from String
- }
- // StringToFloat creates a binding that connects a String data item to a Float.
- // Changes to the String will be parsed and pushed to the Float if the parse was successful, and setting
- // the Float update the String binding.
- //
- // Since: 2.0
- func StringToFloat(str String) Float {
- v := &stringToFloat{from: str}
- str.AddListener(v)
- return v
- }
- // StringToFloatWithFormat creates a binding that connects a String data item to a Float and is
- // presented using the specified format. Changes to the Float will be parsed and if the format matches and
- // the parse is successful it will be pushed to the String. Setting the Float will push a formatted value
- // into the String.
- //
- // Since: 2.0
- func StringToFloatWithFormat(str String, format string) Float {
- if format == "%f" { // Same as not using custom format.
- return StringToFloat(str)
- }
- v := &stringToFloat{from: str, format: format}
- str.AddListener(v)
- return v
- }
- func (s *stringToFloat) Get() (float64, error) {
- str, err := s.from.Get()
- if str == "" || err != nil {
- return 0.0, err
- }
- var val float64
- if s.format != "" {
- n, err := fmt.Sscanf(str, s.format+" ", &val) // " " denotes match to end of string
- if err != nil {
- return 0.0, err
- }
- if n != 1 {
- return 0.0, errParseFailed
- }
- } else {
- new, err := parseFloat(str)
- if err != nil {
- return 0.0, err
- }
- val = new
- }
- return val, nil
- }
- func (s *stringToFloat) Set(val float64) error {
- var str string
- if s.format != "" {
- str = fmt.Sprintf(s.format, val)
- } else {
- str = formatFloat(val)
- }
- old, err := s.from.Get()
- if str == old {
- return err
- }
- if err = s.from.Set(str); err != nil {
- return err
- }
- s.DataChanged()
- return nil
- }
- func (s *stringToFloat) DataChanged() {
- s.lock.RLock()
- defer s.lock.RUnlock()
- s.trigger()
- }
- type stringToInt struct {
- base
- format string
- from String
- }
- // StringToInt creates a binding that connects a String data item to a Int.
- // Changes to the String will be parsed and pushed to the Int if the parse was successful, and setting
- // the Int update the String binding.
- //
- // Since: 2.0
- func StringToInt(str String) Int {
- v := &stringToInt{from: str}
- str.AddListener(v)
- return v
- }
- // StringToIntWithFormat creates a binding that connects a String data item to a Int and is
- // presented using the specified format. Changes to the Int will be parsed and if the format matches and
- // the parse is successful it will be pushed to the String. Setting the Int will push a formatted value
- // into the String.
- //
- // Since: 2.0
- func StringToIntWithFormat(str String, format string) Int {
- if format == "%d" { // Same as not using custom format.
- return StringToInt(str)
- }
- v := &stringToInt{from: str, format: format}
- str.AddListener(v)
- return v
- }
- func (s *stringToInt) Get() (int, error) {
- str, err := s.from.Get()
- if str == "" || err != nil {
- return 0, err
- }
- var val int
- if s.format != "" {
- n, err := fmt.Sscanf(str, s.format+" ", &val) // " " denotes match to end of string
- if err != nil {
- return 0, err
- }
- if n != 1 {
- return 0, errParseFailed
- }
- } else {
- new, err := parseInt(str)
- if err != nil {
- return 0, err
- }
- val = new
- }
- return val, nil
- }
- func (s *stringToInt) Set(val int) error {
- var str string
- if s.format != "" {
- str = fmt.Sprintf(s.format, val)
- } else {
- str = formatInt(val)
- }
- old, err := s.from.Get()
- if str == old {
- return err
- }
- if err = s.from.Set(str); err != nil {
- return err
- }
- s.DataChanged()
- return nil
- }
- func (s *stringToInt) DataChanged() {
- s.lock.RLock()
- defer s.lock.RUnlock()
- s.trigger()
- }
- type stringToURI struct {
- base
- from String
- }
- // StringToURI creates a binding that connects a String data item to a URI.
- // Changes to the String will be parsed and pushed to the URI if the parse was successful, and setting
- // the URI update the String binding.
- //
- // Since: 2.1
- func StringToURI(str String) URI {
- v := &stringToURI{from: str}
- str.AddListener(v)
- return v
- }
- func (s *stringToURI) Get() (fyne.URI, error) {
- str, err := s.from.Get()
- if str == "" || err != nil {
- return fyne.URI(nil), err
- }
- return uriFromString(str)
- }
- func (s *stringToURI) Set(val fyne.URI) error {
- str, err := uriToString(val)
- if err != nil {
- return err
- }
- old, err := s.from.Get()
- if str == old {
- return err
- }
- if err = s.from.Set(str); err != nil {
- return err
- }
- s.DataChanged()
- return nil
- }
- func (s *stringToURI) DataChanged() {
- s.lock.RLock()
- defer s.lock.RUnlock()
- s.trigger()
- }
|