1
1
use crate :: {
2
- app_style:: { get_font_size , NotedeckTextStyle } ,
2
+ app_style:: NotedeckTextStyle ,
3
3
column:: Columns ,
4
- fonts :: NamedFontFamily ,
4
+ imgcache :: ImageCache ,
5
5
nav:: RenderNavAction ,
6
6
route:: Route ,
7
- ui:: anim:: { AnimationHelper , ICON_EXPANSION_MULTIPLE } ,
7
+ timeline:: { TimelineId , TimelineRoute } ,
8
+ ui:: {
9
+ self ,
10
+ anim:: { AnimationHelper , ICON_EXPANSION_MULTIPLE } ,
11
+ } ,
8
12
} ;
9
13
10
- use egui:: { pos2, Color32 , Stroke } ;
14
+ use egui:: { pos2, RichText , Stroke } ;
15
+ use enostr:: Pubkey ;
16
+ use nostrdb:: { Ndb , Transaction } ;
11
17
12
18
pub struct NavTitle < ' a > {
19
+ ndb : & ' a Ndb ,
20
+ img_cache : & ' a mut ImageCache ,
13
21
columns : & ' a Columns ,
22
+ deck_author : Option < & ' a Pubkey > ,
14
23
routes : & ' a [ Route ] ,
15
24
}
16
25
17
26
impl < ' a > NavTitle < ' a > {
18
- pub fn new ( columns : & ' a Columns , routes : & ' a [ Route ] ) -> Self {
19
- NavTitle { columns, routes }
27
+ pub fn new (
28
+ ndb : & ' a Ndb ,
29
+ img_cache : & ' a mut ImageCache ,
30
+ columns : & ' a Columns ,
31
+ deck_author : Option < & ' a Pubkey > ,
32
+ routes : & ' a [ Route ] ,
33
+ ) -> Self {
34
+ NavTitle {
35
+ ndb,
36
+ img_cache,
37
+ columns,
38
+ deck_author,
39
+ routes,
40
+ }
20
41
}
21
42
22
43
pub fn show ( & mut self , ui : & mut egui:: Ui ) -> Option < RenderNavAction > {
@@ -34,7 +55,6 @@ impl<'a> NavTitle<'a> {
34
55
) -> Option < RenderNavAction > {
35
56
let icon_width = 32.0 ;
36
57
let padding_external = 16.0 ;
37
- let padding_internal = 8.0 ;
38
58
let has_back = prev ( self . routes ) . is_some ( ) ;
39
59
40
60
let ( spacing_rect, titlebar_rect) = allocated_response
@@ -43,7 +63,8 @@ impl<'a> NavTitle<'a> {
43
63
44
64
ui. advance_cursor_after_rect ( spacing_rect) ;
45
65
46
- let ( titlebar_resp, back_button_resp) = if has_back {
66
+ // TODO: what are we doing with titlebar_response ?
67
+ let ( _titlebar_resp, back_button_resp) = if has_back {
47
68
let ( button_rect, titlebar_rect) = titlebar_rect. split_left_right_at_x (
48
69
allocated_response. rect . left ( ) + icon_width + padding_external,
49
70
) ;
@@ -55,20 +76,7 @@ impl<'a> NavTitle<'a> {
55
76
( allocated_response, None )
56
77
} ;
57
78
58
- self . title (
59
- ui,
60
- self . routes . last ( ) . unwrap ( ) ,
61
- titlebar_resp. rect ,
62
- icon_width,
63
- if has_back {
64
- padding_internal
65
- } else {
66
- padding_external
67
- } ,
68
- ) ;
69
-
70
- let delete_button_resp =
71
- self . delete_column_button ( ui, titlebar_resp, icon_width, padding_external) ;
79
+ let delete_button_resp = self . title ( ui, self . routes . last ( ) . unwrap ( ) ) ;
72
80
73
81
if delete_button_resp. clicked ( ) {
74
82
Some ( RenderNavAction :: RemoveColumn )
@@ -118,13 +126,7 @@ impl<'a> NavTitle<'a> {
118
126
helper. take_animation_response ( )
119
127
}
120
128
121
- fn delete_column_button (
122
- & self ,
123
- ui : & mut egui:: Ui ,
124
- allocation_response : egui:: Response ,
125
- icon_width : f32 ,
126
- padding : f32 ,
127
- ) -> egui:: Response {
129
+ fn delete_column_button ( & self , ui : & mut egui:: Ui , icon_width : f32 ) -> egui:: Response {
128
130
let img_size = 16.0 ;
129
131
let max_size = icon_width * ICON_EXPANSION_MULTIPLE ;
130
132
@@ -135,20 +137,8 @@ impl<'a> NavTitle<'a> {
135
137
} ;
136
138
let img = egui:: Image :: new ( img_data) . max_width ( img_size) ;
137
139
138
- let button_rect = {
139
- let titlebar_rect = allocation_response. rect ;
140
- let titlebar_width = titlebar_rect. width ( ) ;
141
- let titlebar_center = titlebar_rect. center ( ) ;
142
- let button_center_y = titlebar_center. y ;
143
- let button_center_x =
144
- titlebar_center. x + ( titlebar_width / 2.0 ) - ( max_size / 2.0 ) - padding;
145
- egui:: Rect :: from_center_size (
146
- pos2 ( button_center_x, button_center_y) ,
147
- egui:: vec2 ( max_size, max_size) ,
148
- )
149
- } ;
150
-
151
- let helper = AnimationHelper :: new_from_rect ( ui, "delete-column-button" , button_rect) ;
140
+ let helper =
141
+ AnimationHelper :: new ( ui, "delete-column-button" , egui:: vec2 ( max_size, max_size) ) ;
152
142
153
143
let cur_img_size = helper. scale_1d_pos_min_max ( 0.0 , img_size) ;
154
144
@@ -160,42 +150,89 @@ impl<'a> NavTitle<'a> {
160
150
animation_resp
161
151
}
162
152
163
- fn title (
164
- & mut self ,
165
- ui : & mut egui :: Ui ,
166
- top : & Route ,
167
- titlebar_rect : egui :: Rect ,
168
- icon_width : f32 ,
169
- padding : f32 ,
170
- ) {
171
- let painter = ui . painter_at ( titlebar_rect ) ;
172
-
173
- let font = egui :: FontId :: new (
174
- get_font_size ( ui. ctx ( ) , & NotedeckTextStyle :: Body ) ,
175
- egui :: FontFamily :: Name ( NamedFontFamily :: Bold . as_str ( ) . into ( ) ) ,
176
- ) ;
153
+ fn pubkey_pfp < ' txn , ' me > (
154
+ & ' me mut self ,
155
+ txn : & ' txn Transaction ,
156
+ pubkey : & [ u8 ; 32 ] ,
157
+ pfp_size : f32 ,
158
+ ) -> Option < ui :: ProfilePic < ' me , ' txn > > {
159
+ self . ndb
160
+ . get_profile_by_pubkey ( txn , pubkey )
161
+ . as_ref ( )
162
+ . ok ( )
163
+ . and_then ( move |p| {
164
+ Some ( ui:: ProfilePic :: from_profile ( self . img_cache , p ) ? . size ( pfp_size ) )
165
+ } )
166
+ }
177
167
178
- let max_title_width = titlebar_rect. width ( ) - icon_width - padding * 2. ;
168
+ fn timeline_pfp ( & mut self , ui : & mut egui:: Ui , id : TimelineId , pfp_size : f32 ) {
169
+ let txn = Transaction :: new ( self . ndb ) . unwrap ( ) ;
170
+
171
+ if let Some ( pfp) = self
172
+ . columns
173
+ . find_timeline ( id)
174
+ . and_then ( |tl| tl. kind . pubkey_source ( ) )
175
+ . and_then ( |pksrc| self . deck_author . map ( |da| pksrc. to_pubkey ( da) ) )
176
+ . and_then ( |pk| self . pubkey_pfp ( & txn, pk. bytes ( ) , pfp_size) )
177
+ {
178
+ ui. add ( pfp) ;
179
+ } else {
180
+ ui. add (
181
+ ui:: ProfilePic :: new ( self . img_cache , ui:: ProfilePic :: no_pfp_url ( ) ) . size ( pfp_size) ,
182
+ ) ;
183
+ }
184
+ }
179
185
180
- let title_galley = ui. fonts ( |f| {
181
- f. layout (
182
- top. title ( self . columns ) . to_string ( ) ,
183
- font,
184
- ui. visuals ( ) . text_color ( ) ,
185
- max_title_width,
186
- )
187
- } ) ;
186
+ fn title_pfp ( & mut self , ui : & mut egui:: Ui , top : & Route ) {
187
+ let pfp_size = 32.0 ;
188
+ match top {
189
+ Route :: Timeline ( tlr) => match tlr {
190
+ TimelineRoute :: Timeline ( tlid) => {
191
+ self . timeline_pfp ( ui, * tlid, pfp_size) ;
192
+ }
193
+
194
+ TimelineRoute :: Thread ( _note_id) => { }
195
+ TimelineRoute :: Reply ( _note_id) => { }
196
+ TimelineRoute :: Quote ( _note_id) => { }
197
+
198
+ TimelineRoute :: Profile ( pubkey) => {
199
+ let txn = Transaction :: new ( self . ndb ) . unwrap ( ) ;
200
+ if let Some ( pfp) = self . pubkey_pfp ( & txn, pubkey. bytes ( ) , pfp_size) {
201
+ ui. add ( pfp) ;
202
+ } else {
203
+ ui. add (
204
+ ui:: ProfilePic :: new ( self . img_cache , ui:: ProfilePic :: no_pfp_url ( ) )
205
+ . size ( pfp_size) ,
206
+ ) ;
207
+ }
208
+ }
209
+ } ,
188
210
189
- let pos = {
190
- let titlebar_center = titlebar_rect. center ( ) ;
191
- let text_height = title_galley. rect . height ( ) ;
211
+ Route :: Accounts ( _as) => { }
212
+ Route :: ComposeNote => { }
213
+ Route :: AddColumn ( _add_col_route) => { }
214
+ Route :: Support => { }
215
+ Route :: Relays => { }
216
+ }
217
+ }
192
218
193
- let galley_pos_x = titlebar_rect. left ( ) + padding;
194
- let galley_pos_y = titlebar_center. y - ( text_height / 2. ) ;
195
- pos2 ( galley_pos_x, galley_pos_y)
196
- } ;
219
+ fn title ( & mut self , ui : & mut egui:: Ui , top : & Route ) -> egui:: Response {
220
+ ui. horizontal ( |ui| {
221
+ ui. spacing_mut ( ) . item_spacing . x = 10.0 ;
222
+
223
+ self . title_pfp ( ui, top) ;
224
+
225
+ ui. label (
226
+ RichText :: new ( top. title ( self . columns ) )
227
+ . text_style ( NotedeckTextStyle :: Body . text_style ( ) ) ,
228
+ ) ;
197
229
198
- painter. galley ( pos, title_galley, Color32 :: WHITE ) ;
230
+ ui. with_layout ( egui:: Layout :: right_to_left ( egui:: Align :: Center ) , |ui| {
231
+ self . delete_column_button ( ui, 32.0 )
232
+ } )
233
+ . inner
234
+ } )
235
+ . inner
199
236
}
200
237
}
201
238
0 commit comments