Skip to content

Commit

Permalink
Fix borrow issues
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Dec 15, 2023
1 parent aba2cbe commit 67f9d1c
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 107 deletions.
2 changes: 0 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 @@ -14,7 +14,7 @@ full = ["Window"]
[dependencies]
tokio = { version = "1.32.0", features = ["full"], optional = true }
winit = { version = "0.28.1", optional = true }
concoct = { version = "0.15.0", features = ["full"] }
concoct = { path = "../concoct", features = ["full"] }

[package.metadata.docs.rs]
features = ["full"]
Expand Down
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,29 @@ A cross-platform user interface framework for Rust.
Viewbuilder is a moduler GUI library that can be used as an entire framework, or with individual parts.

```rust
use concoct::{Handle, Object, Slot};
use viewbuilder::native::{window, Window};
use winit::dpi::PhysicalSize;
use concoct::{Context, Object};
use viewbuilder::{event_loop::WindowEvent, EventLoop, Window};

struct App;

impl Object for App {}

impl Slot<window::ResizedEvent> for App {
fn update(&mut self, _cx: Handle<Self>, msg: window::ResizedEvent) {
dbg!(msg);
impl App {
pub fn handle(cx: &mut Context<Self>, event: WindowEvent) {
dbg!(event);
}
}

#[viewbuilder::main]
fn main() {
let app = App.start();
impl Object for App {}

let window_a = Window::builder().title("Window A").build().start();
window_a.bind(&app);
fn main() {
let event_loop = EventLoop::<()>::new().start();

let window_b = Window::builder().title("Window B").build().start();
window_b.bind(&app);
let window = Window::new().start();
Window::insert(&mut window.cx(), &event_loop);

window_a.map(&window_b, |&window::ResizedEvent(size)| {
window::SetSizeMessage(size)
});
let app = App.start();
window.bind(&app, App::handle);

window_a.send(window::SetSizeMessage(PhysicalSize::new(500, 500)));
EventLoop::run(event_loop);
}
```

Expand Down
23 changes: 16 additions & 7 deletions examples/window.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
use concoct::Object;
use viewbuilder::{EventLoop, Window};
use concoct::{Context, Object};
use viewbuilder::{event_loop::WindowEvent, EventLoop, Window};

struct App;

impl App {
pub fn handle(cx: &mut Context<Self>, event: WindowEvent) {
dbg!(event);
}
}

impl Object for App {}

fn main() {
let event_loop = EventLoop::<()>::new().start();

let a = Window::new().start();
Window::insert(&mut a.cx(), &event_loop);
let window = Window::new().start();
Window::insert(&mut window.cx(), &event_loop);

a.listen(|msg| {
dbg!(msg);
});
let app = App.start();
window.bind(&app, App::handle);

EventLoop::run(event_loop);
}
168 changes: 90 additions & 78 deletions src/event_loop.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
use concoct::{Handle, Object, Signal};
use std::mem;
use winit::{
dpi::PhysicalSize,
dpi::{PhysicalPosition, PhysicalSize},
event::{DeviceEvent, DeviceId, Event as RawEvent, StartCause, WindowEvent as RawWindowEvent},
event_loop::EventLoopWindowTarget,
window::WindowId,
};

