@@ -31,6 +31,7 @@ pub struct NoteView<'a> {
31
31
ndb : & ' a Ndb ,
32
32
note_cache : & ' a mut NoteCache ,
33
33
img_cache : & ' a mut ImageCache ,
34
+ parent : Option < NoteKey > ,
34
35
note : & ' a nostrdb:: Note < ' a > ,
35
36
flags : NoteOptions ,
36
37
}
@@ -195,10 +196,12 @@ impl<'a> NoteView<'a> {
195
196
note : & ' a nostrdb:: Note < ' a > ,
196
197
) -> Self {
197
198
let flags = NoteOptions :: actionbar | NoteOptions :: note_previews;
199
+ let parent: Option < NoteKey > = None ;
198
200
Self {
199
201
ndb,
200
202
note_cache,
201
203
img_cache,
204
+ parent,
202
205
note,
203
206
flags,
204
207
}
@@ -257,6 +260,11 @@ impl<'a> NoteView<'a> {
257
260
& mut self . flags
258
261
}
259
262
263
+ pub fn parent ( mut self , parent : NoteKey ) -> Self {
264
+ self . parent = Some ( parent) ;
265
+ self
266
+ }
267
+
260
268
fn textmode_ui ( & mut self , ui : & mut egui:: Ui ) -> egui:: Response {
261
269
let note_key = self . note . key ( ) . expect ( "todo: implement non-db notes" ) ;
262
270
let txn = self . note . txn ( ) . expect ( "todo: implement non-db notes" ) ;
@@ -440,8 +448,9 @@ impl<'a> NoteView<'a> {
440
448
let mut note_action: Option < NoteAction > = None ;
441
449
let mut selected_option: Option < NoteContextSelection > = None ;
442
450
451
+ let hitbox_id = note_hitbox_id ( note_key, self . options ( ) , self . parent ) ;
443
452
let profile = self . ndb . get_profile_by_pubkey ( txn, self . note . pubkey ( ) ) ;
444
- let maybe_hitbox = maybe_note_hitbox ( ui, note_key ) ;
453
+ let maybe_hitbox = maybe_note_hitbox ( ui, hitbox_id ) ;
445
454
let container_right = {
446
455
let r = ui. available_rect_before_wrap ( ) ;
447
456
let x = r. max . x ;
@@ -451,64 +460,68 @@ impl<'a> NoteView<'a> {
451
460
452
461
// wide design
453
462
let response = if self . options ( ) . has_wide ( ) {
454
- ui. horizontal ( |ui| {
455
- if self . pfp ( note_key, & profile, ui) . clicked ( ) {
456
- note_action = Some ( NoteAction :: OpenProfile ( Pubkey :: new ( * self . note . pubkey ( ) ) ) ) ;
457
- } ;
463
+ ui. vertical ( |ui| {
464
+ ui. horizontal ( |ui| {
465
+ if self . pfp ( note_key, & profile, ui) . clicked ( ) {
466
+ note_action =
467
+ Some ( NoteAction :: OpenProfile ( Pubkey :: new ( * self . note . pubkey ( ) ) ) ) ;
468
+ } ;
458
469
459
- let size = ui. available_size ( ) ;
460
- ui. vertical ( |ui| {
461
- ui. add_sized ( [ size. x , self . options ( ) . pfp_size ( ) ] , |ui : & mut egui:: Ui | {
462
- ui. horizontal_centered ( |ui| {
463
- selected_option = NoteView :: note_header (
464
- ui,
465
- self . note_cache ,
466
- self . note ,
467
- & profile,
468
- self . options ( ) ,
469
- container_right,
470
- )
471
- . context_selection ;
472
- } )
473
- . response
474
- } ) ;
470
+ let size = ui. available_size ( ) ;
471
+ ui. vertical ( |ui| {
472
+ ui. add_sized ( [ size. x , self . options ( ) . pfp_size ( ) ] , |ui : & mut egui:: Ui | {
473
+ ui. horizontal_centered ( |ui| {
474
+ selected_option = NoteView :: note_header (
475
+ ui,
476
+ self . note_cache ,
477
+ self . note ,
478
+ & profile,
479
+ self . options ( ) ,
480
+ container_right,
481
+ )
482
+ . context_selection ;
483
+ } )
484
+ . response
485
+ } ) ;
475
486
476
- let note_reply = self
477
- . note_cache
478
- . cached_note_or_insert_mut ( note_key, self . note )
479
- . reply
480
- . borrow ( self . note . tags ( ) ) ;
487
+ let note_reply = self
488
+ . note_cache
489
+ . cached_note_or_insert_mut ( note_key, self . note )
490
+ . reply
491
+ . borrow ( self . note . tags ( ) ) ;
481
492
482
- if note_reply. reply ( ) . is_some ( ) {
483
- ui. horizontal ( |ui| {
484
- reply_desc ( ui, txn, & note_reply, self . ndb , self . img_cache ) ;
485
- } ) ;
486
- }
493
+ if note_reply. reply ( ) . is_some ( ) {
494
+ ui. horizontal ( |ui| {
495
+ reply_desc ( ui, txn, & note_reply, self . ndb , self . img_cache ) ;
496
+ } ) ;
497
+ }
498
+ } ) ;
487
499
} ) ;
488
- } ) ;
489
500
490
- let mut contents = NoteContents :: new (
491
- self . ndb ,
492
- self . img_cache ,
493
- self . note_cache ,
494
- txn,
495
- self . note ,
496
- note_key,
497
- self . options ( ) ,
498
- ) ;
499
- let resp = ui. add ( & mut contents) ;
501
+ let mut contents = NoteContents :: new (
502
+ self . ndb ,
503
+ self . img_cache ,
504
+ self . note_cache ,
505
+ txn,
506
+ self . note ,
507
+ note_key,
508
+ self . options ( ) ,
509
+ ) ;
500
510
501
- if let Some ( action) = contents. action ( ) {
502
- note_action = Some ( * action) ;
503
- }
511
+ ui. add ( & mut contents) ;
504
512
505
- if self . options ( ) . has_actionbar ( ) {
506
- if let Some ( action) = render_note_actionbar ( ui, self . note . id ( ) , note_key) . inner {
507
- note_action = Some ( action) ;
513
+ if let Some ( action) = contents. action ( ) {
514
+ note_action = Some ( * action) ;
508
515
}
509
- }
510
516
511
- resp
517
+ if self . options ( ) . has_actionbar ( ) {
518
+ if let Some ( action) = render_note_actionbar ( ui, self . note . id ( ) , note_key) . inner
519
+ {
520
+ note_action = Some ( action) ;
521
+ }
522
+ }
523
+ } )
524
+ . response
512
525
} else {
513
526
// main design
514
527
ui. with_layout ( egui:: Layout :: left_to_right ( egui:: Align :: TOP ) , |ui| {
@@ -567,14 +580,11 @@ impl<'a> NoteView<'a> {
567
580
. response
568
581
} ;
569
582
570
- note_action = check_note_hitbox (
571
- ui,
572
- self . note . id ( ) ,
573
- note_key,
574
- & response,
575
- maybe_hitbox,
576
- note_action,
577
- ) ;
583
+ let note_action = if note_hitbox_clicked ( ui, hitbox_id, & response. rect , maybe_hitbox) {
584
+ Some ( NoteAction :: OpenThread ( NoteId :: new ( * self . note . id ( ) ) ) )
585
+ } else {
586
+ note_action
587
+ } ;
578
588
579
589
NoteResponse :: new ( response)
580
590
. with_action ( note_action)
@@ -606,16 +616,18 @@ fn get_reposted_note<'a>(ndb: &Ndb, txn: &'a Transaction, note: &Note) -> Option
606
616
note. filter ( |note| note. kind ( ) == 1 )
607
617
}
608
618
609
- fn note_hitbox_id ( note_key : NoteKey ) -> egui:: Id {
610
- Id :: new ( ( "note_size" , note_key) )
619
+ fn note_hitbox_id (
620
+ note_key : NoteKey ,
621
+ note_options : NoteOptions ,
622
+ parent : Option < NoteKey > ,
623
+ ) -> egui:: Id {
624
+ Id :: new ( ( "note_size" , note_key, note_options, parent) )
611
625
}
612
626
613
- fn maybe_note_hitbox ( ui : & mut egui:: Ui , note_key : NoteKey ) -> Option < Response > {
627
+ fn maybe_note_hitbox ( ui : & mut egui:: Ui , hitbox_id : egui :: Id ) -> Option < Response > {
614
628
ui. ctx ( )
615
- . data_mut ( |d| d. get_persisted ( note_hitbox_id ( note_key ) ) )
629
+ . data_mut ( |d| d. get_persisted ( hitbox_id ) )
616
630
. map ( |note_size : Vec2 | {
617
- let id = ui. make_persistent_id ( ( "hitbox_interact" , note_key) ) ;
618
-
619
631
// The hitbox should extend the entire width of the
620
632
// container. The hitbox height was cached last layout.
621
633
let container_rect = ui. max_rect ( ) ;
@@ -624,28 +636,31 @@ fn maybe_note_hitbox(ui: &mut egui::Ui, note_key: NoteKey) -> Option<Response> {
624
636
max : pos2 ( container_rect. max . x , container_rect. min . y + note_size. y ) ,
625
637
} ;
626
638
627
- ui. interact ( rect, id, egui:: Sense :: click ( ) )
639
+ let response = ui. interact ( rect, hitbox_id, egui:: Sense :: click ( ) ) ;
640
+
641
+ response
642
+ . widget_info ( || egui:: WidgetInfo :: labeled ( egui:: WidgetType :: Other , true , "hitbox" ) ) ;
643
+
644
+ response
628
645
} )
629
646
}
630
647
631
- fn check_note_hitbox (
648
+ fn note_hitbox_clicked (
632
649
ui : & mut egui:: Ui ,
633
- note_id : & [ u8 ; 32 ] ,
634
- note_key : NoteKey ,
635
- note_response : & Response ,
650
+ hitbox_id : egui:: Id ,
651
+ note_rect : & Rect ,
636
652
maybe_hitbox : Option < Response > ,
637
- prior_action : Option < NoteAction > ,
638
- ) -> Option < NoteAction > {
653
+ ) -> bool {
639
654
// Stash the dimensions of the note content so we can render the
640
655
// hitbox in the next frame
641
656
ui. ctx ( ) . data_mut ( |d| {
642
- d. insert_persisted ( note_hitbox_id ( note_key ) , note_response . rect . size ( ) ) ;
657
+ d. insert_persisted ( hitbox_id , note_rect . size ( ) ) ;
643
658
} ) ;
644
659
645
660
// If there was an hitbox and it was clicked open the thread
646
661
match maybe_hitbox {
647
- Some ( hitbox) if hitbox. clicked ( ) => Some ( NoteAction :: OpenThread ( NoteId :: new ( * note_id ) ) ) ,
648
- _ => prior_action ,
662
+ Some ( hitbox) => hitbox. clicked ( ) ,
663
+ _ => false ,
649
664
}
650
665
}
651
666
0 commit comments