7474 on_close_view : Option < Box < dyn Fn ( ViewId ) -> Message > > ,
7575 on_create_view : Option < Box < dyn Fn ( ViewId ) -> Message > > ,
7676 on_url_change : Option < Box < dyn Fn ( ViewId , String ) -> Message > > ,
77- urls : Vec < ( ViewId , String ) > ,
77+ urls : HashMap < ViewId , String > ,
7878 on_title_change : Option < Box < dyn Fn ( ViewId , String ) -> Message > > ,
79- titles : Vec < ( ViewId , String ) > ,
79+ titles : HashMap < ViewId , String > ,
8080 on_copy : Option < Box < dyn Fn ( String ) -> Message > > ,
8181 action_mapper : Option < Arc < dyn Fn ( Action ) -> Message + Send + Sync > > ,
8282 inflight_images : usize ,
@@ -94,9 +94,9 @@ impl<Engine: engines::Engine + Default, Message: Send + Clone + 'static> Default
9494 on_close_view : None ,
9595 on_create_view : None ,
9696 on_url_change : None ,
97- urls : Vec :: new ( ) ,
97+ urls : HashMap :: new ( ) ,
9898 on_title_change : None ,
99- titles : Vec :: new ( ) ,
99+ titles : HashMap :: new ( ) ,
100100 on_copy : None ,
101101 action_mapper : None ,
102102 inflight_images : 0 ,
@@ -162,6 +162,13 @@ impl<Engine: engines::Engine + Default, Message: Send + Clone + 'static> WebView
162162 self
163163 }
164164
165+ /// Set the initial viewport size used before the first resize event.
166+ /// Defaults to 1920x1080.
167+ pub fn with_initial_size ( mut self , size : Size < u32 > ) -> Self {
168+ self . view_size = size;
169+ self
170+ }
171+
165172 /// Passes update to webview
166173 pub fn update ( & mut self , action : Action ) -> Task < Message > {
167174 let mut tasks = Vec :: new ( ) ;
@@ -189,8 +196,8 @@ impl<Engine: engines::Engine + Default, Message: Send + Clone + 'static> WebView
189196 match action {
190197 Action :: CloseView ( id) => {
191198 self . engine . remove_view ( id) ;
192- self . urls . retain ( |url| url . 0 != id) ;
193- self . titles . retain ( |title| title . 0 != id) ;
199+ self . urls . remove ( & id) ;
200+ self . titles . remove ( & id) ;
194201
195202 if let Some ( on_view_close) = & self . on_close_view {
196203 tasks. push ( Task :: done ( ( on_view_close) ( id) ) )
@@ -226,8 +233,8 @@ impl<Engine: engines::Engine + Default, Message: Send + Clone + 'static> WebView
226233 self . engine . new_view ( self . view_size , Some ( page_type) )
227234 } ;
228235
229- self . urls . push ( ( id, String :: new ( ) ) ) ;
230- self . titles . push ( ( id, String :: new ( ) ) ) ;
236+ self . urls . insert ( id, String :: new ( ) ) ;
237+ self . titles . insert ( id, String :: new ( ) ) ;
231238
232239 if let Some ( on_view_create) = & self . on_create_view {
233240 tasks. push ( Task :: done ( ( on_view_create) ( id) ) )
@@ -466,6 +473,16 @@ impl<Engine: engines::Engine + Default, Message: Send + Clone + 'static> WebView
466473 Task :: batch ( tasks)
467474 }
468475
476+ /// Get the URL for a specific view
477+ pub fn url_for ( & self , id : ViewId ) -> Option < & str > {
478+ self . urls . get ( & id) . map ( |s| s. as_str ( ) )
479+ }
480+
481+ /// Get the title for a specific view
482+ pub fn title_for ( & self , id : ViewId ) -> Option < & str > {
483+ self . titles . get ( & id) . map ( |s| s. as_str ( ) )
484+ }
485+
469486 /// Like a normal `view()` method in iced, but takes an id of the desired view
470487 pub fn view < ' a , T : ' a > ( & ' a self , id : usize ) -> Element < ' a , Action , T > {
471488 let content_height = self . engine . get_content_height ( id) ;
0 commit comments