diff --git a/WHATSNEW.md b/WHATSNEW.md index 38f2784..9e318c8 100644 --- a/WHATSNEW.md +++ b/WHATSNEW.md @@ -1,3 +1,7 @@ +# 1.0.20 + + - Reworked legend to have fixed a more "fixed size" and value to the left + # 1.0.19 - Added E85.X_EthAct_Tech2 to Trionic 7 calibration shortcuts diff --git a/pkg/dashboard/dashboard.go b/pkg/dashboard/dashboard.go index d5eddd3..7c7e33e 100644 --- a/pkg/dashboard/dashboard.go +++ b/pkg/dashboard/dashboard.go @@ -8,7 +8,6 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" - "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" "github.com/roffe/txlogger/pkg/assets" @@ -23,8 +22,6 @@ type Dashboard struct { metricRouter map[string]func(float64) - container *fyne.Container - text Texts gauges Gauges @@ -251,48 +248,10 @@ func NewDashboard(cfg *Config) *Dashboard { db.limpMode.FillMode = canvas.ImageFillContain db.limpMode.SetMinSize(fyne.NewSize(110, 85)) db.limpMode.Resize(fyne.NewSize(110, 85)) - db.render() return db } -func (db *Dashboard) render() { - db.container = container.NewWithoutLayout( - db.limpMode, - //db.dbgBar, - - db.gauges.rpm, - db.gauges.speed, - db.gauges.airmass, - db.gauges.pressure, - db.gauges.iat, - db.gauges.engineTemp, - - db.text.ign, - db.text.ioff, - db.text.idc, - db.text.amul, - - db.text.activeAirDem, - - db.gauges.nblambda, - db.gauges.wblambda, - db.gauges.throttle, - db.gauges.pwm, - db.checkEngine, - db.text.cruise, - db.knockIcon, - ) - - if !db.logplayer { - db.container.Add(db.fullscreenBtn) - db.container.Add(db.closeBtn) - db.container.Add(db.logBtn) - } else { - db.container.Add(db.text.time) - } -} - func (db *Dashboard) GetMetricNames() []string { names := make([]string, 0, len(db.metricRouter)) for k := range db.metricRouter { @@ -734,7 +693,6 @@ func (dr *DashboardRenderer) Layout(space fyne.Size) { return } dr.size = space - dr.db.container.Resize(space) // Calculate common dimensions dims := &dims{ @@ -784,5 +742,41 @@ func (dr *DashboardRenderer) Destroy() { } func (dr *DashboardRenderer) Objects() []fyne.CanvasObject { - return []fyne.CanvasObject{dr.db.container} + + cont := []fyne.CanvasObject{ + dr.db.limpMode, + //db.dbgBar, + + dr.db.gauges.rpm, + dr.db.gauges.speed, + dr.db.gauges.airmass, + dr.db.gauges.pressure, + dr.db.gauges.iat, + dr.db.gauges.engineTemp, + + dr.db.text.ign, + dr.db.text.ioff, + dr.db.text.idc, + dr.db.text.amul, + + dr.db.text.activeAirDem, + + dr.db.gauges.nblambda, + dr.db.gauges.wblambda, + dr.db.gauges.throttle, + dr.db.gauges.pwm, + dr.db.checkEngine, + dr.db.text.cruise, + dr.db.knockIcon, + } + + if !dr.db.logplayer { + cont = append(cont, dr.db.fullscreenBtn) + cont = append(cont, dr.db.closeBtn) + cont = append(cont, dr.db.logBtn) + } else { + cont = append(cont, dr.db.text.time) + } + + return cont } diff --git a/pkg/plotter/plotter.go b/pkg/plotter/plotter.go index bf9b461..0cc4d48 100644 --- a/pkg/plotter/plotter.go +++ b/pkg/plotter/plotter.go @@ -1,11 +1,10 @@ package plotter import ( + "fmt" "image" "image/color" "log" - "sort" - "strconv" "sync" "fyne.io/fyne/v2" @@ -29,9 +28,9 @@ type Plotter struct { canvas fyne.CanvasObject //canvasImageContainer *fyne.Container - texts []*TappableText - legend *fyne.Container - zoom *widget.Slider + legendTexts []*TappableText + legend *fyne.Container + zoom *widget.Slider ts []*TimeSeries plotStartPos int @@ -47,7 +46,7 @@ type Plotter struct { plotResolution fyne.Size plotResolutionFactor float32 - textBuffer []byte + // textBuffer []byte size fyne.Size @@ -98,7 +97,7 @@ func NewPlotter(values map[string][]float64, opts ...PlotterOpt) *Plotter { for k := range values { p.valueOrder = append(p.valueOrder, k) } - sort.Strings(p.valueOrder) + //sort.Strings(p.valueOrder) } for n, k := range p.valueOrder { @@ -132,27 +131,26 @@ func NewPlotter(values map[string][]float64, opts ...PlotterOpt) *Plotter { p.overlayText.Text = k p.overlayText.Color = p.ts[n].Color p.hilightLine = n - p.texts[n].text.TextStyle.Bold = true + p.legendTexts[n].text.TextStyle.Bold = true p.RefreshImage() } else { //p.ts[n].Color = oldColor - p.texts[n].text.TextStyle.Bold = false + p.legendTexts[n].text.TextStyle.Bold = false p.overlayText.Text = "" p.hilightLine = -1 p.RefreshImage() } } - legendLabel := NewTappableText(k, p.ts[n].Color, onTapped, onColorUpdate, onHover) - legendLabel.SetTextSize(14) - p.texts = append(p.texts, legendLabel) - p.legend.Add(legendLabel) + labelText := NewTappableText(k, p.ts[n].Color, onTapped, onColorUpdate, onHover) + p.legendTexts = append(p.legendTexts, labelText) + p.legend.Add(labelText) } p.dataPointsToShow = min(p.dataLength, 250.0) - canvasImage := container.New(&testL{p: p}, p.canvasImage) + canvasImage := container.New(&plotLayout{p: p}, p.canvasImage) leading := container.NewBorder( nil, @@ -162,10 +160,10 @@ func NewPlotter(values map[string][]float64, opts ...PlotterOpt) *Plotter { canvasImage, ) p.container = container.NewHSplit(leading, container.NewVScroll(p.legend)) - p.container.Offset = 0.83 + p.container.Offset = 0.90 p.overlayText = canvas.NewText("", color.White) - p.overlayText.TextSize = 20 + p.overlayText.TextSize = 25 p.canvas = container.NewWithoutLayout( p.container, @@ -175,12 +173,12 @@ func NewPlotter(values map[string][]float64, opts ...PlotterOpt) *Plotter { return p } -type testL struct { +type plotLayout struct { p *Plotter oldSize fyne.Size } -func (t *testL) Layout(_ []fyne.CanvasObject, plotSize fyne.Size) { +func (t *plotLayout) Layout(_ []fyne.CanvasObject, plotSize fyne.Size) { if t.oldSize == plotSize { return } @@ -197,7 +195,7 @@ func (t *testL) Layout(_ []fyne.CanvasObject, plotSize fyne.Size) { t.p.updateCursor() } -func (t *testL) MinSize([]fyne.CanvasObject) fyne.Size { +func (t *plotLayout) MinSize([]fyne.CanvasObject) fyne.Size { return fyne.NewSize(400, 100) } @@ -224,13 +222,13 @@ func (p *Plotter) Seek(pos int) { func (p *Plotter) updateLegend() { for i, v := range p.valueOrder { valueIndex := min(p.dataLength, p.cursorPos) - obj := p.texts[i] - p.textBuffer = p.textBuffer[:0] - p.textBuffer = append(p.textBuffer, v+" "...) - p.textBuffer = strconv.AppendFloat(p.textBuffer, p.values[v][valueIndex], 'f', 2, 64) - obj.text.Text = string(p.textBuffer) + obj := p.legendTexts[i] + //p.textBuffer = p.textBuffer[:0] + //p.textBuffer = append(p.textBuffer, v+" "...) + //obj.Text = string(p.textBuffer) + obj.value.Text = fmt.Sprintf("%g", p.values[v][valueIndex]) //obj.text.Text = v + ": " + strconv.FormatFloat(p.values[v][valueIndex], 'f', 2, 64) - p.texts[i].Refresh() + p.legendTexts[i].value.Refresh() } } diff --git a/pkg/plotter/text.go b/pkg/plotter/text.go index 5597a0a..756d84b 100644 --- a/pkg/plotter/text.go +++ b/pkg/plotter/text.go @@ -14,17 +14,23 @@ import ( type TappableText struct { widget.BaseWidget + container *fyne.Container text *canvas.Text + value *canvas.Text enabled bool onTapped func(bool) onColorUpdate func(col color.Color) onHover func(bool) color color.Color + + oldSize fyne.Size } func NewTappableText(text string, col color.Color, onTapped func(enabled bool), onColorUpdate func(col color.Color), onHover func(bool)) *TappableText { tt := &TappableText{ + container: container.NewWithoutLayout(), text: canvas.NewText(text, col), + value: canvas.NewText("0", col), enabled: true, onTapped: onTapped, onColorUpdate: onColorUpdate, @@ -50,7 +56,15 @@ func NewTappableText(text string, col color.Color, onTapped func(enabled bool), } } + tt.text.TextSize = 14 tt.text.TextStyle = fyne.TextStyle{Bold: false, Italic: false} + + tt.value.TextSize = 14 + tt.value.TextStyle = fyne.TextStyle{Bold: false, Italic: false} + + tt.container.Add(tt.value) + tt.container.Add(tt.text) + tt.ExtendBaseWidget(tt) return tt } @@ -70,14 +84,18 @@ func (tt *TappableText) MouseOut() { func (tt *TappableText) Enable() { tt.enabled = true tt.text.Color = tt.color + tt.value.Color = tt.color tt.text.TextStyle = fyne.TextStyle{Bold: false, Italic: false} + tt.value.TextStyle = fyne.TextStyle{Bold: false, Italic: false} tt.text.Refresh() } func (tt *TappableText) Disable() { tt.enabled = false tt.text.TextStyle = fyne.TextStyle{Bold: false, Italic: true} + tt.value.TextStyle = fyne.TextStyle{Bold: false, Italic: true} tt.text.Color = color.RGBA{128, 128, 128, 255} + tt.value.Color = color.RGBA{128, 128, 128, 255} tt.text.Refresh() } @@ -113,10 +131,38 @@ func (tt *TappableText) TappedSecondary(*fyne.PointEvent) { modal.Show() } -func (tt *TappableText) SetTextSize(size int) { - tt.text.TextSize = float32(size) +func (tt *TappableText) CreateRenderer() fyne.WidgetRenderer { + return &TappableTextRenderer{ + t: tt, + } +} + +type TappableTextRenderer struct { + t *TappableText } -func (tt *TappableText) CreateRenderer() fyne.WidgetRenderer { - return widget.NewSimpleRenderer(tt.text) +func (tr *TappableTextRenderer) Layout(size fyne.Size) { + if tr.t.oldSize == size { + return + } + tr.t.oldSize = size + + tr.t.value.Move(fyne.NewPos(0, 0)) + tr.t.text.Move(fyne.NewPos(60, 0)) +} + +func (tr *TappableTextRenderer) MinSize() fyne.Size { + return fyne.NewSize(200, 18) +} + +func (tr *TappableTextRenderer) Refresh() { + tr.t.value.Refresh() + +} + +func (tr *TappableTextRenderer) Objects() []fyne.CanvasObject { + return []fyne.CanvasObject{tr.t.value, tr.t.text} +} + +func (tr *TappableTextRenderer) Destroy() { } diff --git a/pkg/widgets/can_settings.go b/pkg/widgets/can_settings.go index f0bf43d..b02faad 100644 --- a/pkg/widgets/can_settings.go +++ b/pkg/widgets/can_settings.go @@ -2,6 +2,7 @@ package widgets import ( "errors" + "sort" "strconv" "strings" @@ -156,16 +157,16 @@ func (cs *CanSettingsWidget) GetAdapter(ecuType string, logger func(string)) (go baudrate, err := strconv.Atoi(baudstring) if cs.adapterSelector.Selected == "" { - return nil, errors.New("No adapter selected") //lint:ignore ST1005 This is ok + return nil, errors.New("Select CANbus adapter in settings") //lint:ignore ST1005 This is ok } if adapter.GetAdapterMap()[cs.adapterSelector.Selected].RequiresSerialPort { if cs.portSelector.Selected == "" { - return nil, errors.New("No port selected") //lint:ignore ST1005 This is ok + return nil, errors.New("Select port in setings") //lint:ignore ST1005 This is ok } if cs.speedSelector.Selected == "" { - return nil, errors.New("No speed selected") //lint:ignore ST1005 This is ok + return nil, errors.New("Select port speed in settings") //lint:ignore ST1005 This is ok } } @@ -226,6 +227,7 @@ func (cs *CanSettingsWidget) listPorts() []string { //m.output("No serial ports found!") return []string{} } + for _, port := range ports { //m.output(fmt.Sprintf("Found port: %s", port.Name)) //if port.IsUSB { @@ -234,6 +236,9 @@ func (cs *CanSettingsWidget) listPorts() []string { portsList = append(portsList, port.Name) //} } + + sort.Strings(portsList) + return portsList } diff --git a/pkg/windows/logplayer.go b/pkg/windows/logplayer.go index 5760282..1db19c2 100644 --- a/pkg/windows/logplayer.go +++ b/pkg/windows/logplayer.go @@ -6,6 +6,7 @@ import ( "log" "os" "path/filepath" + "sort" "strconv" "strings" "time" @@ -339,6 +340,8 @@ func (lp *LogPlayer) setupPlot(logz logfile.Logfile) { factor = 1 } + sort.Strings(order) + plotterOpts := []plotter.PlotterOpt{ plotter.WithPlotResolutionFactor(factor), plotter.WithOrder(order), diff --git a/pkg/windows/mainWindow_buttons.go b/pkg/windows/mainWindow_buttons.go index 556d3fe..0efd1b2 100644 --- a/pkg/windows/mainWindow_buttons.go +++ b/pkg/windows/mainWindow_buttons.go @@ -229,7 +229,8 @@ func (mw *MainWindow) newSettingsBtn() *widget.Button { func (mw *MainWindow) startLogging() { device, err := mw.settings.CanSettings.GetAdapter(mw.ecuSelect.Selected, mw.Log) if err != nil { - mw.Log(err.Error()) + d := dialog.NewError(err, mw) + d.Show() return }