mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 06:11:30 +11:00
Fix compile failures and add canvas positioning
This commit is contained in:
parent
7c6bdcc459
commit
9e25561edf
|
@ -232,8 +232,9 @@ fn add_event<T: 'static, E, F>(elrs: &EventLoopRunnerShared<T>, target: &impl IE
|
|||
|
||||
target.add_event_listener(move |event: E| {
|
||||
// Don't capture the event if the events loop has been destroyed
|
||||
if elrs.runner.borrow().control == ControlFlow::Exit {
|
||||
return;
|
||||
match &*elrs.runner.borrow() {
|
||||
Some(ref runner) if runner.control == ControlFlow::Exit => return,
|
||||
_ => ()
|
||||
}
|
||||
|
||||
event.prevent_default();
|
||||
|
@ -248,7 +249,7 @@ impl<T> ELRShared<T> {
|
|||
fn set_listener(&self, event_handler: Box<dyn FnMut(Event<T>, &mut ControlFlow)>) {
|
||||
*self.runner.borrow_mut() = Some(EventLoopRunner {
|
||||
control: ControlFlow::Poll,
|
||||
handling: false
|
||||
handling: false,
|
||||
event_handler
|
||||
});
|
||||
}
|
||||
|
@ -257,18 +258,20 @@ impl<T> ELRShared<T> {
|
|||
// TODO: handle event buffer
|
||||
pub fn send_event(&self, event: Event<T>) {
|
||||
let start_cause = StartCause::Poll; // TODO: this is obviously not right
|
||||
self.handle_start(StartCause::Poll);
|
||||
self.handle_start(start_cause);
|
||||
self.handle_event(event);
|
||||
self.handle_event(Event::EventsCleared);
|
||||
}
|
||||
|
||||
fn handle_start(&self, start: StartCause) {
|
||||
let is_handling = if Some(ref runner) = *self.runner.borrow() {
|
||||
let is_handling = if let Some(ref runner) = *self.runner.borrow() {
|
||||
runner.handling
|
||||
} else {
|
||||
false
|
||||
};
|
||||
self.handle_event(Event::StartCause(is_handling));
|
||||
if is_handling {
|
||||
self.handle_event(Event::NewEvents(start));
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_event(&self, event: Event<T>) {
|
||||
|
|
|
@ -53,7 +53,8 @@ impl WindowId {
|
|||
pub struct Window {
|
||||
pub(crate) canvas: CanvasElement,
|
||||
pub(crate) redraw: Box<dyn Fn()>,
|
||||
previous_pointer: RefCell<&'static str>
|
||||
previous_pointer: RefCell<&'static str>,
|
||||
position: RefCell<LogicalPosition>,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
@ -79,7 +80,11 @@ impl Window {
|
|||
let window = Window {
|
||||
canvas,
|
||||
redraw,
|
||||
previous_pointer: RefCell::new("auto")
|
||||
previous_pointer: RefCell::new("auto"),
|
||||
position: RefCell::new(LogicalPosition {
|
||||
x: 0.0,
|
||||
y: 0.0
|
||||
})
|
||||
};
|
||||
|
||||
if let Some(dimensions) = attr.dimensions {
|
||||
|
@ -134,12 +139,17 @@ impl Window {
|
|||
}
|
||||
|
||||
pub fn get_inner_position(&self) -> Option<LogicalPosition> {
|
||||
// TODO
|
||||
None
|
||||
Some(*self.position.borrow())
|
||||
}
|
||||
|
||||
pub fn set_position(&self, _position: LogicalPosition) {
|
||||
// TODO: use CSS?
|
||||
pub fn set_position(&self, position: LogicalPosition) {
|
||||
*self.position.borrow_mut() = position;
|
||||
self.canvas.set_attribute("position", "fixed")
|
||||
.expect("Setting the position for the canvas");
|
||||
self.canvas.set_attribute("left", &position.x.to_string())
|
||||
.expect("Setting the position for the canvas");
|
||||
self.canvas.set_attribute("top", &position.y.to_string())
|
||||
.expect("Setting the position for the canvas");
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in a new issue