fix(wallpaper): duplicate color wallpaper previews
The issue arises after the wallpaper settings page is opened after choosing a default color as a background. The chosen color is treated as a custom color on reload which is then duplicated when the default colors are displayed. Solving this issue is as simple as filtering the customs colors list for default colors. I unwrap two `Options` from `partial_cmp` in this fix. Floats don't implement `Eq` due to `NaN`s but they do implement `PartialOrd` and `PartialEq`. Colors shouldn't have `NaN`s at all, so unwrapping here is fine as that invariant should hold unless there is a bug elsewhere.
This commit is contained in:
parent
1f49b9f61a
commit
6d039eb4c3
2 changed files with 31 additions and 14 deletions
|
|
@ -11,6 +11,7 @@ use cosmic::widget::{button, container, space};
|
|||
use cosmic::{iced, Element};
|
||||
use cosmic_settings_wallpaper as wallpaper;
|
||||
use slotmap::DefaultKey;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
const COLOR_WIDTH: u16 = 70;
|
||||
const COLUMN_SPACING: u16 = 12;
|
||||
|
|
@ -93,12 +94,28 @@ pub fn color_select_options(
|
|||
context: &super::Context,
|
||||
selected: Option<&wallpaper::Color>,
|
||||
) -> Element<'static, Message> {
|
||||
static SORTED: OnceLock<Vec<wallpaper::Color>> = OnceLock::new();
|
||||
let sorted = &**SORTED.get_or_init(|| {
|
||||
let mut sorted = wallpaper::DEFAULT_COLORS.to_vec();
|
||||
sorted.sort_by(|a, b| a.partial_cmp(b).expect("Neither slices should have NaNs"));
|
||||
sorted
|
||||
});
|
||||
|
||||
flex_select_row(
|
||||
context
|
||||
.custom_colors
|
||||
.iter()
|
||||
.rev()
|
||||
.map(|color| (color, true))
|
||||
.filter_map(|color| {
|
||||
sorted
|
||||
.binary_search_by(|probe| {
|
||||
probe
|
||||
.partial_cmp(color)
|
||||
.expect("Neither slices should have NaNs")
|
||||
})
|
||||
.is_err()
|
||||
.then_some((color, true))
|
||||
})
|
||||
.chain(wallpaper::DEFAULT_COLORS.iter().map(|color| (color, false)))
|
||||
.map(|(color, removable)| {
|
||||
color_button(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue