mirror of
https://github.com/vsariola/sointu.git
synced 2025-11-13 05:12:47 -05:00
drafting
This commit is contained in:
parent
e5a2fbec51
commit
0bd652dcbb
101
tracker/gioui/instrument_properties.go
Normal file
101
tracker/gioui/instrument_properties.go
Normal file
@ -0,0 +1,101 @@
|
||||
package gioui
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op/clip"
|
||||
"gioui.org/op/paint"
|
||||
"gioui.org/text"
|
||||
"gioui.org/unit"
|
||||
"golang.org/x/exp/shiny/materialdesign/icons"
|
||||
)
|
||||
|
||||
type (
|
||||
InstrumentProperties struct {
|
||||
commentEditor *Editor
|
||||
list *layout.List
|
||||
soloBtn *Clickable
|
||||
muteBtn *Clickable
|
||||
soloHint string
|
||||
unsoloHint string
|
||||
muteHint string
|
||||
unmuteHint string
|
||||
voices *NumericUpDownState
|
||||
splitInstrumentBtn *Clickable
|
||||
splitInstrumentHint string
|
||||
}
|
||||
)
|
||||
|
||||
func NewInstrumentProperties() *InstrumentProperties {
|
||||
ret := &InstrumentProperties{
|
||||
list: &layout.List{Axis: layout.Vertical},
|
||||
commentEditor: NewEditor(false, false, text.Start),
|
||||
soloBtn: new(Clickable),
|
||||
muteBtn: new(Clickable),
|
||||
voices: NewNumericUpDownState(),
|
||||
splitInstrumentBtn: new(Clickable),
|
||||
}
|
||||
ret.soloHint = makeHint("Solo", " (%s)", "SoloInstrument")
|
||||
ret.unsoloHint = makeHint("Unsolo", " (%s)", "SoloInstrument")
|
||||
ret.muteHint = makeHint("Mute", " (%s)", "MuteInstrument")
|
||||
ret.unmuteHint = makeHint("Unmute", " (%s)", "MuteInstrument")
|
||||
ret.splitInstrumentHint = makeHint("Split instrument", " (%s)", "SplitInstrument")
|
||||
return ret
|
||||
}
|
||||
|
||||
// update
|
||||
func (ip *InstrumentProperties) update(gtx C, tr *Tracker) {
|
||||
/*for ip.commentEditor.Update(gtx, tr.InstrumentComment()) != EditorEventNone {
|
||||
tr.PatchPanel.instrList.instrumentDragList.Focus()
|
||||
}*/
|
||||
}
|
||||
|
||||
// layout
|
||||
func (ip *InstrumentProperties) layout(gtx C) D {
|
||||
// get tracker from values
|
||||
tr := TrackerFromContext(gtx)
|
||||
voiceLine := func(gtx C) D {
|
||||
splitInstrumentBtn := ActionIconBtn(tr.SplitInstrument(), tr.Theme, ip.splitInstrumentBtn, icons.CommunicationCallSplit, ip.splitInstrumentHint)
|
||||
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
|
||||
layout.Rigid(func(gtx C) D {
|
||||
instrumentVoices := NumUpDown(tr.Model.InstrumentVoices(), tr.Theme, ip.voices, "Number of voices for this instrument")
|
||||
return instrumentVoices.Layout(gtx)
|
||||
}),
|
||||
layout.Rigid(splitInstrumentBtn.Layout),
|
||||
)
|
||||
}
|
||||
return ip.list.Layout(gtx, 7, func(gtx C, index int) D {
|
||||
switch index {
|
||||
case 0:
|
||||
return layoutInstrumentPropertyLine(gtx, "Voices", voiceLine)
|
||||
case 2:
|
||||
muteBtn := ToggleIconBtn(tr.Mute(), tr.Theme, ip.muteBtn, icons.ToggleCheckBoxOutlineBlank, icons.ToggleCheckBox, ip.muteHint, ip.unmuteHint)
|
||||
return layoutInstrumentPropertyLine(gtx, "Mute", muteBtn.Layout)
|
||||
case 4:
|
||||
soloBtn := ToggleIconBtn(tr.Solo(), tr.Theme, ip.soloBtn, icons.ToggleCheckBoxOutlineBlank, icons.ToggleCheckBox, ip.soloHint, ip.unsoloHint)
|
||||
return layoutInstrumentPropertyLine(gtx, "Solo", soloBtn.Layout)
|
||||
case 6:
|
||||
return layout.UniformInset(unit.Dp(6)).Layout(gtx, func(gtx C) D {
|
||||
return ip.commentEditor.Layout(gtx, tr.InstrumentComment(), tr.Theme, &tr.Theme.InstrumentEditor.InstrumentComment, "Comment")
|
||||
})
|
||||
default: // odd valued list items are dividers
|
||||
px := max(gtx.Dp(unit.Dp(1)), 1)
|
||||
paint.FillShape(gtx.Ops, color.NRGBA{255, 255, 255, 3}, clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, px)).Op())
|
||||
return D{Size: image.Pt(gtx.Constraints.Max.X, px)}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func layoutInstrumentPropertyLine(gtx C, text string, content layout.Widget) D {
|
||||
tr := TrackerFromContext(gtx)
|
||||
gtx.Constraints.Max.X = min(gtx.Dp(unit.Dp(200)), gtx.Constraints.Max.X)
|
||||
label := Label(tr.Theme, &tr.Theme.InstrumentEditor.Properties.Label, text)
|
||||
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
|
||||
layout.Rigid(layout.Spacer{Width: 6}.Layout),
|
||||
layout.Rigid(label.Layout),
|
||||
layout.Flexed(1, func(gtx C) D { return layout.Dimensions{Size: gtx.Constraints.Min} }),
|
||||
layout.Rigid(content),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user