feat: add horizontal mixer layout
Persist a vertical or horizontal mixer orientation in the profile and expose it in Config. Horizontal mode packs fader cards into width-aware bands while keeping separators full-width and respecting per-fader density. Tests: cargo fmt --all -- --check; cargo check --workspace --all-targets --all-features; cargo test --workspace --all-targets --all-features; cargo test --workspace --doc --all-features; cargo clippy --workspace --all-targets --all-features -- -D warnings; cargo build --workspace --release --all-features; default/no-default/backend feature checks.
This commit is contained in:
parent
2fe7824203
commit
acb0f609cb
10
README.md
10
README.md
|
|
@ -54,10 +54,12 @@ volume and mute. Learning opens a waiting popup and captures the next supported
|
|||
fader movement or button press from the selected controller. The editor also
|
||||
provides per-fader Size (`Slim`, `Standard`, or `Thick`) and visibility. Slim
|
||||
faders occupy one terminal row; Standard remains the compatible default. The
|
||||
Config tab is a settings/status page: change the session theme, restore
|
||||
individual hidden faders, inspect backend and MIDI-device state, and apply or
|
||||
save the server-owned draft. The old `Shift+h` hidden-list mode and
|
||||
pipe-delimited object editors are no longer used.
|
||||
Config tab is a settings/status page: change the session theme, switch the
|
||||
persisted mixer layout between Vertical and Horizontal, restore individual
|
||||
hidden faders, inspect backend and MIDI-device state, and apply or save the
|
||||
server-owned draft. Horizontal mode packs fader cards side by side and keeps
|
||||
separators full-width. The old `Shift+h` hidden-list mode and pipe-delimited
|
||||
object editors are no longer used.
|
||||
|
||||
# References
|
||||
|
||||
|
|
|
|||
|
|
@ -404,7 +404,9 @@ rejects duplicate layout IDs, duplicate fader references, and dangling fader
|
|||
references. Each fader layout entry also stores a `slim`, `standard`, or `thick`
|
||||
vertical density. Omitted density defaults to `standard` for existing profiles;
|
||||
`slim` is a single terminal row while the other modes retain progressively more
|
||||
vertical detail.
|
||||
vertical detail. The profile-level `ui.mixer_orientation` is `vertical` by
|
||||
default for compatibility. `horizontal` packs fader cards into display-width
|
||||
rows while separators remain full-width boundaries.
|
||||
|
||||
The selected main-list entry can be moved directly, and separators can be
|
||||
added, renamed, moved, or removed. Editing a fader presents domain fields
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ use std::str::FromStr;
|
|||
|
||||
use toml_edit::{Array, ArrayOfTables, DocumentMut, InlineTable, Item, Table, Value, value};
|
||||
|
||||
use crate::{Action, ConfigError, FaderDensity, MessageKind, Profile, SelectorField, TargetKind};
|
||||
use crate::{
|
||||
Action, ConfigError, FaderDensity, MessageKind, MixerOrientation, Profile, SelectorField,
|
||||
TargetKind,
|
||||
};
|
||||
|
||||
/// Match expression used when creating an application selector.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
|
|
@ -32,6 +35,27 @@ impl ProfileDocument {
|
|||
Ok(Self { document })
|
||||
}
|
||||
|
||||
/// Changes the direction used to arrange faders in the mixer.
|
||||
pub fn set_mixer_orientation(
|
||||
&mut self,
|
||||
orientation: MixerOrientation,
|
||||
) -> Result<(), ConfigError> {
|
||||
self.transaction(|document| {
|
||||
if document.get("ui").is_none() {
|
||||
document["ui"] = Item::Table(Table::new());
|
||||
}
|
||||
let ui = document
|
||||
.get_mut("ui")
|
||||
.and_then(Item::as_table_mut)
|
||||
.ok_or_else(|| ConfigError::validation("ui", "must be a table"))?;
|
||||
ui["mixer_orientation"] = value(match orientation {
|
||||
MixerOrientation::Vertical => "vertical",
|
||||
MixerOrientation::Horizontal => "horizontal",
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
/// Changes one application's display label without rebuilding its table.
|
||||
pub fn set_application_label(
|
||||
&mut self,
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ pub use files::{AtomicFile, MigrationError, PersistenceError, StateLoad, migrate
|
|||
pub use paths::{XdgEnvironment, XdgPaths};
|
||||
pub use profile::{
|
||||
Action, Adapter, Application, Audio, Binding, Fader, FaderDensity, Group, MessageKind,
|
||||
MixerLayoutEntry, NewStreamPolicy, Profile, Selector, SelectorField, StartupPolicy, Surface,
|
||||
TargetKind,
|
||||
MixerLayoutEntry, MixerOrientation, NewStreamPolicy, Profile, Selector, SelectorField,
|
||||
StartupPolicy, Surface, TargetKind,
|
||||
};
|
||||
pub use state::{
|
||||
CachedObservation, DesiredWrite, PersistedState, ProfileState, StartupState, UiView,
|
||||
|
|
|
|||
|
|
@ -34,6 +34,22 @@ const fn default_poll_interval_ms() -> u64 {
|
|||
DEFAULT_POLL_INTERVAL_MS
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct UiSettings {
|
||||
#[serde(default)]
|
||||
mixer_orientation: MixerOrientation,
|
||||
}
|
||||
|
||||
/// Direction used to arrange fader displays in the mixer.
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum MixerOrientation {
|
||||
#[default]
|
||||
Vertical,
|
||||
Horizontal,
|
||||
}
|
||||
|
||||
/// Behavior when a profile becomes active.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
|
|
@ -278,6 +294,8 @@ struct RawProfile {
|
|||
new_stream: NewStreamPolicy,
|
||||
#[serde(default)]
|
||||
runtime: RuntimeSettings,
|
||||
#[serde(default)]
|
||||
ui: UiSettings,
|
||||
audio: Audio,
|
||||
#[serde(default)]
|
||||
applications: Vec<Application>,
|
||||
|
|
@ -368,6 +386,11 @@ impl Profile {
|
|||
&self.mixer_layout
|
||||
}
|
||||
|
||||
/// Direction used to arrange fader displays in the mixer.
|
||||
pub const fn mixer_orientation(&self) -> MixerOrientation {
|
||||
self.raw.ui.mixer_orientation
|
||||
}
|
||||
|
||||
/// Validated bindings.
|
||||
pub fn bindings(&self) -> &[Binding] {
|
||||
&self.raw.bindings
|
||||
|
|
|
|||
|
|
@ -164,6 +164,9 @@ fn mixer_layout_draft_reorders_separators_and_retains_hidden_faders() {
|
|||
1,
|
||||
);
|
||||
let mut draft = ProfileDocument::parse(&source).unwrap();
|
||||
draft
|
||||
.set_mixer_orientation(fader_config::MixerOrientation::Horizontal)
|
||||
.expect("mixer orientation must be editable");
|
||||
draft
|
||||
.set_fader_hidden("media-fader", true)
|
||||
.expect("fader must be hidden without deletion");
|
||||
|
|
@ -178,6 +181,10 @@ fn mixer_layout_draft_reorders_separators_and_retains_hidden_faders() {
|
|||
.expect("separator label must be editable");
|
||||
|
||||
let profile = draft.preview().unwrap();
|
||||
assert_eq!(
|
||||
profile.mixer_orientation(),
|
||||
fader_config::MixerOrientation::Horizontal
|
||||
);
|
||||
assert_eq!(
|
||||
profile.mixer_layout(),
|
||||
[
|
||||
|
|
|
|||
|
|
@ -52,6 +52,10 @@ fn validated_profile_exposes_compiled_runtime_application_and_group_views() {
|
|||
#[test]
|
||||
fn mixer_layout_defaults_to_declared_faders_and_validates_explicit_entries() {
|
||||
let profile = Profile::parse(EXAMPLE).expect("legacy profile must synthesize its layout");
|
||||
assert_eq!(
|
||||
profile.mixer_orientation(),
|
||||
fader_config::MixerOrientation::Vertical
|
||||
);
|
||||
assert_eq!(
|
||||
profile.mixer_layout(),
|
||||
[MixerLayoutEntry::Fader {
|
||||
|
|
@ -93,6 +97,16 @@ fn mixer_layout_defaults_to_declared_faders_and_validates_explicit_entries() {
|
|||
|
||||
let dangling = explicit.replace("fader = \"media-fader\"", "fader = \"missing\"");
|
||||
assert_error_contains(Profile::parse(&dangling), "unknown fader");
|
||||
|
||||
let horizontal = EXAMPLE.replacen(
|
||||
"[runtime]",
|
||||
"[ui]\nmixer_orientation = \"horizontal\"\n\n[runtime]",
|
||||
1,
|
||||
);
|
||||
assert_eq!(
|
||||
Profile::parse(&horizontal).unwrap().mixer_orientation(),
|
||||
fader_config::MixerOrientation::Horizontal
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -204,6 +204,16 @@ impl ConfigurationEditor {
|
|||
crate::ipc::FaderDensity::Thick => fader_config::FaderDensity::Thick,
|
||||
},
|
||||
)?,
|
||||
ConfigurationEdit::SetMixerOrientation { orientation } => {
|
||||
self.document.set_mixer_orientation(match orientation {
|
||||
crate::ipc::MixerOrientation::Vertical => {
|
||||
fader_config::MixerOrientation::Vertical
|
||||
}
|
||||
crate::ipc::MixerOrientation::Horizontal => {
|
||||
fader_config::MixerOrientation::Horizontal
|
||||
}
|
||||
})?
|
||||
}
|
||||
ConfigurationEdit::AddSeparator {
|
||||
id,
|
||||
label,
|
||||
|
|
@ -377,7 +387,7 @@ mod tests {
|
|||
},
|
||||
)
|
||||
.unwrap();
|
||||
let profile = editor
|
||||
editor
|
||||
.apply(
|
||||
2,
|
||||
ConfigurationEdit::SetFaderDensity {
|
||||
|
|
@ -386,6 +396,14 @@ mod tests {
|
|||
},
|
||||
)
|
||||
.unwrap();
|
||||
let profile = editor
|
||||
.apply(
|
||||
3,
|
||||
ConfigurationEdit::SetMixerOrientation {
|
||||
orientation: crate::ipc::MixerOrientation::Horizontal,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(profile.faders().len(), 1);
|
||||
assert_eq!(profile.mixer_layout().len(), 2);
|
||||
assert!(matches!(
|
||||
|
|
@ -395,7 +413,11 @@ mod tests {
|
|||
..
|
||||
}
|
||||
));
|
||||
assert_eq!(editor.revision(), 3);
|
||||
assert_eq!(
|
||||
profile.mixer_orientation(),
|
||||
fader_config::MixerOrientation::Horizontal
|
||||
);
|
||||
assert_eq!(editor.revision(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::io::{self, Read, Write};
|
|||
use serde::{Deserialize, Serialize, de::DeserializeOwned};
|
||||
use thiserror::Error;
|
||||
|
||||
pub const PROTOCOL_VERSION: u16 = 13;
|
||||
pub const PROTOCOL_VERSION: u16 = 14;
|
||||
pub const MAX_FRAME_BYTES: usize = 64 * 1024;
|
||||
|
||||
/// Kind of mixer object addressed by a client.
|
||||
|
|
@ -161,6 +161,9 @@ pub enum ConfigurationEdit {
|
|||
id: String,
|
||||
density: FaderDensity,
|
||||
},
|
||||
SetMixerOrientation {
|
||||
orientation: MixerOrientation,
|
||||
},
|
||||
AddSeparator {
|
||||
id: String,
|
||||
label: String,
|
||||
|
|
@ -208,6 +211,7 @@ pub struct ConfigurationSnapshot {
|
|||
pub learning: Option<String>,
|
||||
pub error: Option<String>,
|
||||
pub profile_id: String,
|
||||
pub mixer_orientation: MixerOrientation,
|
||||
pub applications: Vec<ConfiguredApplication>,
|
||||
pub groups: Vec<ConfiguredGroup>,
|
||||
pub faders: Vec<ConfiguredFader>,
|
||||
|
|
@ -215,6 +219,14 @@ pub struct ConfigurationSnapshot {
|
|||
pub bindings: Vec<ConfiguredBinding>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum MixerOrientation {
|
||||
#[default]
|
||||
Vertical,
|
||||
Horizontal,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(tag = "kind", rename_all = "snake_case")]
|
||||
pub enum MixerLayoutEntry {
|
||||
|
|
|
|||
|
|
@ -116,6 +116,10 @@ pub(crate) fn configuration_snapshot(
|
|||
learning: None,
|
||||
error: None,
|
||||
profile_id: profile.id().to_string(),
|
||||
mixer_orientation: match profile.mixer_orientation() {
|
||||
fader_config::MixerOrientation::Vertical => crate::ipc::MixerOrientation::Vertical,
|
||||
fader_config::MixerOrientation::Horizontal => crate::ipc::MixerOrientation::Horizontal,
|
||||
},
|
||||
applications: profile
|
||||
.applications()
|
||||
.iter()
|
||||
|
|
|
|||
|
|
@ -97,6 +97,12 @@ impl IpcMixerClient {
|
|||
learning: snapshot.configuration.learning,
|
||||
error: snapshot.configuration.error,
|
||||
profile_id: snapshot.configuration.profile_id,
|
||||
mixer_orientation: match snapshot.configuration.mixer_orientation {
|
||||
crate::ipc::MixerOrientation::Vertical => tui::MixerOrientation::Vertical,
|
||||
crate::ipc::MixerOrientation::Horizontal => {
|
||||
tui::MixerOrientation::Horizontal
|
||||
}
|
||||
},
|
||||
applications: snapshot
|
||||
.configuration
|
||||
.applications
|
||||
|
|
@ -357,6 +363,12 @@ fn configuration_edit(edit: TuiConfigurationEdit) -> crate::ipc::ConfigurationEd
|
|||
tui::FaderDensity::Thick => crate::ipc::FaderDensity::Thick,
|
||||
},
|
||||
},
|
||||
TuiConfigurationEdit::SetMixerOrientation { orientation } => IpcEdit::SetMixerOrientation {
|
||||
orientation: match orientation {
|
||||
tui::MixerOrientation::Vertical => crate::ipc::MixerOrientation::Vertical,
|
||||
tui::MixerOrientation::Horizontal => crate::ipc::MixerOrientation::Horizontal,
|
||||
},
|
||||
},
|
||||
TuiConfigurationEdit::AddSeparator {
|
||||
id,
|
||||
label,
|
||||
|
|
|
|||
4
task.md
4
task.md
|
|
@ -367,7 +367,9 @@ Dependencies: M8, M2, M1.
|
|||
layout and provides direct move, separator add/rename/remove, hide, and
|
||||
hidden-fader restore actions through revisioned comment-preserving drafts.
|
||||
Hidden restoration now lives in the Config settings page rather than a
|
||||
second mixer mode.
|
||||
second mixer mode. Config also persists a Vertical or Horizontal mixer
|
||||
orientation; horizontal mode packs faders side by side while separators span
|
||||
the display width.
|
||||
- [x] **M9.5 Guided fader editor:** replace pipe-delimited table commands with a
|
||||
selected-fader form. Application faders edit capture field/mode/pattern;
|
||||
groups select eligible application faders and show the absolute group mode;
|
||||
|
|
|
|||
291
tui/src/lib.rs
291
tui/src/lib.rs
|
|
@ -83,6 +83,7 @@ pub struct ConfigurationSnapshot {
|
|||
pub learning: Option<String>,
|
||||
pub error: Option<String>,
|
||||
pub profile_id: String,
|
||||
pub mixer_orientation: MixerOrientation,
|
||||
pub applications: Vec<ConfiguredApplication>,
|
||||
pub groups: Vec<ConfiguredGroup>,
|
||||
pub faders: Vec<ConfiguredFader>,
|
||||
|
|
@ -90,6 +91,29 @@ pub struct ConfigurationSnapshot {
|
|||
pub bindings: Vec<ConfiguredBinding>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
pub enum MixerOrientation {
|
||||
#[default]
|
||||
Vertical,
|
||||
Horizontal,
|
||||
}
|
||||
|
||||
impl MixerOrientation {
|
||||
const fn label(self) -> &'static str {
|
||||
match self {
|
||||
Self::Vertical => "Vertical",
|
||||
Self::Horizontal => "Horizontal",
|
||||
}
|
||||
}
|
||||
|
||||
const fn toggled(self) -> Self {
|
||||
match self {
|
||||
Self::Vertical => Self::Horizontal,
|
||||
Self::Horizontal => Self::Vertical,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum MixerLayoutEntry {
|
||||
Fader {
|
||||
|
|
@ -224,6 +248,9 @@ pub enum ConfigurationEdit {
|
|||
id: String,
|
||||
density: FaderDensity,
|
||||
},
|
||||
SetMixerOrientation {
|
||||
orientation: MixerOrientation,
|
||||
},
|
||||
AddSeparator {
|
||||
id: String,
|
||||
label: String,
|
||||
|
|
@ -792,6 +819,7 @@ struct EditorInput {
|
|||
|
||||
enum SettingsRow {
|
||||
Theme,
|
||||
MixerOrientation,
|
||||
HiddenFader { id: String, label: String },
|
||||
CancelMidiLearn,
|
||||
Apply,
|
||||
|
|
@ -1215,7 +1243,7 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
}
|
||||
|
||||
fn settings_rows(&self) -> Vec<SettingsRow> {
|
||||
let mut rows = vec![SettingsRow::Theme];
|
||||
let mut rows = vec![SettingsRow::Theme, SettingsRow::MixerOrientation];
|
||||
rows.extend(self.snapshot.configuration.mixer_layout.iter().filter_map(
|
||||
|entry| match entry {
|
||||
MixerLayoutEntry::Fader {
|
||||
|
|
@ -1285,6 +1313,11 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
self.theme.previous()
|
||||
};
|
||||
}
|
||||
SettingsRow::MixerOrientation => {
|
||||
self.apply_layout_edit(ConfigurationEdit::SetMixerOrientation {
|
||||
orientation: self.snapshot.configuration.mixer_orientation.toggled(),
|
||||
});
|
||||
}
|
||||
SettingsRow::HiddenFader { id, .. } if forward => {
|
||||
self.apply_layout_edit(ConfigurationEdit::SetFaderHidden { id, hidden: false });
|
||||
self.clamp_selection();
|
||||
|
|
@ -2337,6 +2370,9 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
};
|
||||
let value = match row {
|
||||
SettingsRow::Theme => format!("Theme {} [←→]", self.theme.label()),
|
||||
SettingsRow::MixerOrientation => {
|
||||
format!("Mixer layout {} [←→]", config.mixer_orientation.label())
|
||||
}
|
||||
SettingsRow::HiddenFader { label, .. } => {
|
||||
format!("Show hidden fader {label} [Enter]")
|
||||
}
|
||||
|
|
@ -2411,6 +2447,10 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
.render(area, buf);
|
||||
return;
|
||||
}
|
||||
if self.snapshot.configuration.mixer_orientation == MixerOrientation::Horizontal {
|
||||
self.render_horizontal_streams(area, buf, &rows);
|
||||
return;
|
||||
}
|
||||
let selected = self.selected.min(rows.len().saturating_sub(1));
|
||||
let mut start = selected;
|
||||
let mut occupied = rows[selected].height();
|
||||
|
|
@ -2532,6 +2572,184 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
.render(meter, buf);
|
||||
}
|
||||
}
|
||||
|
||||
fn render_horizontal_streams(&self, area: Rect, buf: &mut Buffer, rows: &[MixerRow<'_>]) {
|
||||
struct Band {
|
||||
entries: Vec<usize>,
|
||||
height: u16,
|
||||
}
|
||||
|
||||
let columns = usize::from((area.width / 30).max(1));
|
||||
let mut bands = Vec::new();
|
||||
let mut index = 0;
|
||||
while index < rows.len() {
|
||||
if matches!(rows[index], MixerRow::Separator { .. }) {
|
||||
bands.push(Band {
|
||||
entries: vec![index],
|
||||
height: rows[index].height(),
|
||||
});
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
let mut entries = Vec::new();
|
||||
let mut height = 1;
|
||||
while index < rows.len()
|
||||
&& entries.len() < columns
|
||||
&& matches!(rows[index], MixerRow::Fader { .. })
|
||||
{
|
||||
height = height.max(rows[index].height());
|
||||
entries.push(index);
|
||||
index += 1;
|
||||
}
|
||||
bands.push(Band { entries, height });
|
||||
}
|
||||
|
||||
let selected = self.selected.min(rows.len().saturating_sub(1));
|
||||
let selected_band = bands
|
||||
.iter()
|
||||
.position(|band| band.entries.contains(&selected))
|
||||
.unwrap_or(0);
|
||||
let mut start = selected_band;
|
||||
let mut occupied = bands[selected_band].height;
|
||||
while start > 0 {
|
||||
let previous = bands[start - 1].height;
|
||||
if occupied.saturating_add(previous) > area.height {
|
||||
break;
|
||||
}
|
||||
start -= 1;
|
||||
occupied = occupied.saturating_add(previous);
|
||||
}
|
||||
|
||||
let mut y = area.y;
|
||||
for band in bands.iter().skip(start) {
|
||||
let remaining = area.bottom().saturating_sub(y);
|
||||
if remaining == 0 {
|
||||
break;
|
||||
}
|
||||
let height = band.height.min(remaining);
|
||||
if band.entries.len() == 1
|
||||
&& matches!(rows[band.entries[0]], MixerRow::Separator { .. })
|
||||
{
|
||||
self.render_horizontal_entry(
|
||||
&rows[band.entries[0]],
|
||||
Rect::new(area.x, y, area.width, height),
|
||||
band.entries[0] == self.selected,
|
||||
buf,
|
||||
);
|
||||
} else {
|
||||
let count = u16::try_from(band.entries.len()).unwrap_or(u16::MAX).max(1);
|
||||
let width = area.width / count;
|
||||
for (column, entry) in band.entries.iter().enumerate() {
|
||||
let column = u16::try_from(column).unwrap_or(u16::MAX);
|
||||
let x = area.x.saturating_add(width.saturating_mul(column));
|
||||
let card_width = if column + 1 == count {
|
||||
area.right().saturating_sub(x)
|
||||
} else {
|
||||
width
|
||||
};
|
||||
self.render_horizontal_entry(
|
||||
&rows[*entry],
|
||||
Rect::new(x, y, card_width, rows[*entry].height().min(height)),
|
||||
*entry == self.selected,
|
||||
buf,
|
||||
);
|
||||
}
|
||||
}
|
||||
y = y.saturating_add(height);
|
||||
}
|
||||
}
|
||||
|
||||
fn render_horizontal_entry(
|
||||
&self,
|
||||
row: &MixerRow<'_>,
|
||||
area: Rect,
|
||||
selected: bool,
|
||||
buf: &mut Buffer,
|
||||
) {
|
||||
let theme = self.theme.palette();
|
||||
let MixerRow::Fader { item, density, .. } = row else {
|
||||
let MixerRow::Separator { label, .. } = row else {
|
||||
return;
|
||||
};
|
||||
if area.height < 2 {
|
||||
return;
|
||||
}
|
||||
Paragraph::new(format!("── {label} ──"))
|
||||
.alignment(Alignment::Center)
|
||||
.style(if selected {
|
||||
Style::default().fg(theme.accent).bold()
|
||||
} else {
|
||||
Style::default().fg(theme.muted)
|
||||
})
|
||||
.block(Block::bordered().border_style(if selected {
|
||||
Style::default().fg(theme.accent)
|
||||
} else {
|
||||
Style::default().fg(theme.muted)
|
||||
}))
|
||||
.render(area, buf);
|
||||
return;
|
||||
};
|
||||
let percent = item
|
||||
.gain
|
||||
.map_or(0, |gain| (gain.clamp(0.0, 1.0) * 100.0).round() as u16);
|
||||
let state = if item.gain.is_none() {
|
||||
"OFFLINE"
|
||||
} else if item.mute_mixed || item.gain_mixed {
|
||||
"MIXED"
|
||||
} else if item.muted == Some(true) {
|
||||
"MUTED"
|
||||
} else if !item.writable {
|
||||
"READ ONLY"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let meter_style = Style::default()
|
||||
.bg(theme.meter_track)
|
||||
.fg(if item.error.is_some() {
|
||||
theme.error
|
||||
} else if item.muted == Some(true) {
|
||||
theme.warning
|
||||
} else {
|
||||
theme.secondary
|
||||
});
|
||||
let label = item.error.as_deref().map_or_else(
|
||||
|| format!("{percent}% {state}"),
|
||||
|error| format!("ERROR: {error}"),
|
||||
);
|
||||
if *density == FaderDensity::Slim {
|
||||
Gauge::default()
|
||||
.gauge_style(meter_style)
|
||||
.percent(percent)
|
||||
.label(format!(
|
||||
"{} {} {label}",
|
||||
if selected { "▶" } else { " " },
|
||||
item.label
|
||||
))
|
||||
.render(area, buf);
|
||||
return;
|
||||
}
|
||||
if area.height < 2 {
|
||||
return;
|
||||
}
|
||||
let block = Block::bordered()
|
||||
.title(format!(
|
||||
"{} {}",
|
||||
if selected { "▶" } else { " " },
|
||||
item.label
|
||||
))
|
||||
.border_style(if selected {
|
||||
Style::default().fg(theme.accent)
|
||||
} else {
|
||||
Style::default().fg(theme.muted)
|
||||
});
|
||||
let meter = block.inner(area);
|
||||
block.render(area, buf);
|
||||
Gauge::default()
|
||||
.gauge_style(meter_style)
|
||||
.percent(percent)
|
||||
.label(label)
|
||||
.render(meter, buf);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -2681,6 +2899,9 @@ mod tests {
|
|||
*current = *density;
|
||||
}
|
||||
}
|
||||
ConfigurationEdit::SetMixerOrientation { orientation } => {
|
||||
self.snapshot.configuration.mixer_orientation = *orientation;
|
||||
}
|
||||
ConfigurationEdit::AddSeparator {
|
||||
id,
|
||||
label,
|
||||
|
|
@ -2997,6 +3218,7 @@ mod tests {
|
|||
assert!(hidden_rendered.contains("Show hidden fader Music"));
|
||||
assert!(hidden_rendered.contains("Show hidden fader Browser"));
|
||||
|
||||
app.handle_key_event(press(KeyCode::Down));
|
||||
app.handle_key_event(press(KeyCode::Down));
|
||||
app.handle_key_event(press(KeyCode::Enter));
|
||||
app.handle_key_event(press(KeyCode::Tab));
|
||||
|
|
@ -3227,6 +3449,59 @@ mod tests {
|
|||
assert!(rendered.contains("65%"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn horizontal_mixer_renders_faders_side_by_side() {
|
||||
let mut snapshot = DemoClient::default().view();
|
||||
let mut second = snapshot.items[0].clone();
|
||||
snapshot.items[0].id.id = "music".into();
|
||||
snapshot.items[0].label = "Music".into();
|
||||
second.id.id = "browser".into();
|
||||
second.label = "Browser".into();
|
||||
snapshot.items.push(second);
|
||||
snapshot.configuration.mixer_orientation = MixerOrientation::Horizontal;
|
||||
snapshot.configuration.faders = vec![
|
||||
ConfiguredFader {
|
||||
id: "music-fader".into(),
|
||||
target: snapshot.items[0].id.clone(),
|
||||
pickup: true,
|
||||
pickup_tolerance: 0.02,
|
||||
},
|
||||
ConfiguredFader {
|
||||
id: "browser-fader".into(),
|
||||
target: snapshot.items[1].id.clone(),
|
||||
pickup: true,
|
||||
pickup_tolerance: 0.02,
|
||||
},
|
||||
];
|
||||
snapshot.configuration.mixer_layout = vec![
|
||||
MixerLayoutEntry::Fader {
|
||||
fader: "music-fader".into(),
|
||||
hidden: false,
|
||||
density: FaderDensity::Standard,
|
||||
},
|
||||
MixerLayoutEntry::Fader {
|
||||
fader: "browser-fader".into(),
|
||||
hidden: false,
|
||||
density: FaderDensity::Standard,
|
||||
},
|
||||
];
|
||||
let app = LiveTui::new(LayoutClient {
|
||||
snapshot,
|
||||
edits: Arc::new(Mutex::new(Vec::new())),
|
||||
})
|
||||
.unwrap();
|
||||
let area = Rect::new(0, 0, 80, 4);
|
||||
let mut buffer = Buffer::empty(area);
|
||||
app.render_streams(area, &mut buffer);
|
||||
let rendered = buffer
|
||||
.content
|
||||
.iter()
|
||||
.map(|cell| cell.symbol())
|
||||
.collect::<String>();
|
||||
assert!(rendered.contains("Music"));
|
||||
assert!(rendered.contains("Browser"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_fader_form_selects_application_faders_and_shows_mode() {
|
||||
let mut snapshot = DemoClient::default().view();
|
||||
|
|
@ -3324,6 +3599,7 @@ mod tests {
|
|||
learning: None,
|
||||
error: None,
|
||||
profile_id: "desktop".into(),
|
||||
mixer_orientation: MixerOrientation::Vertical,
|
||||
applications: vec![ConfiguredApplication {
|
||||
id: "browser".into(),
|
||||
label: "Browser".into(),
|
||||
|
|
@ -3405,11 +3681,22 @@ mod tests {
|
|||
app.handle_key_event(press(KeyCode::Char('2')));
|
||||
app.handle_key_event(press(KeyCode::Right));
|
||||
assert_eq!(app.theme(), ThemeName::Dracula);
|
||||
app.handle_key_event(press(KeyCode::Down));
|
||||
app.handle_key_event(press(KeyCode::Right));
|
||||
assert_eq!(
|
||||
app.snapshot.configuration.mixer_orientation,
|
||||
MixerOrientation::Horizontal
|
||||
);
|
||||
|
||||
app.handle_key_event(press(KeyCode::Char('g')));
|
||||
app.handle_key_event(press(KeyCode::Char('a')));
|
||||
assert!(app.editor.is_none());
|
||||
assert!(edits.lock().unwrap().is_empty());
|
||||
assert_eq!(
|
||||
edits.lock().unwrap().as_slice(),
|
||||
&[ConfigurationEdit::SetMixerOrientation {
|
||||
orientation: MixerOrientation::Horizontal
|
||||
}]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in New Issue