Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Nov 26, 2023
1 parent b1c5d92 commit 03ea5c2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This library provides a generic diffing engine for user-interfaces and other rea

This crate is inspired by Jetpack Compose, [xilem](https://github.com/linebender/xilem), and [dioxus](https://github.com/dioxuslabs/dioxus).

## Web

```rust
#[derive(PartialEq)]
struct Counter {
Expand All @@ -43,17 +43,34 @@ impl View for Counter {

(
"High five count: {count}",
div("Up High").on_click(|| count += 1),
div("Down low").on_click(|| count -= 1),
button("Up High").on_click(|| count += 1),
button("Down low").on_click(|| count -= 1),
)
}
}
```

## Web
```rust
fn main() {
concoct::web::run(Counter { initial_value: 0 })
}
```

## Native (WebView)
```rust
fn main() {
concoct::webview::run(Counter { initial_value: 0 })
}
```

## Native (Wgpu) - Planned
```rust
fn main() {
concoct::native::run(Counter { initial_value: 0 })
}
```

## Installation
This crate currently requires rust nightly.
You can install concoct by running:
Expand Down
22 changes: 17 additions & 5 deletions src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,27 @@ impl WebViewContext {
}
}

pub fn div<C>(child: C) -> Html<WebHtml, C> {
Html::new(WebHtml {}, child)
pub fn div<C>(child: C) -> Html<WebViewHtml, C> {
Html::new(WebViewHtml {}, child)
}

#[derive(PartialEq, Eq)]
pub struct WebHtml {}
pub struct WebViewHtml {}

impl HtmlPlatform for WebHtml {
fn html(&mut self, html: &mut Builder) -> impl IntoView {}
impl HtmlPlatform for WebViewHtml {
fn html(&mut self, html: &mut Builder) -> impl IntoView {
WebViewContext::current()
.inner
.borrow()
.web_view
.evaluate_script(&format!(
r#"
var element = document.createElement("div");
document.body.appendChild(element);
"#
))
.unwrap();
}
}

pub struct WebView;
Expand Down

0 comments on commit 03ea5c2

Please sign in to comment.