Skip to content

Commit

Permalink
Merge 1c2fe38 into 1cd1d2c
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 authored Jul 15, 2024
2 parents 1cd1d2c + 1c2fe38 commit 2f7f19b
Show file tree
Hide file tree
Showing 23 changed files with 308 additions and 61 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ dioxus-router = { workspace = true }
itertools = "0.13.0"
home = "0.5.9"
dioxus-query = "0.5.1"
gilrs = "0.10.8"

[profile.release]
lto = true
Expand Down
1 change: 0 additions & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ torin = { workspace = true }
dioxus-core = { workspace = true }

accesskit = { workspace = true }
accesskit_winit = { workspace = true }
winit = { workspace = true }
freya-engine = { workspace = true }
freya-native-core = { workspace = true }
Expand Down
2 changes: 0 additions & 2 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
mod event_messages;
mod layers;
mod layout;
mod paragraphs;

pub use event_messages::*;
pub use layers::*;
pub use layout::*;
pub use paragraphs::*;
2 changes: 1 addition & 1 deletion crates/components/src/native_container.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dioxus::prelude::*;
use freya_common::EventMessage;
use freya_core::prelude::EventMessage;
use freya_elements::{
elements as dioxus_elements,
events::KeyboardEvent,
Expand Down
1 change: 1 addition & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dioxus-core = { workspace = true }
tokio = { workspace = true }
winit = { workspace = true }
accesskit = { workspace = true }
accesskit_winit = { workspace = true }

rustc-hash = { workspace = true }
tracing = { workspace = true }
Expand Down
6 changes: 4 additions & 2 deletions crates/core/src/dom/doms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use dioxus_core::VirtualDom;
use freya_common::{
Layers,
ParagraphElements,
TextGroupMeasurement,
};
use freya_native_core::{
prelude::{
Expand Down Expand Up @@ -38,7 +37,10 @@ use torin::prelude::*;
use tracing::info;

use super::mutations_writer::MutationsWriter;
use crate::prelude::measure_paragraph;
use crate::prelude::{
measure_paragraph,
TextGroupMeasurement,
};

pub type DioxusDOM = RealDom<CustomAttributeValues>;
pub type DioxusNode<'a> = NodeRef<'a, CustomAttributeValues>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use winit::window::{
Window,
};

use crate::prelude::PlatformEvent;

pub struct TextGroupMeasurement {
pub text_id: Uuid,
pub cursor_id: usize,
Expand Down Expand Up @@ -39,6 +41,8 @@ pub enum EventMessage {
ExitApp,
/// Callback to access the Window.
WithWindow(Box<dyn FnOnce(&Window) + Send + Sync>),

PlatformEvent(PlatformEvent),
}

impl From<accesskit_winit::Event> for EventMessage {
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod accessibility;
pub mod dom;
pub mod elements;
pub mod event_messages;
pub mod events;
pub mod layout;
pub mod node;
Expand All @@ -16,6 +17,7 @@ pub mod prelude {
accessibility::*,
dom::*,
elements::*,
event_messages::*,
events::*,
layout::*,
node::*,
Expand Down
37 changes: 32 additions & 5 deletions crates/core/src/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,36 @@ use freya_engine::prelude::{
};
use freya_native_core::NodeId;
use torin::torin::Torin;
use winit::window::Window;
use winit::{
event_loop::EventLoopProxy,
window::Window,
};

use crate::{
dom::FreyaDOM,
prelude::{
EventMessage,
PlatformEvent,
},
};

#[derive(Clone)]
pub struct PluginHandle {
pub proxy: EventLoopProxy<EventMessage>,
}

impl PluginHandle {
pub fn new(proxy: EventLoopProxy<EventMessage>) -> Self {
Self { proxy }
}

use crate::dom::FreyaDOM;
/// Emit a [PlatformEvent]. Useful to simulate certain events.
pub fn send_platform_event(&self, event: PlatformEvent) {
self.proxy
.send_event(EventMessage::PlatformEvent(event))
.ok();
}
}

/// Manages all loaded plugins.
#[derive(Default)]
Expand All @@ -19,9 +46,9 @@ impl PluginsManager {
self.plugins.push(Box::new(plugin))
}

pub fn send(&mut self, event: PluginEvent) {
pub fn send(&mut self, event: PluginEvent, handle: PluginHandle) {
for plugin in &mut self.plugins {
plugin.on_event(&event)
plugin.on_event(&event, handle.clone())
}
}
}
Expand Down Expand Up @@ -59,5 +86,5 @@ pub enum PluginEvent<'a> {
/// Skeleton for Freya plugins.
pub trait FreyaPlugin {
/// React on events emitted by Freya.
fn on_event(&mut self, event: &PluginEvent);
fn on_event(&mut self, event: &PluginEvent, handle: PluginHandle);
}
2 changes: 1 addition & 1 deletion crates/core/src/skia/paragraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::ops::Mul;
use freya_common::{
CachedParagraph,
CursorLayoutResponse,
TextGroupMeasurement,
};
use freya_native_core::prelude::NodeImmutable;
use freya_node_state::CursorState;
Expand All @@ -15,6 +14,7 @@ use torin::prelude::{
use crate::prelude::{
align_main_align_paragraph,
DioxusNode,
TextGroupMeasurement,
};

/// Merasure the cursor positio and text selection and notify the subscribed component of the element.
Expand Down
11 changes: 7 additions & 4 deletions crates/freya/src/plugins/performance_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ use std::time::{
Instant,
};

use freya_core::plugins::{
FreyaPlugin,
PluginEvent,
use freya_core::{
plugins::{
FreyaPlugin,
PluginEvent,
},
prelude::PluginHandle,
};
use freya_engine::prelude::{
Color,
Expand Down Expand Up @@ -35,7 +38,7 @@ pub struct PerformanceOverlayPlugin {
}

impl FreyaPlugin for PerformanceOverlayPlugin {
fn on_event(&mut self, event: &PluginEvent) {
fn on_event(&mut self, event: &PluginEvent, _handle: PluginHandle) {
match event {
PluginEvent::StartedLayout(_) => self.started_layout = Some(Instant::now()),
PluginEvent::FinishedLayout(_) => {
Expand Down
4 changes: 2 additions & 2 deletions crates/hooks/src/use_editable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use dioxus_signals::{
Signal,
Writable,
};
use freya_common::{
CursorLayoutResponse,
use freya_common::CursorLayoutResponse;
use freya_core::prelude::{
EventMessage,
TextGroupMeasurement,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/hooks/src/use_focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use dioxus_signals::{
Signal,
Writable,
};
use freya_common::EventMessage;
use freya_core::{
accessibility::ACCESSIBILITY_ROOT_ID,
platform_state::NavigationMode,
prelude::EventMessage,
types::AccessibilityId,
};
use freya_elements::events::{
Expand Down
2 changes: 1 addition & 1 deletion crates/hooks/src/use_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use dioxus_signals::{
Readable,
Signal,
};
use freya_common::EventMessage;
use freya_core::prelude::EventMessage;
use tokio::sync::{
broadcast,
mpsc::UnboundedSender,
Expand Down
2 changes: 1 addition & 1 deletion crates/renderer/src/accessibility.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use accesskit_winit::Adapter;
use freya_common::EventMessage;
use freya_core::{
prelude::{
AccessibilityFocusDirection,
AccessibilityManager,
EventMessage,
SharedAccessibilityManager,
ACCESSIBILITY_ROOT_ID,
},
Expand Down
77 changes: 50 additions & 27 deletions crates/renderer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ use dioxus_core::{
Template,
VirtualDom,
};
use freya_common::{
EventMessage,
TextGroupMeasurement,
};
use freya_core::prelude::*;
use freya_engine::prelude::*;
use freya_native_core::{
Expand Down Expand Up @@ -76,7 +72,7 @@ impl Application {
devtools: Option<Devtools>,
window: &Window,
fonts_config: EmbeddedFonts,
mut plugins: PluginsManager,
plugins: PluginsManager,
default_fonts: Vec<String>,
) -> Self {
let accessibility = AccessKitManager::new(window, proxy.clone());
Expand Down Expand Up @@ -104,9 +100,7 @@ impl Application {
scale_factor: window.scale_factor(),
});

plugins.send(PluginEvent::WindowCreated(window));

Self {
let mut app = Self {
sdom,
vdom,
events: EventsQueue::new(),
Expand All @@ -126,7 +120,14 @@ impl Application {
measure_layout_on_next_render: false,
default_fonts,
queued_focus_node: None,
}
};

app.plugins.send(
PluginEvent::WindowCreated(window),
PluginHandle::new(app.proxy.clone()),
);

app
}

/// Provide the launch state and few other utilities like the EventLoopProxy
Expand All @@ -144,24 +145,36 @@ impl Application {

/// Make the first build of the VirtualDOM and sync it with the RealDOM.
pub fn init_doms<State: 'static>(&mut self, scale_factor: f32, app_state: Option<State>) {
self.plugins.send(PluginEvent::StartedUpdatingDOM);
self.plugins.send(
PluginEvent::StartedUpdatingDOM,
PluginHandle::new(self.proxy.clone()),
);

self.provide_vdom_contexts(app_state);

self.sdom.get_mut().init_dom(&mut self.vdom, scale_factor);
self.plugins.send(PluginEvent::FinishedUpdatingDOM);
self.plugins.send(
PluginEvent::FinishedUpdatingDOM,
PluginHandle::new(self.proxy.clone()),
);
}

/// Update the RealDOM, layout and others with the latest changes from the VirtualDOM
pub fn render_mutations(&mut self, scale_factor: f32) -> (bool, bool) {
self.plugins.send(PluginEvent::StartedUpdatingDOM);
self.plugins.send(
PluginEvent::StartedUpdatingDOM,
PluginHandle::new(self.proxy.clone()),
);

let (repaint, relayout) = self
.sdom
.get_mut()
.render_mutations(&mut self.vdom, scale_factor);

self.plugins.send(PluginEvent::FinishedUpdatingDOM);
self.plugins.send(
PluginEvent::FinishedUpdatingDOM,
PluginHandle::new(self.proxy.clone()),
);

if repaint {
if let Some(devtools) = &self.devtools {
Expand Down Expand Up @@ -264,11 +277,14 @@ impl Application {

/// Render the App into the Window Canvas
pub fn render(&mut self, hovered_node: &HoveredNode, canvas: &Canvas, window: &Window) {
self.plugins.send(PluginEvent::BeforeRender {
canvas,
font_collection: &self.font_collection,
freya_dom: &self.sdom.get(),
});
self.plugins.send(
PluginEvent::BeforeRender {
canvas,
font_collection: &self.font_collection,
freya_dom: &self.sdom.get(),
},
PluginHandle::new(self.proxy.clone()),
);

self.start_render(
hovered_node,
Expand All @@ -280,11 +296,14 @@ impl Application {
self.accessibility
.render_accessibility(window.title().as_str());

self.plugins.send(PluginEvent::AfterRender {
canvas,
font_collection: &self.font_collection,
freya_dom: &self.sdom.get(),
});
self.plugins.send(
PluginEvent::AfterRender {
canvas,
font_collection: &self.font_collection,
freya_dom: &self.sdom.get(),
},
PluginHandle::new(self.proxy.clone()),
);
}

/// Resize the Window
Expand Down Expand Up @@ -336,8 +355,10 @@ impl Application {
{
let fdom = self.sdom.get();

self.plugins
.send(PluginEvent::StartedLayout(&fdom.layout()));
self.plugins.send(
PluginEvent::StartedLayout(&fdom.layout()),
PluginHandle::new(self.proxy.clone()),
);

process_layout(
&fdom,
Expand All @@ -350,8 +371,10 @@ impl Application {
&self.default_fonts,
);

self.plugins
.send(PluginEvent::FinishedLayout(&fdom.layout()));
self.plugins.send(
PluginEvent::FinishedLayout(&fdom.layout()),
PluginHandle::new(self.proxy.clone()),
);
}

if let Some(devtools) = &self.devtools {
Expand Down
Loading

0 comments on commit 2f7f19b

Please sign in to comment.