#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq)]
pub enum WindowEvent {
CursorMoved {
device_id: DeviceId,
position: PhysicalPosition<f64>,
},
CursorEntered {
device_id: DeviceId,
},
CursorLeft {
device_id: DeviceId,
},
Resized(PhysicalSize<u32>),
Focused(bool),
Occluded(bool),
Expand Down Expand Up @@ -68,83 +78,85 @@ impl<E: 'static> EventLoop<E> {
let event = match event {
RawEvent::UserEvent(custom) => Event::Custom(custom),
RawEvent::NewEvents(start_cause) => Event::NewEvents(start_cause),
RawEvent::WindowEvent { window_id, event } => match event {
RawWindowEvent::AxisMotion {
device_id: _,
axis: _,
value: _,
} => todo!(),
RawWindowEvent::Resized(size) => Event::Window {
window_id,
event: WindowEvent::Resized(size),
},
RawWindowEvent::Moved(_) => todo!(),
RawWindowEvent::CloseRequested => todo!(),
RawWindowEvent::Destroyed => Event::Window {
window_id,
event: WindowEvent::Destroyed,
},
RawWindowEvent::DroppedFile(_) => todo!(),
RawWindowEvent::HoveredFile(_) => todo!(),
RawWindowEvent::HoveredFileCancelled => todo!(),
RawWindowEvent::ReceivedCharacter(_) => todo!(),
RawWindowEvent::Focused(focused) => Event::Window {
window_id,
event: WindowEvent::Focused(focused),
},
RawWindowEvent::KeyboardInput {
device_id: _,
input: _,
is_synthetic: _,
} => todo!(),
RawWindowEvent::ModifiersChanged(_) => todo!(),
RawWindowEvent::Ime(_) => todo!(),
RawWindowEvent::CursorMoved {
device_id: _,
position: _,
..
} => todo!(),
RawWindowEvent::CursorEntered { device_id: _ } => todo!(),
RawWindowEvent::CursorLeft { device_id: _ } => todo!(),
RawWindowEvent::MouseWheel {
device_id: _,
delta: _,
phase: _,
..
} => todo!(),
RawWindowEvent::MouseInput {
device_id: _,
state: _,
button: _,
..
} => todo!(),
RawWindowEvent::TouchpadMagnify {
device_id: _,
delta: _,
phase: _,
} => todo!(),
RawWindowEvent::SmartMagnify { device_id: _ } => todo!(),
RawWindowEvent::TouchpadRotate {
device_id: _,
delta: _,
phase: _,
} => todo!(),
RawWindowEvent::TouchpadPressure {
device_id: _,
pressure: _,
stage: _,
} => todo!(),
RawWindowEvent::Touch(_) => todo!(),
RawWindowEvent::ScaleFactorChanged {
scale_factor: _,
new_inner_size: _,
} => todo!(),
RawWindowEvent::ThemeChanged(_) => todo!(),
RawWindowEvent::Occluded(occluded) => Event::Window {
RawEvent::WindowEvent { window_id, event } => {
let window_event = match event {
RawWindowEvent::AxisMotion {
device_id: _,
axis: _,
value: _,
} => todo!(),
RawWindowEvent::Resized(size) => WindowEvent::Resized(size),
RawWindowEvent::Moved(_) => todo!(),
RawWindowEvent::CloseRequested => todo!(),
RawWindowEvent::Destroyed => WindowEvent::Destroyed,
RawWindowEvent::DroppedFile(_) => todo!(),
RawWindowEvent::HoveredFile(_) => todo!(),
RawWindowEvent::HoveredFileCancelled => todo!(),
RawWindowEvent::ReceivedCharacter(_) => todo!(),
RawWindowEvent::Focused(focused) => WindowEvent::Focused(focused),

RawWindowEvent::KeyboardInput {
device_id: _,
input: _,
is_synthetic: _,
} => todo!(),
RawWindowEvent::ModifiersChanged(_) => todo!(),
RawWindowEvent::Ime(_) => todo!(),
RawWindowEvent::CursorMoved {
device_id,
position,
..
} => WindowEvent::CursorMoved {
device_id,
position,
},
RawWindowEvent::CursorEntered { device_id } => {
WindowEvent::CursorEntered { device_id }
}
RawWindowEvent::CursorLeft { device_id } => {
WindowEvent::CursorLeft { device_id }
}
RawWindowEvent::MouseWheel {
device_id: _,
delta: _,
phase: _,
..
} => todo!(),
RawWindowEvent::MouseInput {
device_id: _,
state: _,
button: _,
..
} => todo!(),
RawWindowEvent::TouchpadMagnify {
device_id: _,
delta: _,
phase: _,
} => todo!(),
RawWindowEvent::SmartMagnify { device_id: _ } => todo!(),
RawWindowEvent::TouchpadRotate {
device_id: _,
delta: _,
phase: _,
} => todo!(),
RawWindowEvent::TouchpadPressure {
device_id: _,
pressure: _,
stage: _,
} => todo!(),
RawWindowEvent::Touch(_) => todo!(),
RawWindowEvent::ScaleFactorChanged {
scale_factor: _,
new_inner_size: _,
} => todo!(),
RawWindowEvent::ThemeChanged(_) => todo!(),
RawWindowEvent::Occluded(occluded) => WindowEvent::Occluded(occluded),
};
Event::Window {
window_id,
event: WindowEvent::Occluded(occluded),
},
},
event: window_event,
}
}
RawEvent::DeviceEvent { device_id, event } => {
Event::DeviceEvent { device_id, event }
}
Expand Down
1 change: 1 addition & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum WindowState<E: 'static> {
},
}


pub struct Window<E: 'static> {
state: Option<WindowState<E>>,
}
Expand Down

0 comments on commit 67f9d1c

Please sign in to comment.