fix(panel): match opacity slider to design

Also makes the text of other number sliders fixed-width, to avoid things moving around with changing numbers.
This commit is contained in:
Vukašin Vojinović 2024-10-27 20:38:28 +01:00 committed by Michael Murphy
parent 845b248247
commit 8af34ba9c4
5 changed files with 236 additions and 166 deletions

View file

@ -1,7 +1,7 @@
use cosmic::{
cctk::sctk::reexports::client::{backend::ObjectId, protocol::wl_output::WlOutput, Proxy},
cosmic_config::{self, CosmicConfigEntry},
iced::Length,
iced::{Alignment, Length},
theme,
widget::{
button, container, dropdown, horizontal_space, icon, row, settings, slider, text, toggler,
@ -223,26 +223,31 @@ pub(crate) fn style<
.into(),
text::body(fl!("large")).into(),
])
.spacing(12),
.align_y(Alignment::Center)
.spacing(8),
))
.add(settings::flex_item(
&descriptions[background_opacity],
row::with_capacity(3)
.push(text::body(fl!(
"number",
HashMap::from_iter(vec![("number", 0)])
)))
row::with_capacity(2)
.align_y(Alignment::Center)
.spacing(8)
.push(
text::body(fl!(
"number",
HashMap::from_iter(vec![(
"number",
(panel_config.opacity * 100.0) as i32
)])
))
.width(Length::Fixed(22.0))
.align_x(Alignment::Center),
)
.push(
slider(0..=100, (panel_config.opacity * 100.0) as i32, |v| {
Message::OpacityRequest(v as f32 / 100.0)
})
.breakpoints(&[50]),
)
.push(text::body(fl!(
"number",
HashMap::from_iter(vec![("number", 100)])
)))
.spacing(12),
),
))
.apply(Element::from)
.map(msg_map)

View file

@ -51,7 +51,6 @@ fn mouse() -> Section<crate::pages::Message> {
.view::<Page>(move |binder, _page, section| {
let descriptions = &section.descriptions;
let input = binder.page::<super::Page>().expect("input page not found");
let theme = cosmic::theme::active();
settings::section()
.title(&section.title)
@ -81,8 +80,12 @@ fn mouse() -> Section<crate::pages::Message> {
row::with_capacity(2)
.align_y(Alignment::Center)
.spacing(theme.cosmic().space_s())
.push(text::body(format!("{:.0}", value.round())))
.spacing(8)
.push(
text::body(format!("{:.0}", value.round()))
.width(Length::Fixed(22.0))
.align_x(Alignment::Center),
)
.push(slider)
}),
)
@ -116,7 +119,6 @@ fn scrolling() -> Section<crate::pages::Message> {
.view::<Page>(move |binder, _page, section| {
let descriptions = &section.descriptions;
let input = binder.page::<super::Page>().expect("input page not found");
let theme = cosmic::theme::active();
settings::section()
.title(&section.title)
@ -141,8 +143,12 @@ fn scrolling() -> Section<crate::pages::Message> {
row::with_capacity(2)
.align_y(Alignment::Center)
.spacing(theme.cosmic().space_s())
.push(text::body(format!("{:.0}", value.round())))
.spacing(8)
.push(
text::body(format!("{:.0}", value.round()))
.width(Length::Fixed(22.0))
.align_x(Alignment::Center),
)
.push(slider)
}))
.add(

View file

@ -69,7 +69,6 @@ fn touchpad() -> Section<crate::pages::Message> {
.view::<Page>(move |binder, _page, section| {
let descriptions = &section.descriptions;
let input = binder.page::<super::Page>().expect("input page not found");
let theme = cosmic::theme::active();
settings::section()
.title(&section.title)
@ -104,8 +103,12 @@ fn touchpad() -> Section<crate::pages::Message> {
row::with_capacity(2)
.align_y(Alignment::Center)
.spacing(theme.cosmic().space_s())
.push(text::body(format!("{:.0}", value.round())))
.spacing(8)
.push(
text::body(format!("{:.0}", value.round()))
.width(Length::Fixed(22.0))
.align_x(Alignment::Center),
)
.push(slider)
}),
)
@ -200,7 +203,6 @@ fn scrolling() -> Section<crate::pages::Message> {
let page = binder
.page::<super::Page>()
.expect("input devices page not found");
let theme = cosmic::theme::active();
settings::section()
.title(&section.title)
@ -250,8 +252,12 @@ fn scrolling() -> Section<crate::pages::Message> {
row::with_capacity(2)
.align_y(Alignment::Center)
.spacing(theme.cosmic().space_s())
.push(text::body(format!("{:.0}", value.round())))
.spacing(8)
.push(
text::body(format!("{:.0}", value.round()))
.width(Length::Fixed(22.0))
.align_x(Alignment::Center),
)
.push(slider)
}))
// Natural scrolling toggle

View file

@ -4,6 +4,7 @@
use std::{collections::BTreeMap, time::Duration};
use cosmic::{
iced::{Alignment, Length},
widget::{self, settings},
Element, Task,
};
@ -608,9 +609,8 @@ fn input() -> Section<crate::pages::Message> {
.title(fl!("sound-input"))
.descriptions(descriptions)
.view::<Page>(move |_binder, page, section| {
let volume_control = widget::row::with_capacity(3)
.align_y(cosmic::iced::Alignment::Center)
.spacing(4)
let volume_control = widget::row::with_capacity(4)
.align_y(Alignment::Center)
.push(
widget::button::icon(widget::icon::from_name(if page.source_mute {
"microphone-sensitivity-muted-symbolic"
@ -619,7 +619,12 @@ fn input() -> Section<crate::pages::Message> {
}))
.on_press(Message::SourceMuteToggle),
)
.push(widget::text::body(&page.source_volume_text))
.push(
widget::text::body(&page.source_volume_text)
.width(Length::Fixed(22.0))
.align_x(Alignment::Center),
)
.push(widget::horizontal_space().width(8))
.push(
widget::slider(0..=150, page.source_volume, Message::SourceVolumeChanged)
.breakpoints(&[100]),
@ -666,9 +671,8 @@ fn output() -> Section<crate::pages::Message> {
.title(fl!("sound-output"))
.descriptions(descriptions)
.view::<Page>(move |_binder, page, section| {
let volume_control = widget::row::with_capacity(3)
.align_y(cosmic::iced::Alignment::Center)
.spacing(4)
let volume_control = widget::row::with_capacity(4)
.align_y(Alignment::Center)
.push(
widget::button::icon(if page.sink_mute {
widget::icon::from_name("audio-volume-muted-symbolic")
@ -677,7 +681,12 @@ fn output() -> Section<crate::pages::Message> {
})
.on_press(Message::SinkMuteToggle),
)
.push(widget::text::body(&page.sink_volume_text))
.push(
widget::text::body(&page.sink_volume_text)
.width(Length::Fixed(22.0))
.align_x(Alignment::Center),
)
.push(widget::horizontal_space().width(8))
.push(
widget::slider(0..=150, page.sink_volume, Message::SinkVolumeChanged)
.breakpoints(&[100]),