voelin-gpui: the volume of a person, on the member card
The Volume rows of the Slint member card (members.slint): what the person is played at in percent, a mute for us and a slider (0 to 200, steps of 5), both off for a person the server gave no unique id, since the choice is kept by it. A click on a person on the voice page or in the members panel opens the card, so the volume is a click away from the people the voice page shows. The slider and the button are the actions SetMemberVolume and SetMemberMuted, which go through voelin-ui-vm's settings_page logic (open_client, then client_playback_changed: the engine's SetClientVolume and SetClientMuted, the `client_playback` key, the tree's mark of who is muted), the logic the Slint front end's volume dialog calls; the dialogs slice keeps the dialog itself. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
04223a785c
commit
c566716b45
5 files changed
+305
-17
No files matched your search
@@ -1094,6 +1094,41 @@ impl AppState {
|
||||
self.password.as_ref()
|
||||
}
|
||||
|
||||
/// The volume of a client of the server on screen, in percent (the member
|
||||
/// card's slider): the engine plays them so, and the choice is kept by their
|
||||
/// unique id.
|
||||
pub fn set_member_volume(&mut self, client: u16, percent: f32, cx: &mut Context<Self>) {
|
||||
self.set_client_audio(client, |form| form.volume = percent, cx);
|
||||
}
|
||||
|
||||
/// Play a client of the server on screen or not (the member card's Mute for
|
||||
/// me), kept by their unique id.
|
||||
pub fn set_member_muted(&mut self, client: u16, muted: bool, cx: &mut Context<Self>) {
|
||||
self.set_client_audio(client, |form| form.muted = muted, cx);
|
||||
}
|
||||
|
||||
/// What the volume dialog of the Slint front end does, without the dialog:
|
||||
/// the client's volume and mute as the vm has them, changed by `change`, and
|
||||
/// handed back to `client_playback_changed` (the engine's commands, what is
|
||||
/// kept, the tree's marks).
|
||||
fn set_client_audio(
|
||||
&mut self,
|
||||
client: u16,
|
||||
change: impl FnOnce(&mut voelin_ui_vm::bridge::ClientAudio),
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.transition(cx, |state, cx| {
|
||||
let Some(mut form) = voelin_ui_vm::settings_page::logic::open_client(state, client)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
change(&mut form);
|
||||
voelin_ui_vm::settings_page::logic::client_playback_changed(state, cx, &form);
|
||||
state.playback_dialog = None;
|
||||
});
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Fold or unfold a channel of the tree (`toggle_collapse`), and remember
|
||||
/// it for the server ([`UI_TREE`]).
|
||||
pub fn toggle_collapse(&mut self, channel: ChannelId, cx: &mut Context<Self>) {
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
//! `open_client` (the last one only logs: the client's volume dialog is a
|
||||
//! dialog of its own slice). The callbacks of `bind/servers.rs` that are
|
||||
//! still not here belong to the slices after: `client_audio_changed` to the
|
||||
//! dialogs, and `copied` (the toast that follows a copy) to whichever copies:
|
||||
//! [`Invite`] sets it itself.
|
||||
//! dialogs (the member card has the volume and the mute of a person,
|
||||
//! [`SetMemberVolume`] and [`SetMemberMuted`]), and `copied` (the toast that
|
||||
//! follows a copy) to whichever copies: [`Invite`] sets it itself.
|
||||
|
||||
use gpui_kit::{Action, actions};
|
||||
|
||||
@@ -66,6 +67,27 @@ pub struct ShowVoiceView {
|
||||
pub on: bool,
|
||||
}
|
||||
|
||||
/// The member card's volume slider: the person's playback volume, in percent
|
||||
/// (`member_volume` of the Slint card).
|
||||
#[derive(Clone, Debug, PartialEq, Action)]
|
||||
#[action(namespace = voelin, no_json)]
|
||||
pub struct SetMemberVolume {
|
||||
/// The client's id on the server.
|
||||
pub client: u16,
|
||||
/// 0 to 200.
|
||||
pub percent: f32,
|
||||
}
|
||||
|
||||
/// The member card's Mute for me: stop playing the person (local only).
|
||||
#[derive(Clone, Debug, PartialEq, Action)]
|
||||
#[action(namespace = voelin, no_json)]
|
||||
pub struct SetMemberMuted {
|
||||
/// The client's id on the server.
|
||||
pub client: u16,
|
||||
/// Muted from now on.
|
||||
pub muted: bool,
|
||||
}
|
||||
|
||||
/// `select_server`: show a server (and observe it).
|
||||
#[derive(Clone, Debug, PartialEq, Action)]
|
||||
#[action(namespace = voelin, no_json)]
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
//! the list applies). A talker redraws it, with the tree: a person's row has
|
||||
//! the speaking ring, "Speaking" and the bars, and no other pane of the window
|
||||
//! is told. [`MemberCardView`] is the card, a card over the window with a scrim
|
||||
//! that a click outside closes; its buttons (the volume, a message, a poke,
|
||||
//! friends, blocking) come with the slices that have those dialogs.
|
||||
//! that a click outside closes; it has the volume and the mute of the person for
|
||||
//! us (`SetMemberVolume`, `SetMemberMuted`), and its other buttons (a message, a
|
||||
//! poke, friends, blocking) come with the slices that have those dialogs.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui_kit::component::input::{Input, InputEvent, InputState};
|
||||
use gpui_kit::component::slider::{Slider, SliderEvent, SliderState};
|
||||
use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::{
|
||||
AnyElement, AppContext as _, Context, Entity, FontWeight, InteractiveElement as _, IntoElement,
|
||||
@@ -23,7 +25,7 @@ use gpui_kit::{
|
||||
use voelin_ui_vm::bridge::{MemberCard, MemberItem};
|
||||
use voelin_ui_vm::list::Changes;
|
||||
|
||||
use super::actions::{OpenMember, SearchMembers};
|
||||
use super::actions::{OpenMember, SearchMembers, SetMemberMuted, SetMemberVolume};
|
||||
use super::tree_model::{Emptiness, TreeEvent, TreeModel, debug_check};
|
||||
use super::widgets::{
|
||||
Avatar, IconButton, Presence, chip, icon, live_badge, small_picture, speaking_bars,
|
||||
@@ -448,25 +450,67 @@ impl Render for MembersPane {
|
||||
}
|
||||
|
||||
/// The card over a member row, over the window: a scrim that a click outside
|
||||
/// the card closes, and the card with what is known of the person.
|
||||
/// the card closes, and the card with what is known of the person, and the
|
||||
/// volume and the mute of their voice for us (the Slint card's Volume rows).
|
||||
pub struct MemberCardView {
|
||||
card: Option<MemberCard>,
|
||||
/// How wide the members panel is: the card stands beside it.
|
||||
panel_width: f32,
|
||||
_subscription: Subscription,
|
||||
/// The volume slider, in percent (0 to 200, as the Slint card's).
|
||||
slider: Entity<SliderState>,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
/// The loudest the card's slider plays a person, in percent.
|
||||
const LOUDEST: f32 = 200.0;
|
||||
|
||||
impl MemberCardView {
|
||||
/// A card that follows `model`, beside a panel `panel_width` pixels wide.
|
||||
pub fn new(model: &Entity<TreeModel>, panel_width: f32, cx: &mut Context<Self>) -> Self {
|
||||
pub fn new(
|
||||
model: &Entity<TreeModel>,
|
||||
panel_width: f32,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let card = model.read(cx).card().cloned();
|
||||
let subscription = cx.subscribe(model, |this: &mut Self, model, event: &TreeEvent, cx| {
|
||||
if matches!(event, TreeEvent::Card) {
|
||||
this.card = model.read(cx).card().cloned();
|
||||
cx.notify();
|
||||
}
|
||||
let slider = cx.new(|_| {
|
||||
SliderState::new()
|
||||
.min(0.0)
|
||||
.max(LOUDEST)
|
||||
.step(5.0)
|
||||
.default_value(card.as_ref().map_or(100.0, |card| card.volume))
|
||||
});
|
||||
Self { card, panel_width, _subscription: subscription }
|
||||
let subscriptions = vec![
|
||||
cx.subscribe_in(
|
||||
model,
|
||||
window,
|
||||
|this: &mut Self, model, event: &TreeEvent, window, cx| {
|
||||
if matches!(event, TreeEvent::Card) {
|
||||
this.card = model.read(cx).card().cloned();
|
||||
// The slider shows the person's volume as it is now (a change
|
||||
// the slider itself made comes back the same).
|
||||
if let Some(card) = &this.card {
|
||||
let volume = card.volume.clamp(0.0, LOUDEST);
|
||||
this.slider
|
||||
.update(cx, |slider, cx| slider.set_value(volume, window, cx));
|
||||
}
|
||||
cx.notify();
|
||||
}
|
||||
},
|
||||
),
|
||||
cx.subscribe_in(
|
||||
&slider,
|
||||
window,
|
||||
|this: &mut Self, _, event: &SliderEvent, window, cx| {
|
||||
if let (SliderEvent::Change(value), Some(card)) = (event, &this.card) {
|
||||
let client = u16::try_from(card.id).unwrap_or_default();
|
||||
let percent = value.end();
|
||||
window.dispatch_action(Box::new(SetMemberVolume { client, percent }), cx);
|
||||
}
|
||||
},
|
||||
),
|
||||
];
|
||||
Self { card, panel_width, slider, _subscriptions: subscriptions }
|
||||
}
|
||||
|
||||
/// The card that is open.
|
||||
@@ -485,6 +529,79 @@ fn caption(theme: &VoelinTheme, text: &'static str) -> impl IntoElement {
|
||||
.child(text)
|
||||
}
|
||||
|
||||
/// The card's Volume rows: what the person is played at, a mute for us and
|
||||
/// the slider. Both need a person the server gave a unique id (the choice is
|
||||
/// kept by it), as the Slint card's do.
|
||||
fn volume(
|
||||
theme: &VoelinTheme,
|
||||
person: &MemberCard,
|
||||
slider: &Entity<SliderState>,
|
||||
) -> impl IntoElement {
|
||||
let (c, m) = (&theme.colors, &theme.metrics);
|
||||
let client = u16::try_from(person.id).unwrap_or_default();
|
||||
let (muted, known) = (person.muted, person.known);
|
||||
div()
|
||||
.id("member-volume")
|
||||
.debug_selector(|| "member-volume".into())
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap(px(m.space_2))
|
||||
.pt(px(m.space_3))
|
||||
.border_t_1()
|
||||
.border_color(hsla(c.border_popup))
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.flex_row()
|
||||
.items_center()
|
||||
.gap(px(m.space_2))
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.text_size(px(m.font_sm))
|
||||
.text_color(hsla(c.text_secondary))
|
||||
.child("Volume"),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.id("member-volume-percent")
|
||||
.debug_selector(|| "member-volume-percent".into())
|
||||
.text_size(px(m.font_xs))
|
||||
.text_color(hsla(c.text_muted))
|
||||
.child(format!("{}%", person.volume.round() as i32)),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.flex_row()
|
||||
.items_center()
|
||||
.gap(px(m.space_3))
|
||||
.child(
|
||||
IconButton::new(
|
||||
"member-mute",
|
||||
if muted { "volume-x" } else { "volume-2" },
|
||||
if muted { "Unmute for me" } else { "Mute for me" },
|
||||
)
|
||||
.size(30.0)
|
||||
.danger()
|
||||
.checked(muted)
|
||||
.enabled(known)
|
||||
.on_click(move |_, window, cx| {
|
||||
window
|
||||
.dispatch_action(Box::new(SetMemberMuted { client, muted: !muted }), cx)
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.id("member-slider")
|
||||
.debug_selector(|| "member-slider".into())
|
||||
.flex_1()
|
||||
.child(Slider::new(slider).disabled(!known || muted)),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
impl Render for MemberCardView {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let Some(person) = self.card.clone() else { return div().into_any_element() };
|
||||
@@ -611,7 +728,8 @@ impl Render for MemberCardView {
|
||||
)),
|
||||
)
|
||||
})
|
||||
.child(facts);
|
||||
.child(facts)
|
||||
.child(volume(&theme, &person, &self.slider));
|
||||
// The card stands beside the panel, near the top.
|
||||
div()
|
||||
.id("member-card-scrim")
|
||||
|
||||
@@ -21,7 +21,8 @@ use crate::shell::actions::{
|
||||
DisconnectVoice, EditChannel, EditServer, Invite, JoinChannel, LeaveVoice, MoveClient,
|
||||
OpenClient, OpenMember, OpenSearch, OpenSettings, OpenShare, OpenVoiceSettings, PushToTalk,
|
||||
SaveAndConnect, SaveServer, SearchMembers, SelectChannel, SelectServer, SetInputMuted,
|
||||
SetOutputMuted, ShowVoiceView, SubmitChannelPassword, ToggleChannel, ToggleVoiceCompact,
|
||||
SetMemberMuted, SetMemberVolume, SetOutputMuted, ShowVoiceView, SubmitChannelPassword,
|
||||
ToggleChannel, ToggleVoiceCompact,
|
||||
};
|
||||
use crate::shell::{
|
||||
ChannelPassword, ChannelTree, Emptiness, MainPanel, MemberCardView, MembersPane, SHORT_WINDOW,
|
||||
@@ -175,7 +176,7 @@ impl MainView {
|
||||
let model = cx.new(|cx| TreeModel::new(&app, cx));
|
||||
let tree = cx.new(|cx| ChannelTree::new(&model, counters.clone(), cx));
|
||||
let members = cx.new(|cx| MembersPane::new(&model, counters.clone(), window, cx));
|
||||
let card = cx.new(|cx| MemberCardView::new(&model, members_width, cx));
|
||||
let card = cx.new(|cx| MemberCardView::new(&model, members_width, window, cx));
|
||||
let (voice_shown, compact) = {
|
||||
let app = app.read(cx);
|
||||
(app.voice_page_shown(), app.voice_compact())
|
||||
@@ -300,6 +301,24 @@ impl MainView {
|
||||
self.app.update(cx, |app, cx| app.invite(cx));
|
||||
}
|
||||
|
||||
fn set_member_volume(
|
||||
&mut self,
|
||||
action: &SetMemberVolume,
|
||||
_: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.app.update(cx, |app, cx| app.set_member_volume(action.client, action.percent, cx));
|
||||
}
|
||||
|
||||
fn set_member_muted(
|
||||
&mut self,
|
||||
action: &SetMemberMuted,
|
||||
_: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.app.update(cx, |app, cx| app.set_member_muted(action.client, action.muted, cx));
|
||||
}
|
||||
|
||||
fn show_voice_view(&mut self, action: &ShowVoiceView, _: &mut Window, cx: &mut Context<Self>) {
|
||||
self.app.update(cx, |app, cx| app.show_voice_view(action.on, cx));
|
||||
}
|
||||
@@ -553,6 +572,8 @@ impl Render for MainView {
|
||||
.on_action(cx.listener(Self::set_output_muted))
|
||||
.on_action(cx.listener(Self::push_to_talk))
|
||||
.on_action(cx.listener(Self::invite))
|
||||
.on_action(cx.listener(Self::set_member_volume))
|
||||
.on_action(cx.listener(Self::set_member_muted))
|
||||
.on_action(cx.listener(Self::show_voice_view))
|
||||
.on_action(cx.listener(Self::leave_voice))
|
||||
.on_action(cx.listener(Self::toggle_voice_compact))
|
||||
|
||||
@@ -568,3 +568,95 @@ fn a_volume_and_a_stage_changed_elsewhere_reach_the_window(cx: &mut TestAppConte
|
||||
setting_changed(&shell, cx, UI_VOICE_COMPACT.name());
|
||||
assert!(compact(&shell, cx), "the page is on the smaller stage");
|
||||
}
|
||||
|
||||
/// The volume and the mute of a person, on the card a click on them opens
|
||||
/// (from the voice page as from the members panel): the engine plays them so,
|
||||
/// the choice is kept by their unique id, and the tree marks who is muted.
|
||||
#[gpui::test]
|
||||
fn a_persons_card_has_their_volume_and_mute(cx: &mut TestAppContext) {
|
||||
let (shell, cx) = on_the_voice_page(cx, Switches::default());
|
||||
click(cx, "voice-member-3");
|
||||
assert!(at(cx, "member-card").is_some(), "Kairo's card");
|
||||
assert!(at(cx, "member-volume").is_some());
|
||||
let card = |shell: &Shell, cx: &mut VisualTestContext| {
|
||||
shell.view.read_with(cx, |view, cx| view.member_card().read(cx).card().cloned().unwrap())
|
||||
};
|
||||
assert_eq!((card(&shell, cx).volume, card(&shell, cx).muted), (100.0, false));
|
||||
shell.app.read_with(cx, |app, _| app.take_sent());
|
||||
|
||||
click(cx, "member-mute");
|
||||
let sent = shell.app.read_with(cx, |app, _| app.take_sent());
|
||||
assert!(
|
||||
matches!(
|
||||
sent.as_slice(),
|
||||
[
|
||||
Command::SetClientVolume { client: 3, volume, .. },
|
||||
Command::SetClientMuted { client: 3, muted: true, .. },
|
||||
] if *volume == 1.0
|
||||
),
|
||||
"{sent:?}"
|
||||
);
|
||||
assert!(card(&shell, cx).muted, "the card has it");
|
||||
let kept = shell.app.read_with(cx, |app, _| app.backend().prefs.get(&CLIENT_PLAYBACK));
|
||||
assert_eq!(kept["demo-3"], ClientPlayback { volume: 1.0, muted: true }, "kept by their id");
|
||||
let marked = shell.view.read_with(cx, |view, cx| {
|
||||
view.tree_model()
|
||||
.read(cx)
|
||||
.rows()
|
||||
.iter()
|
||||
.find(|r| !r.is_channel && r.id == 3)
|
||||
.unwrap()
|
||||
.local_muted
|
||||
});
|
||||
assert!(marked, "and the tree marks them");
|
||||
|
||||
click(cx, "member-mute");
|
||||
let sent = shell.app.read_with(cx, |app, _| app.take_sent());
|
||||
assert!(
|
||||
matches!(sent.as_slice(), [_, Command::SetClientMuted { client: 3, muted: false, .. }]),
|
||||
"{sent:?}"
|
||||
);
|
||||
let kept = shell.app.read_with(cx, |app, _| app.backend().prefs.get(&CLIENT_PLAYBACK));
|
||||
assert!(!kept.contains_key("demo-3"), "the default is no choice");
|
||||
}
|
||||
|
||||
/// The slider sets the volume as the person is heard: a click on the track is
|
||||
/// a value, which the engine and the card follow.
|
||||
#[gpui::test]
|
||||
fn the_volume_slider_sets_the_volume_of_the_person(cx: &mut TestAppContext) {
|
||||
let (shell, cx) = on_the_voice_page(cx, Switches::default());
|
||||
click(cx, "voice-member-3");
|
||||
shell.app.read_with(cx, |app, _| app.take_sent());
|
||||
let track = at(cx, "member-slider").expect("the slider");
|
||||
let quarter = gpui_kit::point(track.left() + track.size.width * 0.25, track.center().y);
|
||||
cx.simulate_mouse_down(quarter, MouseButton::Left, Default::default());
|
||||
cx.simulate_mouse_up(quarter, MouseButton::Left, Default::default());
|
||||
frame(cx);
|
||||
let sent = shell.app.read_with(cx, |app, _| app.take_sent());
|
||||
let volume = sent.iter().find_map(|command| match command {
|
||||
Command::SetClientVolume { client: 3, volume, .. } => Some(*volume),
|
||||
_ => None,
|
||||
});
|
||||
let volume = volume.unwrap_or_else(|| panic!("no volume was sent: {sent:?}"));
|
||||
assert!(
|
||||
(0.3..=0.7).contains(&volume),
|
||||
"a click a quarter along 0 to 200 % is about half: {volume}"
|
||||
);
|
||||
let shown =
|
||||
shell.view.read_with(cx, |view, cx| view.member_card().read(cx).card().unwrap().volume);
|
||||
assert!((shown - volume * 100.0).abs() < 0.5, "the card shows {shown} for {volume}");
|
||||
}
|
||||
|
||||
/// A person the server gave no unique id has the controls off: nothing could be
|
||||
/// kept for them, as the Slint card says.
|
||||
#[gpui::test]
|
||||
fn a_person_without_a_unique_id_has_the_controls_off(cx: &mut TestAppContext) {
|
||||
let (shell, cx) = on_the_voice_page(cx, Switches::default());
|
||||
shell.events.send(sample_presence!(p => p.clients.get_mut(&5).unwrap().uid = None)).unwrap();
|
||||
frame(cx);
|
||||
click(cx, "voice-member-5");
|
||||
assert!(at(cx, "member-card").is_some());
|
||||
shell.app.read_with(cx, |app, _| app.take_sent());
|
||||
click(cx, "member-mute");
|
||||
assert!(shell.app.read_with(cx, |app, _| app.take_sent()).is_empty(), "nothing is sent");
|
||||
}
|
||||
Reference in new issue
Block a user