@@ -6,12 +6,15 @@ use iced::{
66 Scrollable ,
77 image:: { Handle , Viewer } ,
88 scrollable:: { Direction , Scrollbar } ,
9+ text:: Wrapping ,
10+ text_input,
911 } ,
1012} ;
1113
1214use crate :: {
13- app:: { ToApp , pages:: prelude:: * } ,
15+ app:: { Editable , ToApp , pages:: prelude:: * } ,
1416 clipboard:: ClipBoardContentType ,
17+ styles:: { delete_button_style, settings_text_input_item_style} ,
1518} ;
1619
1720/// The clipboard view
@@ -30,60 +33,36 @@ pub fn clipboard_view(
3033) -> Element < ' static , Message > {
3134 let theme_clone = theme. clone ( ) ;
3235 let theme_clone_2 = theme. clone ( ) ;
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 ( ) )
39- . height ( Length :: Fill )
40- . width ( Length :: Fill )
41- . align_x ( Alignment :: Start )
42- . font ( theme. font ( ) )
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 ( ) ,
50-
51- ClipBoardContentType :: Image ( data) => {
52- let bytes = data. to_owned_img ( ) . into_owned_bytes ( ) ;
53- container (
54- Viewer :: new (
55- Handle :: from_rgba ( data. width as u32 , data. height as u32 , bytes. to_vec ( ) )
56- . clone ( ) ,
57- )
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- } ;
78- container ( Row :: from_vec ( vec ! [
36+ if clipboard_content. is_empty ( ) {
37+ return container (
38+ Text :: new ( "Copy something to use the clipboard history" )
39+ . font ( theme. font ( ) )
40+ . size ( 30 )
41+ . center ( )
42+ . wrapping ( Wrapping :: WordOrGlyph ) ,
43+ )
44+ . height ( Length :: Fill )
45+ . width ( Length :: Fill )
46+ . style ( move |_| result_row_container_style ( & theme_clone, false ) )
47+ . align_x ( Alignment :: Center )
48+ . align_y ( Alignment :: Center )
49+ . into ( ) ;
50+ }
51+ let viewport_content: Element < ' static , Message > =
52+ match clipboard_content. get ( focussed_id as usize ) {
53+ Some ( content) => viewport_content ( content, & theme) ,
54+ None => Text :: new ( "" ) . into ( ) ,
55+ } ;
56+ container ( Row :: from_iter ( [
7957 container (
80- iced :: widget :: scrollable (
58+ Scrollable :: with_direction (
8159 Column :: from_iter ( clipboard_content. iter ( ) . enumerate ( ) . map ( |( i, content) | {
8260 content
8361 . to_app ( )
8462 . render ( theme. clone ( ) , i as u32 , focussed_id)
8563 } ) )
8664 . width ( WINDOW_WIDTH / 3. ) ,
65+ Direction :: Vertical ( Scrollbar :: hidden ( ) ) ,
8766 )
8867 . id ( "results" ) ,
8968 )
@@ -100,3 +79,92 @@ pub fn clipboard_view(
10079 . height ( 280 )
10180 . into ( )
10281}
82+
83+ fn viewport_content ( content : & ClipBoardContentType , theme : & Theme ) -> Element < ' static , Message > {
84+ let viewer: Element < ' static , Message > = match content {
85+ ClipBoardContentType :: Text ( txt) => Scrollable :: with_direction (
86+ container (
87+ Text :: new ( txt. to_owned ( ) )
88+ . height ( Length :: Fill )
89+ . width ( Length :: Fill )
90+ . align_x ( Alignment :: Start )
91+ . font ( theme. font ( ) )
92+ . size ( 16 ) ,
93+ )
94+ . width ( Length :: Fill )
95+ . height ( Length :: Fill ) ,
96+ Direction :: Both {
97+ vertical : Scrollbar :: hidden ( ) ,
98+ horizontal : Scrollbar :: hidden ( ) ,
99+ } ,
100+ )
101+ . height ( Length :: Fill )
102+ . width ( Length :: Fill )
103+ . into ( ) ,
104+
105+ ClipBoardContentType :: Image ( data) => {
106+ let bytes = data. to_owned_img ( ) . into_owned_bytes ( ) ;
107+ container (
108+ Viewer :: new (
109+ Handle :: from_rgba ( data. width as u32 , data. height as u32 , bytes. to_vec ( ) )
110+ . clone ( ) ,
111+ )
112+ . content_fit ( ContentFit :: ScaleDown )
113+ . scale_step ( 0. )
114+ . max_scale ( 1. )
115+ . min_scale ( 1. ) ,
116+ )
117+ . padding ( 10 )
118+ . style ( |_| container:: Style {
119+ border : iced:: Border {
120+ color : iced:: Color :: WHITE ,
121+ width : 1. ,
122+ radius : Radius :: new ( 0. ) ,
123+ } ,
124+ ..Default :: default ( )
125+ } )
126+ . width ( Length :: Fill )
127+ . into ( )
128+ }
129+ } ;
130+
131+ let theme_clone = theme. clone ( ) ;
132+ Column :: from_iter ( [
133+ viewer,
134+ container (
135+ Button :: new ( "Delete" )
136+ . on_press ( Message :: EditClipboardHistory ( Editable :: Delete (
137+ content. to_owned ( ) ,
138+ ) ) )
139+ . style ( move |_, _| delete_button_style ( & theme_clone) ) ,
140+ )
141+ . width ( Length :: Fill )
142+ . align_x ( Alignment :: Center )
143+ . padding ( 10 )
144+ . into ( ) ,
145+ ] )
146+ . into ( )
147+ }
148+
149+ #[ allow( unused) ]
150+ fn editable_text ( text : & str , theme : & Theme ) -> Element < ' static , Message > {
151+ let text_string = text. to_string ( ) ;
152+ let theme_clone = theme. clone ( ) ;
153+ container (
154+ text_input ( "Edit clipboard history text" , text)
155+ . on_input ( move |input| {
156+ Message :: EditClipboardHistory ( Editable :: Update {
157+ old : ClipBoardContentType :: Text ( text_string. clone ( ) ) ,
158+ new : ClipBoardContentType :: Text ( input) ,
159+ } )
160+ } )
161+ . align_x ( Alignment :: Start )
162+ . size ( 16 )
163+ . width ( Length :: Fill )
164+ . style ( move |_, _| settings_text_input_item_style ( & theme_clone) )
165+ . font ( theme. font ( ) ) ,
166+ )
167+ . height ( Length :: Fill )
168+ . width ( Length :: Fill )
169+ . into ( )
170+ }
0 commit comments