Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
LegitCamper committed Oct 1, 2024
1 parent 55f335f commit 4a84b4d
Showing 1 changed file with 23 additions and 50 deletions.
73 changes: 23 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,33 @@
<img src="https://github.com/LegitCamper/icy_browser/blob/main/assets/basic_browser.png?raw=true" width=50%>

``` Rust
use iced::{Sandbox, Settings, Theme};
use iced_aw::BOOTSTRAP_FONT_BYTES;
use iced::{Settings, Task, Theme};
use icy_browser::{get_fonts, BasicBrowser, Bookmark, Message};

use icy_browser::{widgets, BrowserWidget, Ultralight};
fn run() -> (BasicBrowser, Task<Message>) {
(
BasicBrowser::new_basic()
.with_tab_bar()
.with_nav_bar()
.with_bookmark_bar(vec![Bookmark::new(
"https://www.rust-lang.org",
"rust-lang.org",
)])
.build(),
Task::none(),
)
}

fn main() -> Result<(), iced::Error> {
// This imports `icons` for widgets
let bootstrap_font = BOOTSTRAP_FONT_BYTES.into();
fn main() -> iced::Result {
let settings = Settings {
fonts: vec![bootstrap_font],
fonts: get_fonts(),
..Default::default()
};
Browser::run(settings)
}

struct Browser {
widgets: BrowserWidget<Ultralight>,
iced::application("Basic Browser", BasicBrowser::update, BasicBrowser::view)
.subscription(BasicBrowser::subscription)
.settings(settings)
.theme(|_| Theme::Dark)
.run_with(run)
}

#[derive(Debug, Clone)]
pub enum Message {
BrowserWidget(widgets::Message),
}

impl Sandbox for Browser {
type Message = Message;

fn new() -> Self {
let widgets = BrowserWidget::new_with_ultralight()
.with_tab_bar()
.with_nav_bar()
.with_browsesr_view()
.build();

Self { widgets }
}

fn title(&self) -> String {
String::from("Basic Browser")
}

fn theme(&self) -> Theme {
Theme::Dark
}

fn update(&mut self, message: Self::Message) {
match message {
Message::BrowserWidget(msg) => {
self.widgets.update(msg);
}
}
}

fn view(&self) -> iced::Element<'_, Self::Message> {
self.widgets.view().map(Message::BrowserWidget)
}
}```
```

0 comments on commit 4a84b4d

Please sign in to comment.