[feat]: Changing preview size of the slides
This commit is contained in:
parent
9b6287a3e6
commit
be4fc8d370
2 changed files with 82 additions and 16 deletions
64
src/main.rs
64
src/main.rs
|
|
@ -1739,8 +1739,18 @@ impl cosmic::Application for App {
|
|||
Task::none()
|
||||
}
|
||||
Message::ViewModeSwitch(mode) => {
|
||||
let grid_to_row = matches!(mode, ViewMode::Row);
|
||||
|
||||
self.view_mode = mode;
|
||||
Task::none()
|
||||
if grid_to_row
|
||||
&& self.presenter.preview_size() > 150.0
|
||||
{
|
||||
self.update(Message::Present(
|
||||
presenter::Message::ChangePreviewSize(150.0),
|
||||
))
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1885,7 +1895,7 @@ impl cosmic::Application for App {
|
|||
)
|
||||
.clip(true)
|
||||
.width(Length::Fill)
|
||||
.center_y(180)
|
||||
.center_y(200)
|
||||
}
|
||||
} else {
|
||||
Container::new(horizontal())
|
||||
|
|
@ -1979,11 +1989,51 @@ impl cosmic::Application for App {
|
|||
} else {
|
||||
theme::Button::HeaderBar
|
||||
});
|
||||
row![grid_button, list_button, space::horizontal()]
|
||||
.spacing(space_s)
|
||||
.apply(container)
|
||||
.class(theme::Container::Primary)
|
||||
.padding(space_s)
|
||||
let (preview_size_range, preview_breakpoints) =
|
||||
match self.view_mode {
|
||||
ViewMode::Grid => (
|
||||
100.0..=300.0,
|
||||
&[100.0, 150.0, 200.0, 250.0, 300.0],
|
||||
),
|
||||
ViewMode::Row => (
|
||||
100.0..=150.0,
|
||||
&[100.0, 110.0, 120.0, 130.0, 140.0],
|
||||
),
|
||||
ViewMode::Detail => todo!(),
|
||||
};
|
||||
let preview_size_slider = row![
|
||||
text::body("Preview Size"),
|
||||
slider(
|
||||
preview_size_range,
|
||||
self.presenter.preview_size(),
|
||||
|size| {
|
||||
Message::Present(
|
||||
presenter::Message::ChangePreviewSize(
|
||||
size,
|
||||
),
|
||||
)
|
||||
},
|
||||
)
|
||||
.height(space_l)
|
||||
.name("Preview Size")
|
||||
.step(10.0)
|
||||
.breakpoints(preview_breakpoints)
|
||||
]
|
||||
.align_y(Vertical::Center)
|
||||
.spacing(space_s)
|
||||
.apply(container)
|
||||
.padding([space_none, space_none, space_none, space_s]);
|
||||
row![
|
||||
grid_button,
|
||||
list_button,
|
||||
space::horizontal(),
|
||||
preview_size_slider
|
||||
]
|
||||
.align_y(Vertical::Center)
|
||||
.spacing(space_s)
|
||||
.apply(container)
|
||||
.class(theme::Container::Primary)
|
||||
.padding(space_s)
|
||||
} else {
|
||||
horizontal().apply(container)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ use cosmic::iced::{
|
|||
use cosmic::prelude::*;
|
||||
use cosmic::widget::divider::{self, vertical};
|
||||
use cosmic::widget::{
|
||||
Container, Id, Row, Space, column, container, flex_row,
|
||||
image as cosmic_image, menu, mouse_area, popover, responsive,
|
||||
scrollable, space, text,
|
||||
Container, Id, JustifyContent, Row, Space, column, container,
|
||||
flex_row, image as cosmic_image, menu, mouse_area, popover,
|
||||
responsive, scrollable, space, text,
|
||||
};
|
||||
use cosmic::{Task, theme};
|
||||
use derive_more::Debug;
|
||||
|
|
@ -69,6 +69,7 @@ pub(crate) struct Presenter {
|
|||
context_menu_id: Option<(usize, usize)>,
|
||||
context_point: Point,
|
||||
obs_scenes: Option<Vec<Scene>>,
|
||||
preview_size: f32,
|
||||
pub image_loader: ImageLoader,
|
||||
}
|
||||
|
||||
|
|
@ -107,6 +108,7 @@ pub(crate) enum Message {
|
|||
AssignSlideAction(slide_actions::Action),
|
||||
PlayPauseVideo,
|
||||
CloseContextMenu,
|
||||
ChangePreviewSize(f64),
|
||||
}
|
||||
|
||||
// #[allow(clippy::enum_variant_names)]
|
||||
|
|
@ -256,6 +258,7 @@ impl Presenter {
|
|||
context_point: Point::ORIGIN,
|
||||
obs_scenes: None,
|
||||
image_loader: ImageLoader::default(),
|
||||
preview_size: 100.0,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -424,6 +427,9 @@ impl Presenter {
|
|||
self.slide_action_map = Some(map);
|
||||
}
|
||||
}
|
||||
Message::ChangePreviewSize(size) => {
|
||||
self.preview_size = size as f32;
|
||||
}
|
||||
Message::ChangeFont(s) => {
|
||||
let font_name = s.into_boxed_str();
|
||||
let family = Family::Name(Box::leak(font_name));
|
||||
|
|
@ -639,8 +645,8 @@ impl Presenter {
|
|||
};
|
||||
style
|
||||
})
|
||||
.center_x(100.0 * 16.0 / 9.0)
|
||||
.height(100)
|
||||
.center_x(self.preview_size * 16.0 / 9.0)
|
||||
.height(self.preview_size)
|
||||
.padding(10),
|
||||
)
|
||||
.interaction(
|
||||
|
|
@ -697,6 +703,9 @@ impl Presenter {
|
|||
let scrollable = scrollable(
|
||||
container(
|
||||
flex_row(items)
|
||||
.justify_content(Some(
|
||||
JustifyContent::SpaceEvenly,
|
||||
))
|
||||
.align_items(cosmic::iced::Alignment::Center)
|
||||
.justify_items(cosmic::iced::Alignment::End)
|
||||
.column_spacing(space_s)
|
||||
|
|
@ -707,10 +716,11 @@ impl Presenter {
|
|||
style.border(Border::default().width(2))
|
||||
}),
|
||||
)
|
||||
.auto_scroll(true)
|
||||
// .direction(Direction::Horizontal(Scrollbar::new()))
|
||||
.height(Length::Fill)
|
||||
.width(Length::Fill)
|
||||
.id(self.scroll_id.clone());
|
||||
.width(Length::Fill);
|
||||
// .id(self.scroll_id.clone());
|
||||
scrollable.into()
|
||||
|
||||
// scrollable.into()
|
||||
|
|
@ -792,8 +802,10 @@ impl Presenter {
|
|||
};
|
||||
style
|
||||
})
|
||||
.center_x(100.0 * 16.0 / 9.0)
|
||||
.height(100)
|
||||
.center_x(
|
||||
self.preview_size * 16.0 / 9.0,
|
||||
)
|
||||
.height(self.preview_size)
|
||||
.padding(10),
|
||||
)
|
||||
.interaction(
|
||||
|
|
@ -1180,6 +1192,10 @@ impl Presenter {
|
|||
debug!(?task_count);
|
||||
Action::Task(Task::batch(tasks))
|
||||
}
|
||||
|
||||
pub(crate) fn preview_size(&self) -> f64 {
|
||||
self.preview_size.into()
|
||||
}
|
||||
}
|
||||
|
||||
// #[allow(clippy::unused_async)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue