Files
8bitMyGoUI/account/volumemixer.go
T
ZacharyZhang-NY c745b082a9 Add account components 386-405; Reduce setting, PinInput Cmd+V
Twenty account components: SettingsList, OptionCycler, KeyBindings,
ControllerMap, ProfileCard, CharacterCreator, LoginForm, PasswordGrid,
SessionList, LanguagePicker, PalettePicker, VolumeMixer,
DifficultySelect, AccessibilityOptions, AccountSwitcher, PlayerSelect,
TwoFactor, About, PatchNotes and FeedbackForm.

The components never check credentials, and no secret reaches the log:
LoginForm reports Submitted and the caller counts Failures; each new
failure clears the password, refocuses it, shakes the form and names no
field. TwoFactor builds on input.PinInput and drains an epoch-aligned
period bar. PalettePicker draws each tile in its own palette on a
pixel.Pad grid.

pixel.Settings.Reduce stills motion like the system preference, the
micro font gains '?', display.Face draws avatar faces anywhere, and
input.PinInput pastes on Cmd+V as native hosts send it.
2026-10-12 08:21:39 -04:00

52 lines
1.3 KiB
Go

package account
import (
"fmt"
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
// Mix is music, effects and voice volume, 0 to 1.
type Mix struct {
BGM, SE, Voice float64
}
type VolumeMixerOptions struct {
Disabled bool
}
type VolumeMixerResult struct {
Element *ui.Element
Changed bool
}
// VolumeMixer sets BGM, SE and VOICE on faders.
func VolumeMixer(c *ui.Context, text string, mix *Mix, o VolumeMixerOptions) VolumeMixerResult {
k := pixel.K(c)
var res VolumeMixerResult
res.Element = ui.Row(c).Gap(k.D(10)).Role(ui.RoleGroup).Label(text).Children(func() {
for _, ch := range []struct {
key string
v *float64
}{{"bgm", &mix.BGM}, {"se", &mix.SE}, {"voice", &mix.Voice}} {
if !(*ch.v >= 0 && *ch.v <= 1) {
panic(fmt.Sprintf("account: VolumeMixer %s at %v", ch.key, *ch.v))
}
ui.Column(c).Gap(k.D(2)).AlignItems(ui.Center).Children(func() {
name := k.Msg(ch.key)
if input.Fader(c, name, ch.v, input.FaderOptions{Height: 56, Disabled: o.Disabled}).Changed {
res.Changed = true
slog.Debug("8bit: volume mixer", "label", text, "channel", ch.key, "level", *ch.v)
}
mark(c, k, name, pixel.Faint, 0)
caption(c, k, fmt.Sprintf("%d%%", int(*ch.v*100+0.5)), pixel.Ink)
})
}
})
return res
}