Skip to content

Commit 3473239

Browse files
authored
Merge pull request #195 from unsecretised/clipboard-page-ui
add a better clipboard UI
2 parents fc8c902 + ae8a8e9 commit 3473239

3 files changed

Lines changed: 72 additions & 32 deletions

File tree

src/app/pages/clipboard.rs

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
//! The elements for the clipboard history page
2-
use iced::widget::{
3-
Scrollable,
4-
image::{Handle, Viewer},
5-
scrollable::{Direction, Scrollbar},
2+
use iced::{
3+
ContentFit,
4+
border::Radius,
5+
widget::{
6+
Scrollable,
7+
image::{Handle, Viewer},
8+
scrollable::{Direction, Scrollbar},
9+
},
610
};
711

812
use crate::{
@@ -26,30 +30,51 @@ pub fn clipboard_view(
2630
) -> Element<'static, Message> {
2731
let theme_clone = theme.clone();
2832
let theme_clone_2 = theme.clone();
29-
let viewport_content: Element<'static, Message> =
30-
match clipboard_content.get(focussed_id as usize) {
31-
Some(content) => match content {
32-
ClipBoardContentType::Text(txt) => Text::new(txt.to_owned())
33+
let viewport_content: Element<'static, Message> = match clipboard_content
34+
.get(focussed_id as usize)
35+
{
36+
Some(content) => match content {
37+
ClipBoardContentType::Text(txt) => Scrollable::with_direction(
38+
Text::new(txt.to_owned())
3339
.height(Length::Fill)
3440
.width(Length::Fill)
3541
.align_x(Alignment::Start)
3642
.font(theme.font())
37-
.size(16)
38-
.into(),
43+
.size(16),
44+
Direction::Both {
45+
vertical: Scrollbar::new().scroller_width(0.).width(0.),
46+
horizontal: Scrollbar::new().scroller_width(0.).width(0.),
47+
},
48+
)
49+
.into(),
3950

40-
ClipBoardContentType::Image(data) => {
41-
let bytes = data.to_owned_img().into_owned_bytes();
51+
ClipBoardContentType::Image(data) => {
52+
let bytes = data.to_owned_img().into_owned_bytes();
53+
container(
4254
Viewer::new(
4355
Handle::from_rgba(data.width as u32, data.height as u32, bytes.to_vec())
4456
.clone(),
4557
)
46-
.width(500)
47-
.height(500)
48-
.into()
49-
}
50-
},
51-
None => Text::new("").into(),
52-
};
58+
.content_fit(ContentFit::ScaleDown)
59+
.scale_step(0.)
60+
.max_scale(1.)
61+
.min_scale(1.),
62+
)
63+
.padding(10)
64+
.style(|_| container::Style {
65+
border: iced::Border {
66+
color: iced::Color::WHITE,
67+
width: 1.,
68+
radius: Radius::new(0.),
69+
},
70+
..Default::default()
71+
})
72+
.width(Length::Fill)
73+
.into()
74+
}
75+
},
76+
None => Text::new("").into(),
77+
};
5378
container(Row::from_vec(vec![
5479
container(
5580
iced::widget::scrollable(
@@ -65,18 +90,12 @@ pub fn clipboard_view(
6590
.height(10000)
6691
.style(move |_| result_row_container_style(&theme_clone_2, false))
6792
.into(),
68-
container(Scrollable::with_direction(
69-
viewport_content,
70-
Direction::Both {
71-
vertical: Scrollbar::new().scroller_width(0.).width(0.),
72-
horizontal: Scrollbar::new().scroller_width(0.).width(0.),
73-
},
74-
))
75-
.height(10000)
76-
.padding(10)
77-
.style(move |_| result_row_container_style(&theme_clone, false))
78-
.width((WINDOW_WIDTH / 3.) * 2.)
79-
.into(),
93+
container(viewport_content)
94+
.height(10000)
95+
.padding(10)
96+
.style(move |_| result_row_container_style(&theme_clone, false))
97+
.width((WINDOW_WIDTH / 3.) * 2.)
98+
.into(),
8099
]))
81100
.height(280)
82101
.into()

src/app/tile.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,9 @@ fn handle_clipboard_history() -> impl futures::Stream<Item = Message> {
355355
loop {
356356
let byte_rep = if let Ok(a) = clipboard.get_image() {
357357
Some(ClipBoardContentType::Image(a))
358-
} else if let Ok(a) = clipboard.get_text() {
358+
} else if let Ok(a) = clipboard.get_text()
359+
&& !a.trim().is_empty()
360+
{
359361
Some(ClipBoardContentType::Text(a))
360362
} else {
361363
None

src/app/tile/update.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use iced::widget::operation::AbsoluteOffset;
1111
use iced::window;
1212
use iced::window::Id;
1313
use log::info;
14+
use rayon::iter::IntoParallelRefIterator;
1415
use rayon::iter::ParallelIterator;
1516
use rayon::slice::ParallelSliceMut;
1617

@@ -408,6 +409,24 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
408409
}
409410

410411
Message::ClipboardHistory(content) => {
412+
if !tile.clipboard_content.contains(&content) {
413+
tile.clipboard_content.insert(0, content);
414+
return Task::none();
415+
}
416+
417+
let new_content_vec = tile
418+
.clipboard_content
419+
.par_iter()
420+
.filter_map(|x| {
421+
if *x == content {
422+
None
423+
} else {
424+
Some(x.to_owned())
425+
}
426+
})
427+
.collect();
428+
429+
tile.clipboard_content = new_content_vec;
411430
tile.clipboard_content.insert(0, content);
412431
Task::none()
413432
}

0 commit comments

Comments
 (0)