44#include <LCUI/input.h>
55#include <LCUI/timer.h>
66#include <LCUI/gui/widget.h>
7+ #include <LCUI/gui/widget/textview.h>
78#include <LCUI/gui/widget/textedit.h>
89#include <LCUI/gui/widget/scrollbar.h>
910#include "frame.h"
@@ -18,11 +19,12 @@ typedef struct FrameViewRec_ {
1819 LCUI_Widget btn_forward ;
1920 LCUI_Widget btn_refresh ;
2021 LCUI_Widget btn_home ;
22+ LCUI_Widget btn_menu ;
2123 LCUI_Widget input ;
2224 LCUI_Widget content ;
2325 LCUI_Widget client ;
2426 LCUI_Widget scrollbar ;
25- LCUI_Widget hscrollbar ;
27+ LCUI_Widget dropdown ;
2628} FrameViewRec , * FrameView ;
2729
2830static size_t frame_id_count = 0 ;
@@ -131,6 +133,61 @@ static void FrameView_OnRouteUpdate(void *arg, const router_route_t *to,
131133 Widget_TriggerEvent (arg , & e , NULL );
132134}
133135
136+ static void FrameView_OnCommandOpenNewTab (LCUI_Widget w , LCUI_WidgetEvent e ,
137+ void * arg )
138+ {
139+ LCUI_WidgetEventRec ev ;
140+
141+ LCUI_InitWidgetEvent (& ev , "command.OpenNewTab" );
142+ Widget_TriggerEvent (e -> data , & ev , NULL );
143+ }
144+
145+ static void FrameView_OnCommandQuit (LCUI_Widget w , LCUI_WidgetEvent e ,
146+ void * arg )
147+ {
148+ LCUI_WidgetEventRec ev ;
149+
150+ LCUI_InitWidgetEvent (& ev , "command.Quit" );
151+ Widget_TriggerEvent (e -> data , & ev , NULL );
152+ }
153+
154+ static void FrameView_OnOpenHelp (LCUI_Widget w , LCUI_WidgetEvent e , void * arg )
155+ {
156+ FrameView_Load (e -> data , "/help" );
157+ }
158+
159+ static void FrameView_InitDropdownMenu (LCUI_Widget w )
160+ {
161+ FrameView self ;
162+ LCUI_Widget item ;
163+
164+ self = Widget_GetData (w , frame_proto );
165+ Dropdown_BindTarget (self -> dropdown , self -> btn_menu );
166+ Dropdown_SetPosition (self -> dropdown , SV_BOTTOM_RIGHT );
167+
168+ item = LCUIWidget_New ("text" );
169+ Widget_AddClass (item , "dropdown-item" );
170+ TextView_SetTextW (item , L"Open New Tab" );
171+ Widget_BindEvent (item , "click" , FrameView_OnCommandOpenNewTab , w , NULL );
172+ Widget_Append (self -> dropdown , item );
173+
174+ item = LCUIWidget_New ("text" );
175+ Widget_AddClass (item , "dropdown-item" );
176+ TextView_SetTextW (item , L"Help" );
177+ Widget_BindEvent (item , "click" , FrameView_OnOpenHelp , w , NULL );
178+ Widget_Append (self -> dropdown , item );
179+
180+ item = LCUIWidget_New (NULL );
181+ Widget_AddClass (item , "dropdown-divider" );
182+ Widget_Append (self -> dropdown , item );
183+
184+ item = LCUIWidget_New ("text" );
185+ Widget_AddClass (item , "dropdown-item" );
186+ TextView_SetTextW (item , L"Quit" );
187+ Widget_BindEvent (item , "click" , FrameView_OnCommandQuit , w , NULL );
188+ Widget_Append (self -> dropdown , item );
189+ }
190+
134191static void FrameView_OnInit (LCUI_Widget w )
135192{
136193 FrameView self ;
@@ -150,6 +207,8 @@ static void FrameView_OnInit(LCUI_Widget w)
150207 self -> content = LCUIWidget_New ("router-view" );
151208 self -> client = LCUIWidget_New (NULL );
152209 self -> scrollbar = LCUIWidget_New ("scrollbar" );
210+ self -> btn_menu = LCUIWidget_New ("icon" );
211+ self -> dropdown = LCUIWidget_New ("dropdown-menu" );
153212 ScrollBar_BindTarget (self -> scrollbar , self -> content );
154213 Widget_SetAttribute (w , "router" , router_name );
155214 Widget_AddClass (w , "v-frame" );
@@ -158,6 +217,7 @@ static void FrameView_OnInit(LCUI_Widget w)
158217 Widget_AddClass (self -> btn_forward , "c-navbar__btn" );
159218 Widget_AddClass (self -> btn_home , "c-navbar__btn" );
160219 Widget_AddClass (self -> btn_refresh , "c-navbar__btn" );
220+ Widget_AddClass (self -> btn_menu , "c-navbar__btn" );
161221 Widget_AddClass (self -> input , "c-navbar__input" );
162222 Widget_AddClass (self -> content , "v-frame__content" );
163223 Widget_AddClass (self -> client , "v-frame__client" );
@@ -166,8 +226,10 @@ static void FrameView_OnInit(LCUI_Widget w)
166226 Widget_Append (self -> navbar , self -> btn_refresh );
167227 Widget_Append (self -> navbar , self -> btn_home );
168228 Widget_Append (self -> navbar , self -> input );
229+ Widget_Append (self -> navbar , self -> btn_menu );
169230 Widget_Append (self -> client , self -> content );
170231 Widget_Append (self -> client , self -> scrollbar );
232+ Icon_SetName (self -> btn_menu , "menu" );
171233 Icon_SetName (self -> btn_back , "arrow-left" );
172234 Icon_SetName (self -> btn_forward , "arrow-right" );
173235 Icon_SetName (self -> btn_refresh , "refresh" );
@@ -180,10 +242,13 @@ static void FrameView_OnInit(LCUI_Widget w)
180242 self , NULL );
181243 Widget_BindEvent (self -> btn_refresh , "click" ,
182244 FrameView_OnBtnRefreshClick , self , NULL );
183- Widget_BindEvent (self -> input , "keydown" , FrameView_OnInputKeydown , self , NULL );
245+ Widget_BindEvent (self -> input , "keydown" , FrameView_OnInputKeydown , self ,
246+ NULL );
184247 Widget_Append (w , self -> navbar );
185248 Widget_Append (w , self -> client );
249+ Widget_Append (w , self -> dropdown );
186250 Widget_SetId (w , router_name );
251+ FrameView_InitDropdownMenu (w );
187252 FrameView_OnRouteUpdate (w , router_get_current_route (self -> router ),
188253 NULL );
189254}
0 commit comments