Skip to content

Commit

Permalink
Update to latest concoct
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Dec 13, 2023
1 parent 0b6f677 commit fb85c9f
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 30 deletions.
13 changes: 11 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kurbo = "0.9.5"
tokio = { version = "1.32.0", features = ["full"] }
slotmap = "1.0.7"
winit = { version = "0.28.1" }
concoct = { git = "https://github.com/concoct-rs/concoct" }
concoct = { git = "https://github.com/concoct-rs/concoct", features = ["full"] }
viewbuilder-macros = { path = "macros" }
web-sys = { version = "0.3.66", optional = true, features = ["Document", "HtmlElement", "Text", "Window"] }

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct App {
impl Object for App {}

impl Slot<window::Resized> for App {
fn handle(&mut self, _cx: Context<Self>, msg: window::Resized) {
fn handle(&mut self, _cx: Handle<Self>, msg: window::Resized) {
if msg.width != self.size.width {
self.width_text.send(format!("Width: {}", msg.width).into());
self.size.width = msg.width
Expand Down
12 changes: 6 additions & 6 deletions examples/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use concoct::{Context, Handle, Object, Slot};
use concoct::{ Handle, Object, Slot};
use viewbuilder::native::{
view::{LinearLayout, Text},
window, Window,
Expand All @@ -14,7 +14,7 @@ struct App {
impl Object for App {}

impl Slot<window::Resized> for App {
fn handle(&mut self, _cx: Context<Self>, msg: window::Resized) {
fn handle(&mut self, _cx: Handle<Self>, msg: window::Resized) {
if msg.width != self.size.width {
self.width_text.send(format!("Width: {}", msg.width).into());
self.size.width = msg.width
Expand All @@ -30,16 +30,16 @@ impl Slot<window::Resized> for App {

#[viewbuilder::main]
fn main() {
let width_text = Text::default().spawn();
let height_text = Text::default().spawn();
let width_text = Text::default().start();
let height_text = Text::default().start();

let app = App {
width_text: width_text.clone(),
height_text: height_text.clone(),
size: PhysicalSize::default(),
}
.spawn();
.start();

let window = Window::new(LinearLayout::new((width_text, height_text))).spawn();
let window = Window::new(LinearLayout::new((width_text, height_text))).start();
window.bind(&app);
}
2 changes: 1 addition & 1 deletion src/native/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl<V> Object for Element<V> {}
pub struct LayoutMessage;

impl<V> Slot<LayoutMessage> for Element<V> {
fn handle(&mut self, _handle: concoct::Context<Self>, _msg: LayoutMessage) {
fn handle(&mut self, _handle: concoct::Handle<Self>, _msg: LayoutMessage) {
todo!()
}
}
2 changes: 1 addition & 1 deletion src/native/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use concoct::{Runtime, RuntimeGuard, SlotHandle};
use concoct::{Runtime, SlotHandle, rt::RuntimeGuard};
use std::{cell::RefCell, collections::HashMap, rc::Rc};
use window::WindowMessage;
use winit::{
Expand Down
2 changes: 1 addition & 1 deletion src/native/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ where
type View = V;

fn into_view(self) -> Handle<Self::View> {
self.spawn()
self.start()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/native/view/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Object for Text {}
impl View for Text {}

impl Slot<Rc<str>> for Text {
fn handle(&mut self, _handle: concoct::Context<Self>, msg: Rc<str>) {
fn handle(&mut self, _handle: concoct::Handle<Self>, msg: Rc<str>) {
dbg!(msg);
}
}
10 changes: 5 additions & 5 deletions src/native/window.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::{view::IntoView, UserInterface};
use concoct::{Context, Handle, Object, Signal, Slot};
use concoct::{ Handle, Object, Signal, Slot};
use std::ops::Deref;
use winit::dpi::PhysicalSize;

pub struct Window<V> {
view: Handle<V>,
cx: Option<Context<Self>>,
cx: Option<Handle<Self>>,
}

impl<V> Window<V> {
Expand All @@ -18,7 +18,7 @@ impl<V> Window<V> {
}

impl<V: 'static> Object for Window<V> {
fn start(&mut self, cx: Context<Self>) {
fn started(&mut self, cx: Handle<Self>) {
UserInterface::current()
.inner
.borrow_mut()
Expand All @@ -45,15 +45,15 @@ impl<V: 'static> Signal<Resized> for Window<V> {}
pub struct SetSize {}

impl<V: 'static> Slot<SetSize> for Window<V> {
fn handle(&mut self, _handle: Context<Self>, _msg: SetSize) {}
fn handle(&mut self, _handle: Handle<Self>, _msg: SetSize) {}
}

pub enum WindowMessage {
Resized(PhysicalSize<u32>),
}

impl<V: 'static> Slot<WindowMessage> for Window<V> {
fn handle(&mut self, handle: Context<Self>, msg: WindowMessage) {
fn handle(&mut self, handle: Handle<Self>, msg: WindowMessage) {
match msg {
WindowMessage::Resized(size) => handle.emit(Resized(size)),
}
Expand Down
6 changes: 3 additions & 3 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ where
type View = V;

fn into_view(self) -> Handle<Self::View> {
self.spawn()
self.start()
}
}

Expand Down Expand Up @@ -111,7 +111,7 @@ impl View for Element {
pub struct AppendChild<V>(pub Handle<V>);

impl<V: View + 'static> Slot<AppendChild<V>> for Element {
fn handle(&mut self, _handle: concoct::Context<Self>, msg: AppendChild<V>) {
fn handle(&mut self, _handle: concoct::Handle<Self>, msg: AppendChild<V>) {
self.element.append_child(msg.0.borrow().node()).unwrap();
}
}
Expand Down Expand Up @@ -148,5 +148,5 @@ impl View for Text {
impl Object for Text {}

impl Slot<String> for Text {
fn handle(&mut self, _handle: concoct::Context<Self>, _msg: String) {}
fn handle(&mut self, _handle: concoct::Handle<Self>, _msg: String) {}
}
2 changes: 1 addition & 1 deletion web-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"

[dependencies]
viewbuilder = { path = "../", features = ["full"] }
concoct = { git = "https://github.com/concoct-rs/concoct" }
concoct = { git = "https://github.com/concoct-rs/concoct", features = ["full"] }
14 changes: 7 additions & 7 deletions web-examples/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct Counter {
impl Object for Counter {}

impl Slot<Message> for Counter {
fn handle(&mut self, _cx: concoct::Context<Self>, msg: Message) {
fn handle(&mut self, _cx: concoct::Handle<Self>, msg: Message) {
match msg {
Message::Increment => self.value += 1,
Message::Decrement => self.value -= 1,
Expand All @@ -32,31 +32,31 @@ struct CounterButton {
impl Object for CounterButton {}

impl Slot<web::MouseEvent> for CounterButton {
fn handle(&mut self, _cx: concoct::Context<Self>, _msg: web::MouseEvent) {
fn handle(&mut self, _cx: concoct::Handle<Self>, _msg: web::MouseEvent) {
self.counter.send(self.msg);
}
}

#[viewbuilder::main]
fn main() {
let text = Text::new("0").spawn();
let text = Text::new("0").start();

let counter = Counter {
value: 0,
text: text.clone(),
}
.spawn();
.start();

let increment_button = CounterButton {
msg: Message::Increment,
counter: counter.clone(),
}
.spawn();
.start();
let decrement_button = CounterButton {
msg: Message::Decrement,
counter,
}
.spawn();
.start();

Element::builder()
.child((
Expand All @@ -71,5 +71,5 @@ fn main() {
.build(),
))
.build()
.spawn();
.start();
}

0 comments on commit fb85c9f

Please sign in to comment.