From 437e41f99d9d712cbe8e2a886c6619fc05cf610b Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Fri, 23 Jun 2023 11:52:06 +0200 Subject: [PATCH] Add styles for microphone and speakers buttons --- crates/collab_ui/src/collab_titlebar_item.rs | 29 ++++++--- crates/theme/src/theme.rs | 2 + styles/src/styleTree/workspace.ts | 64 ++++++++++++++++++++ 3 files changed, 85 insertions(+), 10 deletions(-) diff --git a/crates/collab_ui/src/collab_titlebar_item.rs b/crates/collab_ui/src/collab_titlebar_item.rs index 1cfa18f432..17f4f06ff9 100644 --- a/crates/collab_ui/src/collab_titlebar_item.rs +++ b/crates/collab_ui/src/collab_titlebar_item.rs @@ -451,21 +451,22 @@ impl CollabTitlebarItem { ) -> AnyElement { let icon; let tooltip; - let background; - if room.read(cx).is_muted().unwrap_or(false) { + let is_muted = room.read(cx).is_muted().unwrap_or(false); + if is_muted { icon = "icons/radix/mic-mute.svg"; tooltip = "Unmute microphone\nRight click for options"; - background = Color::red(); } else { icon = "icons/radix/mic.svg"; tooltip = "Mute microphone\nRight click for options"; - background = Color::transparent_black(); } let titlebar = &theme.workspace.titlebar; MouseEventHandler::::new(0, cx, |state, _| { - let style = titlebar.call_control.style_for(state); - Svg::new(icon) + let style = titlebar + .toggle_microphone_button + .in_state(is_muted) + .style_for(state); + let image = Svg::new(icon) .with_color(style.color) .constrained() .with_width(style.icon_width) @@ -474,8 +475,12 @@ impl CollabTitlebarItem { .with_width(style.button_width) .with_height(style.button_width) .contained() - .with_style(style.container) - .with_background_color(background) + .with_style(style.container); + if let Some(color) = style.container.background_color { + image.with_background_color(color) + } else { + image + } }) .with_cursor_style(CursorStyle::PointingHand) .on_click(MouseButton::Left, move |_, _, cx| { @@ -499,7 +504,8 @@ impl CollabTitlebarItem { ) -> AnyElement { let icon; let tooltip; - if room.read(cx).is_deafened().unwrap_or(false) { + let is_deafened = room.read(cx).is_deafened().unwrap_or(false); + if is_deafened { icon = "icons/radix/speaker-off.svg"; tooltip = "Unmute speakers\nRight click for options"; } else { @@ -509,7 +515,10 @@ impl CollabTitlebarItem { let titlebar = &theme.workspace.titlebar; MouseEventHandler::::new(0, cx, |state, _| { - let style = titlebar.call_control.style_for(state); + let style = titlebar + .toggle_speakers_button + .in_state(is_deafened) + .style_for(state); Svg::new(icon) .with_color(style.color) .constrained() diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index 69c06c85ad..bccb74a7ac 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -133,6 +133,8 @@ pub struct Titlebar { pub share_button: Toggleable>, pub call_control: Interactive, pub toggle_contacts_button: Toggleable>, + pub toggle_microphone_button: Toggleable>, + pub toggle_speakers_button: Toggleable>, pub user_menu_button: Toggleable>, pub toggle_contacts_badge: ContainerStyle, } diff --git a/styles/src/styleTree/workspace.ts b/styles/src/styleTree/workspace.ts index d7f994d98e..0e00f6f5bc 100644 --- a/styles/src/styleTree/workspace.ts +++ b/styles/src/styleTree/workspace.ts @@ -343,6 +343,70 @@ export default function workspace(colorScheme: ColorScheme) { }, }, }), + toggleMicrophoneButton: toggleable({ + base: interactive({ + base: { + margin: { left: itemSpacing }, + cornerRadius: 6, + color: foreground(layer, "variant"), + iconWidth: 14, + buttonWidth: 20, + }, + state: { + clicked: { + background: background(layer, "variant", "pressed"), + }, + hovered: { + background: background(layer, "variant", "hovered"), + }, + }, + }), + state: { + active: { + default: { + background: background(layer, "on", "default"), + }, + hovered: { + background: background(layer, "on", "hovered"), + }, + clicked: { + background: background(layer, "on", "pressed"), + }, + }, + }, + }), + toggleSpeakersButton: toggleable({ + base: interactive({ + base: { + margin: { left: itemSpacing }, + cornerRadius: 6, + color: foreground(layer, "variant"), + iconWidth: 14, + buttonWidth: 20, + }, + state: { + clicked: { + background: background(layer, "variant", "pressed"), + }, + hovered: { + background: background(layer, "variant", "hovered"), + }, + }, + }), + state: { + active: { + default: { + background: background(layer, "on", "default"), + }, + hovered: { + background: background(layer, "on", "hovered"), + }, + clicked: { + background: background(layer, "on", "pressed"), + }, + }, + }, + }), userMenuButton: merge(titlebarButton, { inactive: { default: {