fix(wallpaper): better flex row item aalgorithm
This commit is contained in:
parent
84f96d3d0e
commit
c933f80cde
2 changed files with 15 additions and 9 deletions
|
|
@ -526,7 +526,6 @@ pub fn settings() -> Section<crate::pages::Message> {
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
.apply(cosmic::iced::widget::container)
|
.apply(cosmic::iced::widget::container)
|
||||||
.width(Length::Fill)
|
|
||||||
.height(Length::Fixed(32.0))
|
.height(Length::Fixed(32.0))
|
||||||
.into()
|
.into()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -597,7 +596,6 @@ pub fn settings() -> Section<crate::pages::Message> {
|
||||||
|
|
||||||
cosmic::iced::widget::column(children)
|
cosmic::iced::widget::column(children)
|
||||||
.spacing(22)
|
.spacing(22)
|
||||||
.padding(0)
|
|
||||||
.max_width(683)
|
.max_width(683)
|
||||||
.apply(Element::from)
|
.apply(Element::from)
|
||||||
.map(crate::pages::Message::DesktopWallpaper)
|
.map(crate::pages::Message::DesktopWallpaper)
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,8 @@ pub fn color_image(
|
||||||
/// Color selection list
|
/// Color selection list
|
||||||
pub fn color_select_options() -> Element<'static, Message> {
|
pub fn color_select_options() -> Element<'static, Message> {
|
||||||
cosmic::iced::widget::responsive(|size| {
|
cosmic::iced::widget::responsive(|size| {
|
||||||
let items_per_row = ((size.width / (COLOR_WIDTH + ROW_SPACING) as f32).floor() as usize)
|
let items_per_row =
|
||||||
.max(1)
|
flex_row_items(size.width, COLOR_WIDTH as f32, ROW_SPACING as f32, 8) as usize;
|
||||||
.min(8);
|
|
||||||
|
|
||||||
let mut color_column = Vec::with_capacity(wallpaper::DEFAULT_COLORS.len() / items_per_row);
|
let mut color_column = Vec::with_capacity(wallpaper::DEFAULT_COLORS.len() / items_per_row);
|
||||||
let mut colors = wallpaper::DEFAULT_COLORS.iter();
|
let mut colors = wallpaper::DEFAULT_COLORS.iter();
|
||||||
|
|
@ -100,16 +99,25 @@ pub fn color_select_options() -> Element<'static, Message> {
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn flex_row_items(available: f32, item_width: f32, spacing: f32, max_items: u32) -> u32 {
|
||||||
|
let mut items = 2;
|
||||||
|
|
||||||
|
while items <= max_items && available >= (item_width + spacing) * items as f32 - spacing {
|
||||||
|
items += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
items - 1
|
||||||
|
}
|
||||||
|
|
||||||
/// Background selection list
|
/// Background selection list
|
||||||
pub fn wallpaper_select_options(page: &super::Page) -> Element<Message> {
|
pub fn wallpaper_select_options(page: &super::Page) -> Element<Message> {
|
||||||
cosmic::iced::widget::responsive(|size| {
|
cosmic::iced::widget::responsive(|size| {
|
||||||
let items_per_row = ((size.width / (WALLPAPER_WIDTH + ROW_SPACING as f32)).floor()
|
let items_per_row =
|
||||||
as usize)
|
flex_row_items(size.width, WALLPAPER_WIDTH, ROW_SPACING as f32, 4) as usize;
|
||||||
.max(1)
|
|
||||||
.min(4);
|
|
||||||
|
|
||||||
let mut image_column =
|
let mut image_column =
|
||||||
Vec::with_capacity(page.selection.selection_handles.len() / items_per_row);
|
Vec::with_capacity(page.selection.selection_handles.len() / items_per_row);
|
||||||
|
|
||||||
let mut image_handles = page.selection.selection_handles.iter();
|
let mut image_handles = page.selection.selection_handles.iter();
|
||||||
|
|
||||||
while let Some((id, handle)) = image_handles.next() {
|
while let Some((id, handle)) = image_handles.next() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue