Adapt playback layout and fonts for displays and add contrast fading
This commit is contained in:
9 files changed
+104
-28
No files matched your search
@@ -41,6 +41,9 @@ type Context interface {
|
||||
|
||||
// Settings are the user settings.
|
||||
Settings() *config.Settings
|
||||
|
||||
// SetContrast updates all screen's contrast.
|
||||
SetContrast(level uint8)
|
||||
}
|
||||
|
||||
type Widget interface {
|
||||
|
||||
Binary file not shown.
@@ -17,6 +17,9 @@ var (
|
||||
|
||||
//go:embed asset/spleen-8x16.bdf
|
||||
spleen8x16BDF []byte
|
||||
|
||||
//go:embed asset/unifont-16.0.02.bdf
|
||||
unifontBDF []byte
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -16,6 +16,7 @@ var (
|
||||
Spleen5x8 = Must(NewFromBytes(spleen5x8BDF))
|
||||
Spleen6x12 = Must(NewFromBytes(spleen6x12BDF))
|
||||
Spleen8x16 = Must(NewFromBytes(spleen8x16BDF))
|
||||
Unifont = Must(NewFromBytes(unifontBDF))
|
||||
)
|
||||
|
||||
// Icons mapped in SM4TIK
|
||||
|
||||
+49
-19
@@ -11,6 +11,7 @@ import (
|
||||
"periph.io/x/conn/v3/physic"
|
||||
|
||||
"github.com/BeatGlow/audio"
|
||||
"github.com/BeatGlow/display/pixel"
|
||||
|
||||
"github.com/BeatGlow/beatglow/app"
|
||||
"github.com/BeatGlow/beatglow/app/font"
|
||||
@@ -48,11 +49,20 @@ type playing struct {
|
||||
spectrumWidget *widget.Spectrum
|
||||
}
|
||||
|
||||
const playingWaterfallHeight = 32
|
||||
|
||||
func Playing(ctx app.Context) app.Layout {
|
||||
bounds := ctx.Display().Bounds()
|
||||
styles := app.StylesFor(ctx.Display().ColorModel())
|
||||
var (
|
||||
config = ctx.Settings()
|
||||
bounds = ctx.Display().Bounds()
|
||||
cmodel = ctx.Display().ColorModel()
|
||||
styles = app.StylesFor(cmodel)
|
||||
playingWaterfallHeight = bounds.Dy() - 32
|
||||
maxWidth = bounds.Dx() - bounds.Dy()
|
||||
)
|
||||
|
||||
if !config.Player.ShowArt {
|
||||
maxWidth = bounds.Dx()
|
||||
}
|
||||
|
||||
layout := &playing{
|
||||
base: base{name: "playing"},
|
||||
settings: ctx.Settings(),
|
||||
@@ -62,21 +72,29 @@ func Playing(ctx app.Context) app.Layout {
|
||||
durationText: durationTextPlaceholder,
|
||||
durationWidget: widget.NewText(image.Pt(2+len(durationTextPlaceholder)*9, 12)),
|
||||
trackText: trackTextPlaceholder,
|
||||
trackWidget: widget.NewText(image.Pt(bounds.Dx()-bounds.Dy(), bounds.Dy()-12-playingWaterfallHeight)),
|
||||
trackWidget: widget.NewText(image.Pt(maxWidth, bounds.Dy()-12-playingWaterfallHeight)),
|
||||
iconText: iconTextPlaceholder,
|
||||
iconWidget: widget.NewText(image.Pt(10, 12)),
|
||||
artWidget: widget.NewImage(image.Pt(bounds.Dy(), bounds.Dy())),
|
||||
spectrumWidget: widget.NewSpectrum(image.Pt(bounds.Dx()-bounds.Dy(), playingWaterfallHeight)),
|
||||
spectrumWidget: widget.NewSpectrum(image.Pt(maxWidth, playingWaterfallHeight)),
|
||||
}
|
||||
if config.Player.ShowArt {
|
||||
layout.artWidget = widget.NewImage(image.Pt(bounds.Dy(), bounds.Dy()))
|
||||
}
|
||||
|
||||
var (
|
||||
formatStyle = styles.Text.WithFont(font.Spleen6x12)
|
||||
iconStyle = styles.Text.WithFont(font.SM4TIK).WithForegroundColor(color.Gray{0x3f})
|
||||
iconStyle = styles.Text.WithFont(font.SM4TIK).WithForegroundColor(color.Gray{0x80})
|
||||
durationStyle = formatStyle
|
||||
titleStyle = styles.Text.WithFont(font.Montserrat.WithPointSize(20))
|
||||
offset int
|
||||
)
|
||||
|
||||
switch cmodel {
|
||||
case pixel.MonoModel:
|
||||
titleFont := font.Unifont
|
||||
titleStyle = styles.Text.WithFont(titleFont)
|
||||
}
|
||||
|
||||
layout.phonesWidget.
|
||||
SetStyle(iconStyle).
|
||||
Update(string(font.IconNote)).
|
||||
@@ -110,8 +128,10 @@ func Playing(ctx app.Context) app.Layout {
|
||||
Bind(&layout.trackText).
|
||||
Move(image.Pt(0, 12))
|
||||
|
||||
layout.artWidget.
|
||||
Move(image.Pt(bounds.Dx()-bounds.Dy(), 0))
|
||||
if config.Player.ShowArt {
|
||||
layout.artWidget.
|
||||
Move(image.Pt(bounds.Dx()-bounds.Dy(), 0))
|
||||
}
|
||||
|
||||
layout.spectrumWidget.
|
||||
SetWaterfall(false).
|
||||
@@ -125,9 +145,11 @@ func Playing(ctx app.Context) app.Layout {
|
||||
layout.iconWidget,
|
||||
layout.durationWidget,
|
||||
layout.trackWidget,
|
||||
layout.artWidget,
|
||||
layout.spectrumWidget,
|
||||
}
|
||||
if config.Player.ShowArt {
|
||||
layout.widgets = append(layout.widgets, layout.artWidget)
|
||||
}
|
||||
|
||||
return layout
|
||||
}
|
||||
@@ -160,8 +182,10 @@ func (l *playing) TrackChanged(ctx app.Context, track *player.Track) {
|
||||
|
||||
if !track.Eq(l.track) {
|
||||
l.track = track
|
||||
l.artWidget.Update(beatglowLogo, ctx.Display().ColorModel())
|
||||
go l.updateArt(ctx, track)
|
||||
if ctx.Settings().Player.ShowArt {
|
||||
l.artWidget.Update(beatglowLogo, ctx.Display().ColorModel())
|
||||
go l.updateArt(ctx, track)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,6 +199,7 @@ func (l *playing) updateArt(ctx app.Context, track *player.Track) {
|
||||
}
|
||||
}
|
||||
log.Debug("updating album art failed: unavailable")
|
||||
|
||||
}
|
||||
|
||||
func (l *playing) StatusChanged(ctx app.Context, status *player.Status) {
|
||||
@@ -188,10 +213,13 @@ func (l *playing) StatusChanged(ctx app.Context, status *player.Status) {
|
||||
|
||||
if status.Paused {
|
||||
l.iconText = string(font.IconPause)
|
||||
ctx.SetContrast(ctx.Settings().Display.Contrast)
|
||||
} else if status.Playing {
|
||||
l.iconText = string(font.IconPlay)
|
||||
ctx.SetContrast(ctx.Settings().Display.Contrast)
|
||||
} else {
|
||||
l.iconText = string(font.IconStop)
|
||||
ctx.SetContrast(1)
|
||||
}
|
||||
|
||||
if status.Duration > 0 {
|
||||
@@ -199,12 +227,14 @@ func (l *playing) StatusChanged(ctx app.Context, status *player.Status) {
|
||||
}
|
||||
|
||||
if status.Track != nil {
|
||||
if l.formatRate {
|
||||
l.formatText = fmt.Sprintf("%04d@%s", status.Format.BitRate, formatRate(status.Format.SampleRate))
|
||||
} else {
|
||||
l.formatText = fmt.Sprintf("%-4s@%s", strings.ToUpper(status.Track.Format), formatRate(status.Format.SampleRate))
|
||||
}
|
||||
l.formatRate = !l.formatRate
|
||||
//if l.formatRate {
|
||||
// l.formatText = fmt.Sprintf("%04d@%s", status.Format.BitRate, formatRate(status.Format.SampleRate))
|
||||
//} else {
|
||||
l.formatText = fmt.Sprintf("%-4s@%s", strings.ToUpper(status.Track.Format), formatRate(status.Format.SampleRate))
|
||||
//}
|
||||
//l.formatRate = !l.formatRate
|
||||
} else {
|
||||
l.formatText = formatTextPlaceholder
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ var (
|
||||
|
||||
var (
|
||||
defaultMonoObjectStyle = ObjectStyle{
|
||||
BackgroundImage: image.Black,
|
||||
BackgroundColor: pixel.Off,
|
||||
ForegroundColor: pixel.On,
|
||||
BorderColor: pixel.On,
|
||||
@@ -35,7 +36,7 @@ var (
|
||||
Graph: defaultMonoObjectStyle,
|
||||
Text: TextStyle{
|
||||
ObjectStyle: defaultMonoObjectStyle,
|
||||
Font: font.SmoochSans,
|
||||
Font: font.Spleen5x8,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user