1
1
use crate :: {
2
2
accounts:: render_accounts_route,
3
3
actionbar:: NoteAction ,
4
- app_style:: { get_font_size, NotedeckTextStyle } ,
5
- fonts:: NamedFontFamily ,
6
4
notes_holder:: NotesHolder ,
7
5
profile:: Profile ,
8
6
relay_pool_manager:: RelayPoolManager ,
@@ -15,16 +13,15 @@ use crate::{
15
13
ui:: {
16
14
self ,
17
15
add_column:: render_add_column_routes,
18
- anim :: { AnimationHelper , ICON_EXPANSION_MULTIPLE } ,
16
+ column :: { NavColumnHeader , TitleResponse } ,
19
17
note:: { PostAction , PostType } ,
20
18
support:: SupportView ,
21
19
RelayView , View ,
22
20
} ,
23
21
Damus ,
24
22
} ;
25
23
26
- use egui:: { pos2, Color32 , InnerResponse , Stroke } ;
27
- use egui_nav:: { Nav , NavAction , NavResponse , TitleBarResponse } ;
24
+ use egui_nav:: { Nav , NavAction , NavResponse } ;
28
25
use nostrdb:: { Ndb , Transaction } ;
29
26
use tracing:: { error, info} ;
30
27
@@ -45,17 +42,16 @@ impl From<NoteAction> for RenderNavAction {
45
42
}
46
43
}
47
44
45
+ pub type NotedeckNavResponse = NavResponse < Option < RenderNavAction > , TitleResponse > ;
46
+
48
47
pub struct RenderNavResponse {
49
48
column : usize ,
50
- response : NavResponse < Option < RenderNavAction > , TitleResponse > ,
49
+ response : NotedeckNavResponse ,
51
50
}
52
51
53
52
impl RenderNavResponse {
54
53
#[ allow( private_interfaces) ]
55
- pub fn new (
56
- column : usize ,
57
- response : NavResponse < Option < RenderNavAction > , TitleResponse > ,
58
- ) -> Self {
54
+ pub fn new ( column : usize , response : NotedeckNavResponse ) -> Self {
59
55
RenderNavResponse { column, response }
60
56
}
61
57
@@ -135,8 +131,14 @@ impl RenderNavResponse {
135
131
col_changed = true ;
136
132
}
137
133
138
- if let Some ( title_response) = & self . response . title_response {
139
- match title_response {
134
+ if let Some ( response) = & self . response . title_response {
135
+ match response. inner {
136
+ TitleResponse :: GoBack => {
137
+ app. columns_mut ( ) . column_mut ( col) . router_mut ( ) . go_back ( ) ;
138
+ }
139
+
140
+ TitleResponse :: Nothing => { }
141
+
140
142
TitleResponse :: RemoveColumn => {
141
143
let tl = app. columns ( ) . find_timeline_for_column_index ( col) ;
142
144
if let Some ( timeline) = tl {
@@ -166,11 +168,10 @@ pub fn render_nav(col: usize, app: &mut Damus, ui: &mut egui::Ui) -> RenderNavRe
166
168
. map ( |r| r. get_titled_route ( & app. columns , & app. ndb ) )
167
169
. collect ( ) ;
168
170
169
- let nav_response = Nav :: new ( routes)
171
+ let nav_response = Nav :: new ( routes, NavColumnHeader :: new ( ) )
170
172
. navigating ( app. columns_mut ( ) . column_mut ( col) . router_mut ( ) . navigating )
171
173
. returning ( app. columns_mut ( ) . column_mut ( col) . router_mut ( ) . returning )
172
174
. id_source ( egui:: Id :: new ( col_id) )
173
- . title ( 48.0 , title_bar)
174
175
. show_mut ( ui, |ui, nav| match & nav. top ( ) . route {
175
176
Route :: Timeline ( tlr) => render_timeline_route (
176
177
& app. ndb ,
@@ -211,7 +212,7 @@ pub fn render_nav(col: usize, app: &mut Damus, ui: &mut egui::Ui) -> RenderNavRe
211
212
let kp = app. accounts . get_selected_account ( ) ?. to_full ( ) ?;
212
213
let draft = app. drafts . compose_mut ( ) ;
213
214
214
- let txn = nostrdb :: Transaction :: new ( & app. ndb ) . expect ( "txn" ) ;
215
+ let txn = Transaction :: new ( & app. ndb ) . expect ( "txn" ) ;
215
216
let post_response = ui:: PostView :: new (
216
217
& app. ndb ,
217
218
draft,
@@ -252,172 +253,3 @@ fn unsubscribe_timeline(ndb: &Ndb, timeline: &Timeline) {
252
253
}
253
254
}
254
255
}
255
-
256
- fn title_bar (
257
- ui : & mut egui:: Ui ,
258
- allocated_response : egui:: Response ,
259
- title_name : String ,
260
- back_name : Option < String > ,
261
- ) -> egui:: InnerResponse < TitleBarResponse < TitleResponse > > {
262
- let icon_width = 32.0 ;
263
- let padding_external = 16.0 ;
264
- let padding_internal = 8.0 ;
265
- let has_back = back_name. is_some ( ) ;
266
-
267
- let ( spacing_rect, titlebar_rect) = allocated_response
268
- . rect
269
- . split_left_right_at_x ( allocated_response. rect . left ( ) + padding_external) ;
270
- ui. advance_cursor_after_rect ( spacing_rect) ;
271
-
272
- let ( titlebar_resp, maybe_button_resp) = if has_back {
273
- let ( button_rect, titlebar_rect) = titlebar_rect
274
- . split_left_right_at_x ( allocated_response. rect . left ( ) + icon_width + padding_external) ;
275
- (
276
- allocated_response. with_new_rect ( titlebar_rect) ,
277
- Some ( back_button ( ui, button_rect) ) ,
278
- )
279
- } else {
280
- ( allocated_response, None )
281
- } ;
282
-
283
- title (
284
- ui,
285
- title_name,
286
- titlebar_resp. rect ,
287
- icon_width,
288
- if has_back {
289
- padding_internal
290
- } else {
291
- padding_external
292
- } ,
293
- ) ;
294
-
295
- let delete_button_resp = delete_column_button ( ui, titlebar_resp, icon_width, padding_external) ;
296
- let title_response = if delete_button_resp. clicked ( ) {
297
- Some ( TitleResponse :: RemoveColumn )
298
- } else {
299
- None
300
- } ;
301
-
302
- let titlebar_resp = TitleBarResponse {
303
- title_response,
304
- go_back : maybe_button_resp. map_or ( false , |r| r. clicked ( ) ) ,
305
- } ;
306
-
307
- InnerResponse :: new ( titlebar_resp, delete_button_resp)
308
- }
309
-
310
- fn back_button ( ui : & mut egui:: Ui , button_rect : egui:: Rect ) -> egui:: Response {
311
- let horizontal_length = 10.0 ;
312
- let arrow_length = 5.0 ;
313
-
314
- let helper = AnimationHelper :: new_from_rect ( ui, "note-compose-button" , button_rect) ;
315
- let painter = ui. painter_at ( helper. get_animation_rect ( ) ) ;
316
- let stroke = Stroke :: new ( 1.5 , ui. visuals ( ) . text_color ( ) ) ;
317
-
318
- // Horizontal segment
319
- let left_horizontal_point = pos2 ( -horizontal_length / 2. , 0. ) ;
320
- let right_horizontal_point = pos2 ( horizontal_length / 2. , 0. ) ;
321
- let scaled_left_horizontal_point = helper. scale_pos_from_center ( left_horizontal_point) ;
322
- let scaled_right_horizontal_point = helper. scale_pos_from_center ( right_horizontal_point) ;
323
-
324
- painter. line_segment (
325
- [ scaled_left_horizontal_point, scaled_right_horizontal_point] ,
326
- stroke,
327
- ) ;
328
-
329
- // Top Arrow
330
- let sqrt_2_over_2 = std:: f32:: consts:: SQRT_2 / 2. ;
331
- let right_top_arrow_point = helper. scale_pos_from_center ( pos2 (
332
- left_horizontal_point. x + ( sqrt_2_over_2 * arrow_length) ,
333
- right_horizontal_point. y + sqrt_2_over_2 * arrow_length,
334
- ) ) ;
335
-
336
- let scaled_left_arrow_point = scaled_left_horizontal_point;
337
- painter. line_segment ( [ scaled_left_arrow_point, right_top_arrow_point] , stroke) ;
338
-
339
- let right_bottom_arrow_point = helper. scale_pos_from_center ( pos2 (
340
- left_horizontal_point. x + ( sqrt_2_over_2 * arrow_length) ,
341
- right_horizontal_point. y - sqrt_2_over_2 * arrow_length,
342
- ) ) ;
343
-
344
- painter. line_segment ( [ scaled_left_arrow_point, right_bottom_arrow_point] , stroke) ;
345
-
346
- helper. take_animation_response ( )
347
- }
348
-
349
- fn delete_column_button (
350
- ui : & mut egui:: Ui ,
351
- allocation_response : egui:: Response ,
352
- icon_width : f32 ,
353
- padding : f32 ,
354
- ) -> egui:: Response {
355
- let img_size = 16.0 ;
356
- let max_size = icon_width * ICON_EXPANSION_MULTIPLE ;
357
-
358
- let img_data = if ui. visuals ( ) . dark_mode {
359
- egui:: include_image!( "../assets/icons/column_delete_icon_4x.png" )
360
- } else {
361
- egui:: include_image!( "../assets/icons/column_delete_icon_light_4x.png" )
362
- } ;
363
- let img = egui:: Image :: new ( img_data) . max_width ( img_size) ;
364
-
365
- let button_rect = {
366
- let titlebar_rect = allocation_response. rect ;
367
- let titlebar_width = titlebar_rect. width ( ) ;
368
- let titlebar_center = titlebar_rect. center ( ) ;
369
- let button_center_y = titlebar_center. y ;
370
- let button_center_x =
371
- titlebar_center. x + ( titlebar_width / 2.0 ) - ( max_size / 2.0 ) - padding;
372
- egui:: Rect :: from_center_size (
373
- pos2 ( button_center_x, button_center_y) ,
374
- egui:: vec2 ( max_size, max_size) ,
375
- )
376
- } ;
377
-
378
- let helper = AnimationHelper :: new_from_rect ( ui, "delete-column-button" , button_rect) ;
379
-
380
- let cur_img_size = helper. scale_1d_pos ( img_size) ;
381
-
382
- let animation_rect = helper. get_animation_rect ( ) ;
383
- let animation_resp = helper. take_animation_response ( ) ;
384
- if allocation_response. union ( animation_resp. clone ( ) ) . hovered ( ) {
385
- img. paint_at ( ui, animation_rect. shrink ( ( max_size - cur_img_size) / 2.0 ) ) ;
386
- }
387
-
388
- animation_resp
389
- }
390
-
391
- fn title (
392
- ui : & mut egui:: Ui ,
393
- title_name : String ,
394
- titlebar_rect : egui:: Rect ,
395
- icon_width : f32 ,
396
- padding : f32 ,
397
- ) {
398
- let painter = ui. painter_at ( titlebar_rect) ;
399
-
400
- let font = egui:: FontId :: new (
401
- get_font_size ( ui. ctx ( ) , & NotedeckTextStyle :: Body ) ,
402
- egui:: FontFamily :: Name ( NamedFontFamily :: Bold . as_str ( ) . into ( ) ) ,
403
- ) ;
404
-
405
- let max_title_width = titlebar_rect. width ( ) - icon_width - padding * 2. ;
406
- let title_galley =
407
- ui. fonts ( |f| f. layout ( title_name, font, ui. visuals ( ) . text_color ( ) , max_title_width) ) ;
408
-
409
- let pos = {
410
- let titlebar_center = titlebar_rect. center ( ) ;
411
- let text_height = title_galley. rect . height ( ) ;
412
-
413
- let galley_pos_x = titlebar_rect. left ( ) + padding;
414
- let galley_pos_y = titlebar_center. y - ( text_height / 2. ) ;
415
- pos2 ( galley_pos_x, galley_pos_y)
416
- } ;
417
-
418
- painter. galley ( pos, title_galley, Color32 :: WHITE ) ;
419
- }
420
-
421
- enum TitleResponse {
422
- RemoveColumn ,
423
- }
0 commit comments