-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathclipboard.rs
More file actions
77 lines (70 loc) · 2.34 KB
/
clipboard.rs
File metadata and controls
77 lines (70 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! This has all the logic regarding the cliboard history
use arboard::ImageData;
use iced::{
Length::Fill,
Theme,
alignment::Vertical,
widget::{Button, Row, Text, container},
};
use crate::{app::Message, commands::Function};
/// The kinds of clipboard content that rustcast can handle and their contents
#[derive(Debug, Clone)]
pub enum ClipBoardContentType {
Text(String),
Image(ImageData<'static>),
}
impl ClipBoardContentType {
/// Returns the iced element for rendering the clipboard item
pub fn render_clipboard_item(&self) -> impl Into<iced::Element<'_, Message>> {
let mut tile = Row::new().width(Fill).height(55);
let text = match self {
ClipBoardContentType::Text(text) => text,
ClipBoardContentType::Image(_) => "<img>",
};
tile = tile.push(
Button::new(
Text::new(text.to_owned())
.height(Fill)
.width(Fill)
.align_y(Vertical::Center),
)
.on_press(Message::RunFunction(Function::CopyToClipboard(
self.to_owned(),
)))
.style(|_, _| iced::widget::button::Style {
background: Some(iced::Background::Color(
Theme::KanagawaDragon.palette().background,
)),
text_color: Theme::KanagawaDragon.palette().text,
..Default::default()
})
.width(Fill)
.height(55),
);
container(tile)
.style(|_| iced::widget::container::Style {
text_color: Some(Theme::KanagawaDragon.palette().text),
background: Some(iced::Background::Color(
Theme::KanagawaDragon.palette().background,
)),
..Default::default()
})
.width(Fill)
.height(Fill)
}
}
impl PartialEq for ClipBoardContentType {
/// Let cliboard items be comparable
fn eq(&self, other: &Self) -> bool {
if let Self::Text(a) = self
&& let Self::Text(b) = other
{
return a == b;
} else if let Self::Image(image_data) = self
&& let Self::Image(other_image_data) = other
{
return image_data.bytes == other_image_data.bytes;
}
false
}
}