@@ -239,12 +239,16 @@ impl LibraryPage {
239
239
fn sync_local ( & mut self , s : & SharedState ) {
240
240
let list = self . tabs . selected_mut ( ) ;
241
241
if list. ty == ChartListType :: Local {
242
- list. view . set (
243
- s. t ,
244
- std:: iter:: once ( ChartDisplayItem :: new ( None , None ) )
245
- . chain ( s. charts_local . iter ( ) . map ( |it| ChartDisplayItem :: new ( Some ( it. clone ( ) ) , None ) ) )
246
- . collect ( ) ,
242
+ let search = self . search_str . clone ( ) ;
243
+ let mut charts = Vec :: new ( ) ;
244
+ charts. push ( ChartDisplayItem :: new ( None , None ) ) ;
245
+ charts. append ( & mut s. charts_local
246
+ . iter ( )
247
+ . filter ( |it| it. info . name . contains ( & search) )
248
+ . map ( |it| ChartDisplayItem :: new ( Some ( it. clone ( ) ) , None ) )
249
+ . collect :: < Vec < ChartDisplayItem > > ( )
247
250
) ;
251
+ list. view . set ( s. t , charts) ;
248
252
}
249
253
}
250
254
}
@@ -310,6 +314,16 @@ impl Page for LibraryPage {
310
314
request_file ( "_import" ) ;
311
315
return Ok ( true ) ;
312
316
}
317
+ if !self . search_str . is_empty ( ) && self . search_clr_btn . touch ( touch) {
318
+ button_hit ( ) ;
319
+ self . search_str . clear ( ) ;
320
+ self . sync_local ( s) ;
321
+ return Ok ( true ) ;
322
+ }
323
+ if !self . search_clr_btn . contains ( touch. position ) && self . search_btn . touch ( touch, t) {
324
+ request_input ( "search" , & self . search_str ) ;
325
+ return Ok ( true ) ;
326
+ }
313
327
}
314
328
ChartListType :: Ranked | ChartListType :: Special | ChartListType :: Unstable => {
315
329
if !self . search_str . is_empty ( ) && self . search_clr_btn . touch ( touch) {
@@ -346,18 +360,15 @@ impl Page for LibraryPage {
346
360
self . tags . update ( t) ;
347
361
self . rating . update ( t) ;
348
362
363
+ let is_local = self . tabs . selected ( ) . ty == ChartListType :: Local ;
349
364
if self . tabs . changed ( ) {
350
365
self . tabs . selected_mut ( ) . view . reset_scroll ( ) ;
351
- match self . tabs . selected ( ) . ty {
352
- ChartListType :: Local => {
353
- self . online_task = None ;
354
- self . sync_local ( s) ;
355
- }
356
- _ => {
357
- self . online_task = None ;
358
- self . current_page = 0 ;
359
- self . load_online ( ) ;
360
- }
366
+ self . online_task = None ;
367
+ if is_local {
368
+ self . sync_local ( s) ;
369
+ } else {
370
+ self . current_page = 0 ;
371
+ self . load_online ( ) ;
361
372
}
362
373
}
363
374
if self . tabs . selected_mut ( ) . view . clicked_special {
@@ -416,8 +427,12 @@ impl Page for LibraryPage {
416
427
if let Some ( ( id, text) ) = take_input ( ) {
417
428
if id == "search" {
418
429
self . search_str = text;
419
- self . current_page = 0 ;
420
- self . load_online ( ) ;
430
+ if is_local {
431
+ self . sync_local ( s) ;
432
+ } else {
433
+ self . current_page = 0 ;
434
+ self . load_online ( ) ;
435
+ }
421
436
} else {
422
437
return_input ( id, text) ;
423
438
}
@@ -447,47 +462,55 @@ impl Page for LibraryPage {
447
462
Ok ( ( ) )
448
463
} )
449
464
} ) ?;
450
- match chosen {
451
- ChartListType :: Local => {
452
- s. render_fader ( ui, |ui| {
453
- let w = 0.24 ;
454
- let r = Rect :: new ( r. right ( ) - w, -ui. top + 0.04 , w, r. y + ui. top - 0.06 ) ;
455
- self . import_btn . render_text ( ui, r, t, tl ! ( "import" ) , 0.6 , false ) ;
465
+ if chosen != ChartListType :: Popular {
466
+ s. render_fader ( ui, |ui| {
467
+ let empty = self . search_str . is_empty ( ) ;
468
+ let w = 0.53 ;
469
+ let mut r = Rect :: new ( r. right ( ) - w, -ui. top + 0.04 , w, r. y + ui. top - 0.06 ) ;
470
+ if empty {
471
+ r. x += r. h ;
472
+ r. w -= r. h ;
473
+ }
474
+ let rt = r. right ( ) ;
475
+ self . search_btn . render_shadow ( ui, r, t, |ui, path| {
476
+ ui. fill_path ( & path, semi_black ( 0.4 ) ) ;
456
477
} ) ;
457
- }
458
- ChartListType :: Ranked | ChartListType :: Special | ChartListType :: Unstable => {
459
- s. render_fader ( ui, |ui| {
460
- let empty = self . search_str . is_empty ( ) ;
461
- let w = 0.53 ;
462
- let mut r = Rect :: new ( r. right ( ) - w, -ui. top + 0.04 , w, r. y + ui. top - 0.06 ) ;
463
- if empty {
464
- r. x += r. h ;
465
- r. w -= r. h ;
466
- }
467
- let rt = r. right ( ) ;
468
- self . search_btn . render_shadow ( ui, r, t, |ui, path| {
478
+ let mut r = r. feather ( -0.01 ) ;
479
+ r. w = r. h ;
480
+ if !empty {
481
+ ui. fill_rect ( r, ( * self . icons . close , r, ScaleType :: Fit ) ) ;
482
+ self . search_clr_btn . set ( ui, r) ;
483
+ r. x += r. w ;
484
+ }
485
+ ui. fill_rect ( r, ( * self . icons . search , r, ScaleType :: Fit ) ) ;
486
+ ui. text ( & self . search_str )
487
+ . pos ( r. right ( ) + 0.01 , r. center ( ) . y )
488
+ . anchor ( 0. , 0.5 )
489
+ . no_baseline ( )
490
+ . size ( 0.6 )
491
+ . max_width ( rt - r. right ( ) - 0.02 )
492
+ . draw ( ) ;
493
+ let mut r = r. feather ( 0.01 ) ;
494
+ // TODO: better shifting
495
+ r. x = 1. - w - r. w - 0.05 ;
496
+ if empty {
497
+ r. x += r. w ;
498
+ }
499
+ if chosen == ChartListType :: Local {
500
+ let w = 0.24 ;
501
+ r. x = r. x + r. w - w;
502
+ r. w = w;
503
+ let ct = r. center ( ) ;
504
+ self . import_btn . render_shadow ( ui, r, t, |ui, path| {
469
505
ui. fill_path ( & path, semi_black ( 0.4 ) ) ;
470
506
} ) ;
471
- let mut r = r. feather ( -0.01 ) ;
472
- r. w = r. h ;
473
- if !empty {
474
- ui. fill_rect ( r, ( * self . icons . close , r, ScaleType :: Fit ) ) ;
475
- self . search_clr_btn . set ( ui, r) ;
476
- r. x += r. w ;
477
- }
478
- ui. fill_rect ( r, ( * self . icons . search , r, ScaleType :: Fit ) ) ;
479
- ui. text ( & self . search_str )
480
- . pos ( r. right ( ) + 0.01 , r. center ( ) . y )
481
- . anchor ( 0. , 0.5 )
507
+ ui. text ( tl ! ( "import" ) )
508
+ . pos ( ct. x , ct. y )
509
+ . anchor ( 0.5 , 0.5 )
482
510
. no_baseline ( )
483
511
. size ( 0.6 )
484
- . max_width ( rt - r. right ( ) - 0.02 )
485
512
. draw ( ) ;
486
- let mut r = r. feather ( 0.01 ) ;
487
- r. x = 1. - w - r. w - 0.05 ;
488
- if empty {
489
- r. x += r. w ;
490
- }
513
+ } else {
491
514
self . order_btn . render_shadow ( ui, r, t, |ui, path| {
492
515
ui. fill_path ( & path, semi_black ( 0.4 ) ) ;
493
516
ui. fill_rect ( r, ( * self . icons . order , r, ScaleType :: Fit ) ) ;
@@ -504,9 +527,8 @@ impl Page for LibraryPage {
504
527
let cr = r. feather ( -0.005 ) ;
505
528
ui. fill_rect ( cr, ( * self . icons . filter , cr, ScaleType :: Fit ) ) ;
506
529
} ) ;
507
- } ) ;
508
- }
509
- ChartListType :: Popular => { }
530
+ }
531
+ } ) ;
510
532
}
511
533
if chosen != ChartListType :: Local {
512
534
let total_page = self . total_page ( s) ;
0 commit comments