22
33use iced:: widget:: Slider ;
44use iced:: widget:: checkbox;
5- use iced:: widget:: scrollable;
65use iced:: widget:: text_input;
76
87use crate :: app:: SetConfigBufferFields ;
@@ -17,7 +16,7 @@ use crate::{
1716} ;
1817
1918const SETTINGS_ITEM_PADDING : u16 = 5 ;
20- const SETTINGS_ITEM_HEIGHT : u32 = 70 ;
19+ const SETTINGS_ITEM_HEIGHT : u32 = 80 ;
2120const SETTINGS_ITEM_COL_SPACING : u32 = 5 ;
2221
2322pub fn settings_page ( config : Config ) -> Element < ' static , Message > {
@@ -29,43 +28,47 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
2928 settings_hint_text ( theme. clone ( ) , "Toggle hotkey" ) ,
3029 text_input ( "Toggle Hotkey" , & config. toggle_hotkey )
3130 . on_input ( |input| Message :: SetConfig ( SetConfigFields :: ToggleHotkey ( input. clone ( ) ) ) )
32- . on_submit ( Message :: WriteConfig )
31+ . on_submit ( Message :: WriteConfig ( false ) )
3332 . width ( Length :: Fill )
3433 . style ( move |_, _| settings_text_input_item_style ( & hotkey_theme) )
3534 . into ( ) ,
35+ notice_item ( theme. clone ( ) , "Requires a restart" ) ,
3636 ] ) ;
3737
3838 let cb_theme = theme. clone ( ) ;
3939 let cb_hotkey = settings_item_column ( [
4040 settings_hint_text ( theme. clone ( ) , "Clipboard hotkey" ) ,
4141 text_input ( "Clipboard Hotkey" , & config. clipboard_hotkey )
4242 . on_input ( |input| Message :: SetConfig ( SetConfigFields :: ClipboardHotkey ( input. clone ( ) ) ) )
43- . on_submit ( Message :: WriteConfig )
43+ . on_submit ( Message :: WriteConfig ( false ) )
4444 . width ( Length :: Fill )
4545 . style ( move |_, _| settings_text_input_item_style ( & cb_theme) )
4646 . into ( ) ,
47+ notice_item ( theme. clone ( ) , "Requires a restart" ) ,
4748 ] ) ;
4849
4950 let placeholder_theme = theme. clone ( ) ;
5051 let placeholder_setting = settings_item_column ( [
5152 settings_hint_text ( theme. clone ( ) , "Set the rustcast placeholder" ) ,
5253 text_input ( "Set Placeholder" , & config. placeholder )
5354 . on_input ( |input| Message :: SetConfig ( SetConfigFields :: PlaceHolder ( input. clone ( ) ) ) )
54- . on_submit ( Message :: WriteConfig )
55+ . on_submit ( Message :: WriteConfig ( false ) )
5556 . width ( Length :: Fill )
5657 . style ( move |_, _| settings_text_input_item_style ( & placeholder_theme) )
5758 . into ( ) ,
59+ notice_item ( theme. clone ( ) , "What the text box shows when its empty" ) ,
5860 ] ) ;
5961
6062 let theme_clone = theme. clone ( ) ;
6163 let search = settings_item_column ( [
6264 settings_hint_text ( theme. clone ( ) , "Set the search URL" ) ,
6365 text_input ( "Set Search URL" , & config. search_url )
6466 . on_input ( |input| Message :: SetConfig ( SetConfigFields :: SearchUrl ( input. clone ( ) ) ) )
65- . on_submit ( Message :: WriteConfig )
67+ . on_submit ( Message :: WriteConfig ( false ) )
6668 . width ( Length :: Fill )
6769 . style ( move |_, _| settings_text_input_item_style ( & theme_clone) )
6870 . into ( ) ,
71+ notice_item ( theme. clone ( ) , "Which search engine to use (%s = query)" ) ,
6972 ] ) ;
7073
7174 let theme_clone = theme. clone ( ) ;
@@ -77,10 +80,14 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
7780 let delay = input. parse :: < u64 > ( ) . unwrap_or ( current_delay) ;
7881 Message :: SetConfig ( SetConfigFields :: DebounceDelay ( delay) )
7982 } )
80- . on_submit ( Message :: WriteConfig )
83+ . on_submit ( Message :: WriteConfig ( false ) )
8184 . width ( Length :: Fill )
8285 . style ( move |_, _| settings_text_input_item_style ( & theme_clone) )
8386 . into ( ) ,
87+ notice_item (
88+ theme. clone ( ) ,
89+ "How quickly you want file searching to return a value" ,
90+ ) ,
8491 ] ) ;
8592
8693 let theme_clone = theme. clone ( ) ;
@@ -90,6 +97,10 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
9097 . style ( move |_, _| settings_checkbox_style ( & theme_clone) )
9198 . on_toggle ( |input| Message :: SetConfig ( SetConfigFields :: HapticFeedback ( input) ) )
9299 . into ( ) ,
100+ notice_item (
101+ theme. clone ( ) ,
102+ "If there should be haptic feedback when you type" ,
103+ ) ,
93104 ] )
94105 . align_y ( Alignment :: Center )
95106 . spacing ( SETTINGS_ITEM_COL_SPACING * 2 )
@@ -103,6 +114,24 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
103114 . style ( move |_, _| settings_checkbox_style ( & theme_clone) )
104115 . on_toggle ( |input| Message :: SetConfig ( SetConfigFields :: ShowMenubarIcon ( input) ) )
105116 . into ( ) ,
117+ notice_item (
118+ theme. clone ( ) ,
119+ "If the menubar icon should be shown in rustcast" ,
120+ ) ,
121+ ] ) ;
122+
123+ let theme_clone = theme. clone ( ) ;
124+ let show_scrollbar = settings_item_row ( [
125+ settings_hint_text ( theme. clone ( ) , "Show scrollbar" ) ,
126+ checkbox ( config. theme . show_scroll_bar )
127+ . style ( move |_, _| settings_checkbox_style ( & theme_clone) )
128+ . on_toggle ( |input| {
129+ Message :: SetConfig ( SetConfigFields :: SetThemeFields (
130+ SetConfigThemeFields :: ShowScrollBar ( input) ,
131+ ) )
132+ } )
133+ . into ( ) ,
134+ notice_item ( theme. clone ( ) , "If there should be a scrollbar" ) ,
106135 ] ) ;
107136
108137 let theme_clone = theme. clone ( ) ;
@@ -116,6 +145,10 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
116145 ) )
117146 } )
118147 . into ( ) ,
148+ notice_item (
149+ theme. clone ( ) ,
150+ "If the query should be cleared when rustcast is hidden" ,
151+ ) ,
119152 ] ) ;
120153
121154 let theme_clone = theme. clone ( ) ;
@@ -129,6 +162,10 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
129162 ) )
130163 } )
131164 . into ( ) ,
165+ notice_item (
166+ theme. clone ( ) ,
167+ "If the query should be cleared when an app is opened" ,
168+ ) ,
132169 ] ) ;
133170
134171 let theme_clone = theme. clone ( ) ;
@@ -142,6 +179,7 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
142179 ) )
143180 } )
144181 . into ( ) ,
182+ notice_item ( theme. clone ( ) , "If you want app icons to be visible" ) ,
145183 ] ) ;
146184
147185 let theme_clone = theme. clone ( ) ;
@@ -153,10 +191,11 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
153191 input,
154192 ) ) )
155193 } )
156- . on_submit ( Message :: WriteConfig )
194+ . on_submit ( Message :: WriteConfig ( false ) )
157195 . width ( Length :: Fill )
158196 . style ( move |_, _| settings_text_input_item_style ( & theme_clone) )
159197 . into ( ) ,
198+ notice_item ( theme. clone ( ) , "What font rustcast should use" ) ,
160199 ] ) ;
161200
162201 let theme_clone = theme. clone ( ) ;
@@ -166,7 +205,10 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
166205 let text_clr = Column :: from_iter ( [
167206 settings_hint_text ( theme. clone ( ) , "Set text colour" ) ,
168207 Column :: from_iter ( [
169- settings_hint_text ( theme. clone ( ) , "Set R value" ) ,
208+ settings_hint_text (
209+ theme. clone ( ) ,
210+ format ! ( "R value: {}" , theme_clone. text_color. 0 ) ,
211+ ) ,
170212 Slider :: new (
171213 0 ..=100 ,
172214 ( theme_clone. text_color . 0 * 100. ) as i32 ,
@@ -181,7 +223,10 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
181223 . style ( move |_, _| settings_slider_style ( & theme_clone_1) )
182224 . width ( ( WINDOW_WIDTH / 5. ) * 4. )
183225 . into ( ) ,
184- settings_hint_text ( theme. clone ( ) , "Set G value" ) ,
226+ settings_hint_text (
227+ theme. clone ( ) ,
228+ format ! ( "G value: {}" , theme_clone. text_color. 1 ) ,
229+ ) ,
185230 Slider :: new (
186231 0 ..=100 ,
187232 ( theme_clone. text_color . 1 * 100. ) as i32 ,
@@ -196,7 +241,10 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
196241 . style ( move |_, _| settings_slider_style ( & theme_clone_2) )
197242 . width ( ( WINDOW_WIDTH / 5. ) * 4. )
198243 . into ( ) ,
199- settings_hint_text ( theme. clone ( ) , "Set B value" ) ,
244+ settings_hint_text (
245+ theme. clone ( ) ,
246+ format ! ( "B value: {}" , theme_clone. text_color. 2 ) ,
247+ ) ,
200248 Slider :: new (
201249 0 ..=100 ,
202250 ( theme_clone. text_color . 2 * 100. ) as i32 ,
@@ -211,6 +259,7 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
211259 . style ( move |_, _| settings_slider_style ( & theme_clone_3) )
212260 . width ( ( WINDOW_WIDTH / 5. ) * 4. )
213261 . into ( ) ,
262+ notice_item ( theme. clone ( ) , "Text colour in RGB format" ) ,
214263 ] )
215264 . spacing ( 7 )
216265 . width ( Length :: Fill )
@@ -225,7 +274,10 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
225274 let bg_clr = Column :: from_iter ( [
226275 settings_hint_text ( theme. clone ( ) , "Set background colour" ) ,
227276 Column :: from_iter ( [
228- settings_hint_text ( theme. clone ( ) , "Set R value" ) ,
277+ settings_hint_text (
278+ theme. clone ( ) ,
279+ format ! ( "R value: {}" , theme_clone. background_color. 0 ) ,
280+ ) ,
229281 Slider :: new (
230282 0 ..=100 ,
231283 ( theme_clone. background_color . 0 * 100. ) as i32 ,
@@ -240,7 +292,10 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
240292 . style ( move |_, _| settings_slider_style ( & theme_clone_1) )
241293 . width ( ( WINDOW_WIDTH / 5. ) * 4. )
242294 . into ( ) ,
243- settings_hint_text ( theme. clone ( ) , "Set G value" ) ,
295+ settings_hint_text (
296+ theme. clone ( ) ,
297+ format ! ( "G value: {}" , theme_clone. background_color. 1 ) ,
298+ ) ,
244299 Slider :: new (
245300 0 ..=100 ,
246301 ( theme_clone. background_color . 1 * 100. ) as i32 ,
@@ -255,7 +310,10 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
255310 . style ( move |_, _| settings_slider_style ( & theme_clone_2) )
256311 . width ( ( WINDOW_WIDTH / 5. ) * 4. )
257312 . into ( ) ,
258- settings_hint_text ( theme. clone ( ) , "Set B value" ) ,
313+ settings_hint_text (
314+ theme. clone ( ) ,
315+ format ! ( "B value: {}" , theme_clone. background_color. 2 ) ,
316+ ) ,
259317 Slider :: new (
260318 0 ..=100 ,
261319 ( theme_clone. background_color . 2 * 100. ) as i32 ,
@@ -270,41 +328,47 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
270328 . style ( move |_, _| settings_slider_style ( & theme_clone_3) )
271329 . width ( ( WINDOW_WIDTH / 5. ) * 4. )
272330 . into ( ) ,
331+ notice_item ( theme. clone ( ) , "Background colour in RGB format" ) ,
273332 ] )
274333 . spacing ( 7 )
275334 . width ( Length :: Fill )
276335 . align_x ( Alignment :: Center )
277336 . into ( ) ,
278337 ] ) ;
279338
280- container ( scrollable (
281- Column :: from_iter ( [
282- hotkey . into ( ) ,
283- cb_hotkey . into ( ) ,
284- placeholder_setting . into ( ) ,
285- search . into ( ) ,
286- debounce . into ( ) ,
287- haptic . into ( ) ,
288- tray_icon . into ( ) ,
289- clear_on_hide. into ( ) ,
290- clear_on_enter. into ( ) ,
291- show_icons. into ( ) ,
292- font_family. into ( ) ,
293- text_clr. into ( ) ,
294- bg_clr. into ( ) ,
295- Row :: from_iter ( [ savebutton ( theme . clone ( ) ) , default_button ( theme . clone ( ) ) ] )
296- . spacing ( 5 )
297- . width ( Length :: Fill )
298- . into ( ) ,
339+ let items = Column :: from_iter ( [
340+ hotkey . into ( ) ,
341+ cb_hotkey . into ( ) ,
342+ placeholder_setting . into ( ) ,
343+ search . into ( ) ,
344+ debounce . into ( ) ,
345+ haptic . into ( ) ,
346+ tray_icon . into ( ) ,
347+ show_scrollbar . into ( ) ,
348+ clear_on_hide. into ( ) ,
349+ clear_on_enter. into ( ) ,
350+ show_icons. into ( ) ,
351+ font_family. into ( ) ,
352+ text_clr. into ( ) ,
353+ bg_clr. into ( ) ,
354+ Row :: from_iter ( [
355+ savebutton ( theme . clone ( ) ) ,
356+ default_button ( theme . clone ( ) ) ,
357+ wiki_button ( theme . clone ( ) ) ,
299358 ] )
300- . spacing ( 10 ) ,
301- ) )
302- . style ( move |_| result_row_container_style ( & theme, false ) )
303- . height ( Length :: Fill )
304- . width ( Length :: Fill )
305- . padding ( 10 )
306- . align_x ( Alignment :: Center )
307- . into ( )
359+ . spacing ( 5 )
360+ . width ( Length :: Fill )
361+ . into ( ) ,
362+ ] )
363+ . spacing ( 10 ) ;
364+
365+ container ( items)
366+ . style ( move |_| result_row_container_style ( & theme, false ) )
367+ . height ( Length :: Fill )
368+ . width ( Length :: Fill )
369+ . padding ( 10 )
370+ . align_x ( Alignment :: Center )
371+ . into ( )
308372}
309373
310374fn savebutton ( theme : Theme ) -> Element < ' static , Message > {
@@ -316,7 +380,7 @@ fn savebutton(theme: Theme) -> Element<'static, Message> {
316380 )
317381 . style ( move |_, _| settings_save_button_style ( & theme) )
318382 . width ( Length :: Fill )
319- . on_press ( Message :: WriteConfig )
383+ . on_press ( Message :: WriteConfig ( true ) )
320384 . into ( )
321385}
322386
@@ -333,6 +397,23 @@ fn default_button(theme: Theme) -> Element<'static, Message> {
333397 . into ( )
334398}
335399
400+ fn wiki_button ( theme : Theme ) -> Element < ' static , Message > {
401+ Button :: new (
402+ Text :: new ( "Open the wiki" )
403+ . align_x ( Alignment :: Center )
404+ . width ( Length :: Fill )
405+ . font ( theme. font ( ) ) ,
406+ )
407+ . style ( move |_, _| settings_save_button_style ( & theme) )
408+ . width ( Length :: Fill )
409+ . on_press ( Message :: RunFunction (
410+ crate :: commands:: Function :: OpenWebsite (
411+ "https://github.com/unsecretised/rustcast/wiki" . to_string ( ) ,
412+ ) ,
413+ ) )
414+ . into ( )
415+ }
416+
336417fn settings_hint_text ( theme : Theme , text : impl ToString ) -> Element < ' static , Message > {
337418 let text = text. to_string ( ) ;
338419
@@ -360,3 +441,13 @@ fn settings_item_row(
360441 . padding ( SETTINGS_ITEM_PADDING )
361442 . height ( SETTINGS_ITEM_HEIGHT )
362443}
444+
445+ fn notice_item ( theme : Theme , notice : impl ToString ) -> Element < ' static , Message > {
446+ Text :: new ( notice. to_string ( ) )
447+ . font ( theme. font ( ) )
448+ . color ( theme. text_color ( 0.7 ) )
449+ . size ( 10 )
450+ . width ( Length :: Fill )
451+ . align_x ( Alignment :: End )
452+ . into ( )
453+ }
0 commit comments