Skip to content

Commit

Permalink
moving widgets from components
Browse files Browse the repository at this point in the history
  • Loading branch information
LegitCamper committed Aug 12, 2024
1 parent 801c85b commit 459e388
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 314 deletions.
72 changes: 41 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ panic = "abort"
rustflags = ["-Z", "threads=8"]

[dependencies]
iced = { version = "0.12.1", features = ["advanced", "image", "tokio", "lazy"] }
iced = { version = "0.12.1", features = ["advanced", "image", "tokio", "lazy"]}
iced_aw = { version = "0.9.3", features = ["tab_bar", "icons"] }
iced_on_focus_widget = "0.1.0"
# reqwest = { version = "0.12.5", features = ["blocking"] }
smol_str = "0.2.2"
ul-next = { version = "0.2.0", optional = true }
Expand Down
46 changes: 38 additions & 8 deletions examples/basic_browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use iced::{executor, Command, Subscription};
use iced::{widget::column, Application, Settings, Theme};
use iced_aw::BOOTSTRAP_FONT_BYTES;

use icy_browser::{browser_view, nav_bar, tab_bar, State, Ultralight};
use icy_browser::{browser_view, nav_bar, tab_bar, BrowserView, NavBar, State, TabBar, Ultralight};

use std::borrow::Borrow;
use std::time::Duration;
Expand All @@ -18,10 +18,18 @@ fn main() -> Result<(), iced::Error> {
Browser::run(settings)
}

struct Browser(State<Ultralight>);
struct Browser {
state: State<Ultralight>,
tab_bar: TabBar<Ultralight>,
nav_bar: NavBar<Ultralight>,
browser_view: BrowserView<Ultralight>,
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone)]
pub enum Message {
TabBar(tab_bar::Message),
NavBar(nav_bar::Message),
BrowserView(browser_view::Message),
DoWork,
}

Expand All @@ -32,7 +40,20 @@ impl Application for Browser {
type Theme = Theme;

fn new(_flags: Self::Flags) -> (Self, Command<Message>) {
(Self(State::new_ultralight()), Command::none())
let state = State::new_ultralight();
let tab_bar = tab_bar(state.clone());
let nav_bar = nav_bar(state.clone());
let browser_view = browser_view(state.clone());

(
Self {
state,
tab_bar,
nav_bar,
browser_view,
},
Command::none(),
)
}

fn title(&self) -> String {
Expand All @@ -49,15 +70,24 @@ impl Application for Browser {

fn update(&mut self, message: Self::Message) -> Command<Message> {
match message {
Message::DoWork => self.0.borrow().do_work(),
Message::DoWork => self.state.borrow().do_work(),
Message::NavBar(nav_bar_message) => match self.nav_bar.update(nav_bar_message) {
nav_bar::Action::None => {}
},
Message::TabBar(tab_bar_message) => match self.tab_bar.update(tab_bar_message) {
tab_bar::Action::None => {}
},
Message::BrowserView(browser_view) => match self.browser_view.update(browser_view) {
browser_view::Action::None => {}
},
}
Command::none()
}

fn view(&self) -> iced::Element<'_, Self::Message> {
let tab_bar = tab_bar(self.0.clone());
let nav_bar = nav_bar(self.0.clone());
let browser_view = browser_view(self.0.clone());
let tab_bar = self.tab_bar.view().map(Message::TabBar);
let nav_bar = self.nav_bar.view().map(Message::NavBar);
let browser_view = self.browser_view.view().map(Message::BrowserView);

column!(tab_bar, nav_bar, browser_view).into()
}
Expand Down
Loading

0 comments on commit 459e388

Please sign in to comment.