diff --git a/build.rs b/build.rs index e487560..c85e226 100644 --- a/build.rs +++ b/build.rs @@ -3,7 +3,7 @@ use std::fs::{self, DirEntry}; use std::path::Path; fn main() { - // ensure runtime resources exist + // ensure runtime resources exist - for examples & local tests #[cfg(feature = "ultralight-resources")] { let out = var("OUT_DIR").unwrap(); diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index 12f6a0f..b524bdb 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -98,7 +98,7 @@ impl Default for TabSelectionType { pub struct IcyBrowser { engine: Engine, home: Url, - nav_bar_state: NavBarState, + nav_bar_state: Option, command_window_state: CommandWindowState, with_tab_bar: bool, with_nav_bar: bool, @@ -108,16 +108,13 @@ pub struct IcyBrowser { view_size: Size, } -impl Default for IcyBrowser -where - Engine: BrowserEngine, -{ +impl Default for IcyBrowser { fn default() -> Self { let home = Url::parse(Self::HOME).unwrap(); Self { engine: Engine::new(), home, - nav_bar_state: NavBarState::new(), + nav_bar_state: None, command_window_state: CommandWindowState::new(), with_tab_bar: false, with_nav_bar: false, @@ -133,10 +130,7 @@ impl IcyBrowser { const HOME: &'static str = "https://google.com"; pub fn new() -> Self { - Self { - engine: Engine::new(), - ..Default::default() - } + Self::default() } pub fn with_homepage(mut self, homepage: &str) -> Self { @@ -151,6 +145,7 @@ impl IcyBrowser { pub fn with_nav_bar(mut self) -> Self { self.with_nav_bar = true; + self.nav_bar_state = Some(NavBarState::new()); self } @@ -242,7 +237,9 @@ impl IcyBrowser { TabSelectionType::Index(index) => self.engine.get_tabs().index_to_id(index), }; self.engine.get_tabs_mut().set_current_id(id); - self.nav_bar_state.0 = self.engine.get_tabs().get_current().url(); + if let Some(state) = self.nav_bar_state.as_mut() { + state.0 = self.engine.get_tabs().get_current().url(); + } Task::none() } Message::CloseCurrentTab => Task::done(Message::CloseTab(TabSelectionType::Id( @@ -259,11 +256,15 @@ impl IcyBrowser { TabSelectionType::Index(index) => self.engine.get_tabs().index_to_id(index), }; self.engine.get_tabs_mut().remove(id); - self.nav_bar_state.0 = self.engine.get_tabs().get_current().url(); + if let Some(state) = self.nav_bar_state.as_mut() { + state.0 = self.engine.get_tabs().get_current().url(); + } Task::none() } Message::CreateTab => { - self.nav_bar_state.0 = self.home.to_string(); + if let Some(state) = self.nav_bar_state.as_mut() { + state.0 = self.home.to_string(); + } let home = self.home.clone(); let bounds = self.view_size; let tab = self.engine.new_tab( @@ -279,12 +280,16 @@ impl IcyBrowser { } Message::GoBackward => { self.engine.go_back(); - self.nav_bar_state.0 = self.engine.get_tabs().get_current().url(); + if let Some(state) = self.nav_bar_state.as_mut() { + state.0 = self.engine.get_tabs().get_current().url(); + } Task::none() } Message::GoForward => { self.engine.go_forward(); - self.nav_bar_state.0 = self.engine.get_tabs().get_current().url(); + if let Some(state) = self.nav_bar_state.as_mut() { + state.0 = self.engine.get_tabs().get_current().url(); + } Task::none() } Message::Refresh => { @@ -300,11 +305,15 @@ impl IcyBrowser { Task::none() } Message::UpdateUrl => { - self.nav_bar_state.0 = self.engine.get_tabs().get_current().url(); + if let Some(state) = self.nav_bar_state.as_mut() { + state.0 = self.engine.get_tabs().get_current().url(); + } Task::none() } Message::UrlChanged(url) => { - self.nav_bar_state.0 = url; + if let Some(state) = self.nav_bar_state.as_mut() { + state.0 = url; + } Task::none() } Message::QueryChanged(query) => { @@ -385,8 +394,10 @@ impl IcyBrowser { column = column.push(tab_bar(self.engine.get_tabs())) } if self.with_nav_bar { - column = column - .push(hoverable(nav_bar(&self.nav_bar_state)).on_focus_change(Message::UpdateUrl)) + column = column.push( + hoverable(nav_bar(self.nav_bar_state.as_ref().unwrap())) + .on_focus_change(Message::UpdateUrl), + ) } if let Some(bookmarks) = self.bookmarks.as_ref() { column = column.push(bookmark_bar(bookmarks))