1
1
2
2
#include <stdio.h>
3
3
#include <LCUI.h>
4
+ #include <LCDesign.h>
5
+ #include <LCUI/timer.h>
4
6
#include <LCUI/gui/widget.h>
5
7
#include <LCUI/gui/widget/textedit.h>
6
- #include <LCDesign.h>
7
8
#include "frame.h"
8
9
#include "router.h"
9
10
@@ -23,14 +24,16 @@ typedef struct FrameViewRec_ {
23
24
static size_t frame_id_count = 0 ;
24
25
static LCUI_WidgetPrototype frame_proto ;
25
26
26
- static void BrowserView_UpdateNavbar (LCUI_Widget w )
27
+ static void BrowserView_UpdateNavbar (void * arg )
27
28
{
28
29
size_t index ;
29
30
size_t length ;
30
31
router_history_t * history ;
31
32
32
33
FrameView self ;
34
+ LCUI_Widget w ;
33
35
36
+ w = arg ;
34
37
self = Widget_GetData (w , frame_proto );
35
38
history = router_get_history (self -> router );
36
39
index = router_history_get_index (history );
@@ -47,6 +50,30 @@ static void BrowserView_UpdateNavbar(LCUI_Widget w)
47
50
}
48
51
}
49
52
53
+ static void FrameView_OnBtnBackClick (LCUI_Widget w , LCUI_WidgetEvent e ,
54
+ void * arg )
55
+ {
56
+ router_back (((FrameView )e -> data )-> router );
57
+ }
58
+
59
+ static void FrameView_OnBtnForwardClick (LCUI_Widget w , LCUI_WidgetEvent e ,
60
+ void * arg )
61
+ {
62
+ router_forward (((FrameView )e -> data )-> router );
63
+ }
64
+
65
+ static void FrameView_OnBtnHomeClick (LCUI_Widget w , LCUI_WidgetEvent e ,
66
+ void * arg )
67
+ {
68
+ router_location_t * location ;
69
+ FrameView self ;
70
+
71
+ self = e -> data ;
72
+ location = router_location_create (NULL , "/welcome" );
73
+ router_push (self -> router , location );
74
+ router_location_destroy (location );
75
+ }
76
+
50
77
static void FrameView_OnRouteUpdate (void * arg , const router_route_t * to ,
51
78
const router_route_t * from )
52
79
{
@@ -58,7 +85,7 @@ static void FrameView_OnRouteUpdate(void *arg, const router_route_t *to,
58
85
path = router_route_get_full_path (to );
59
86
TextEdit_SetText (self -> input , path );
60
87
}
61
- BrowserView_UpdateNavbar ( arg );
88
+ LCUI_SetTimeout ( 0 , BrowserView_UpdateNavbar , arg );
62
89
}
63
90
64
91
static void FrameView_OnInit (LCUI_Widget w )
@@ -95,6 +122,12 @@ static void FrameView_OnInit(LCUI_Widget w)
95
122
Icon_SetName (self -> btn_forward , "arrow-right" );
96
123
Icon_SetName (self -> btn_refresh , "refresh" );
97
124
Icon_SetName (self -> btn_home , "home-outline" );
125
+ Widget_BindEvent (self -> btn_back , "click" , FrameView_OnBtnBackClick ,
126
+ self , NULL );
127
+ Widget_BindEvent (self -> btn_forward , "click" , FrameView_OnBtnForwardClick ,
128
+ self , NULL );
129
+ Widget_BindEvent (self -> btn_home , "click" , FrameView_OnBtnHomeClick ,
130
+ self , NULL );
98
131
Widget_Append (w , self -> navbar );
99
132
Widget_Append (w , self -> content );
100
133
FrameView_OnRouteUpdate (w , router_get_current_route (self -> router ),
0 commit comments