11
22#include <stdio.h>
33#include <LCUI.h>
4+ #include <LCDesign.h>
5+ #include <LCUI/timer.h>
46#include <LCUI/gui/widget.h>
57#include <LCUI/gui/widget/textedit.h>
6- #include <LCDesign.h>
78#include "frame.h"
89#include "router.h"
910
@@ -23,14 +24,16 @@ typedef struct FrameViewRec_ {
2324static size_t frame_id_count = 0 ;
2425static LCUI_WidgetPrototype frame_proto ;
2526
26- static void BrowserView_UpdateNavbar (LCUI_Widget w )
27+ static void BrowserView_UpdateNavbar (void * arg )
2728{
2829 size_t index ;
2930 size_t length ;
3031 router_history_t * history ;
3132
3233 FrameView self ;
34+ LCUI_Widget w ;
3335
36+ w = arg ;
3437 self = Widget_GetData (w , frame_proto );
3538 history = router_get_history (self -> router );
3639 index = router_history_get_index (history );
@@ -47,6 +50,30 @@ static void BrowserView_UpdateNavbar(LCUI_Widget w)
4750 }
4851}
4952
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+
5077static void FrameView_OnRouteUpdate (void * arg , const router_route_t * to ,
5178 const router_route_t * from )
5279{
@@ -58,7 +85,7 @@ static void FrameView_OnRouteUpdate(void *arg, const router_route_t *to,
5885 path = router_route_get_full_path (to );
5986 TextEdit_SetText (self -> input , path );
6087 }
61- BrowserView_UpdateNavbar ( arg );
88+ LCUI_SetTimeout ( 0 , BrowserView_UpdateNavbar , arg );
6289}
6390
6491static void FrameView_OnInit (LCUI_Widget w )
@@ -95,6 +122,12 @@ static void FrameView_OnInit(LCUI_Widget w)
95122 Icon_SetName (self -> btn_forward , "arrow-right" );
96123 Icon_SetName (self -> btn_refresh , "refresh" );
97124 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 );
98131 Widget_Append (w , self -> navbar );
99132 Widget_Append (w , self -> content );
100133 FrameView_OnRouteUpdate (w , router_get_current_route (self -> router ),
0 commit comments