Fixed non-existant vehicle communicate, fixed clearButton, added stuff in order to display numerical keyboard on entering input
This commit is contained in:
parent
46c88a1db2
commit
9a38ef2387
1 changed files with 46 additions and 6 deletions
|
@ -3,12 +3,50 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/gocolly/colly/v2"
|
"github.com/gocolly/colly/v2"
|
||||||
|
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/driver/mobile"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type numericalEntry struct {
|
||||||
|
widget.Entry
|
||||||
|
}
|
||||||
|
|
||||||
|
func newNumericalEntry() *numericalEntry {
|
||||||
|
entry := &numericalEntry{}
|
||||||
|
entry.ExtendBaseWidget(entry)
|
||||||
|
return entry
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *numericalEntry) TypedRune(r rune) {
|
||||||
|
if (r >= '0' && r <= '9') || r == '.' || r == ',' {
|
||||||
|
e.Entry.TypedRune(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *numericalEntry) TypedShortcut(shortcut fyne.Shortcut) {
|
||||||
|
paste, ok := shortcut.(*fyne.ShortcutPaste)
|
||||||
|
if !ok {
|
||||||
|
e.Entry.TypedShortcut(shortcut)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
content := paste.Clipboard.Content()
|
||||||
|
if _, err := strconv.ParseFloat(content, 64); err == nil {
|
||||||
|
e.Entry.TypedShortcut(shortcut)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *numericalEntry) Keyboard() mobile.KeyboardType {
|
||||||
|
return mobile.NumberKeyboard
|
||||||
|
}
|
||||||
|
|
||||||
type vehicle struct {
|
type vehicle struct {
|
||||||
producer string
|
producer string
|
||||||
model string
|
model string
|
||||||
|
@ -34,7 +72,7 @@ func getVehicleByNum(vehicleNum string) string {
|
||||||
vehicleURL = text
|
vehicleURL = text
|
||||||
})
|
})
|
||||||
c2.Visit(searchURL)
|
c2.Visit(searchURL)
|
||||||
if searchURL == "" {
|
if vehicleURL == "" {
|
||||||
return ""
|
return ""
|
||||||
} else {
|
} else {
|
||||||
var retrievedData [10]string
|
var retrievedData [10]string
|
||||||
|
@ -79,7 +117,7 @@ func main() {
|
||||||
w := a.NewWindow("Hello")
|
w := a.NewWindow("Hello")
|
||||||
|
|
||||||
output := widget.NewLabel("")
|
output := widget.NewLabel("")
|
||||||
entry := widget.NewEntry()
|
entry := newNumericalEntry()
|
||||||
form := &widget.Form{
|
form := &widget.Form{
|
||||||
Items: []*widget.FormItem{ // we can specify items in the constructor
|
Items: []*widget.FormItem{ // we can specify items in the constructor
|
||||||
{Text: "Podaj numer taborowy pojazdu:", Widget: entry}},
|
{Text: "Podaj numer taborowy pojazdu:", Widget: entry}},
|
||||||
|
@ -96,6 +134,8 @@ func main() {
|
||||||
clearButton := widget.NewButton("Wyczyść", func() {
|
clearButton := widget.NewButton("Wyczyść", func() {
|
||||||
entry.Text = ""
|
entry.Text = ""
|
||||||
output.Text = ""
|
output.Text = ""
|
||||||
|
output.Refresh()
|
||||||
|
entry.Refresh()
|
||||||
})
|
})
|
||||||
w.SetContent(container.NewVBox(
|
w.SetContent(container.NewVBox(
|
||||||
form,
|
form,
|
||||||
|
|
Loading…
Add table
Reference in a new issue