From f99991b23bdf7442011a12dd86e058557d1107d5 Mon Sep 17 00:00:00 2001 From: Stuart Woodbury Date: Fri, 23 Dec 2022 09:52:12 -0500 Subject: [PATCH 1/7] feat(DesktopContext): expose set_inner_size --- packages/desktop/src/desktop_context.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index 89d0e2fe4..84e321e18 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -1,5 +1,6 @@ use crate::controller::DesktopController; use dioxus_core::ScopeState; +use wry::application::dpi::LogicalSize; use wry::application::event_loop::ControlFlow; use wry::application::event_loop::EventLoopProxy; use wry::application::window::Fullscreen as WryFullscreen; @@ -120,6 +121,11 @@ impl DesktopContext { let _ = self.proxy.send_event(SetZoomLevel(scale_factor)); } + /// modifies the inner size of the window + pub fn set_inner_size(&self, logical_size: LogicalSize) { + let _ = self.proxy.send_event(SetInnerSize(logical_size)); + } + /// launch print modal pub fn print(&self) { let _ = self.proxy.send_event(Print); @@ -159,6 +165,7 @@ pub enum UserWindowEvent { SetDecorations(bool), SetZoomLevel(f64), + SetInnerSize(LogicalSize), Print, DevTool, @@ -205,6 +212,7 @@ pub(super) fn handler( SetDecorations(state) => window.set_decorations(state), SetZoomLevel(scale_factor) => webview.zoom(scale_factor), + SetInnerSize(logical_size) => window.set_inner_size(logical_size), Print => { if let Err(e) = webview.print() { From fe9c482afbdc14298fa81263c6fdfc93c2f6f47f Mon Sep 17 00:00:00 2001 From: Stuart Woodbury Date: Fri, 23 Dec 2022 11:40:51 -0500 Subject: [PATCH 2/7] fix(clippy) --- packages/desktop/src/desktop_context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index 321be314c..7b41d33e0 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -2,12 +2,12 @@ use std::rc::Rc; use crate::controller::DesktopController; use dioxus_core::ScopeState; -use wry::application::dpi::LogicalSize; use serde::de::Error; use serde_json::Value; use std::future::Future; use std::future::IntoFuture; use std::pin::Pin; +use wry::application::dpi::LogicalSize; use wry::application::event_loop::ControlFlow; use wry::application::event_loop::EventLoopProxy; #[cfg(target_os = "ios")] From 4e49d71efe404883ce5cace430fd59a63f64e610 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 23 Dec 2022 17:11:00 -0500 Subject: [PATCH 3/7] chore: tweak global attributes --- packages/html/src/global_attributes.rs | 3088 +++++++++++++++++------- 1 file changed, 2264 insertions(+), 824 deletions(-) diff --git a/packages/html/src/global_attributes.rs b/packages/html/src/global_attributes.rs index 5c4ac42e8..a03b2f5e6 100644 --- a/packages/html/src/global_attributes.rs +++ b/packages/html/src/global_attributes.rs @@ -2,131 +2,165 @@ use crate::AttributeDiscription; -macro_rules! no_namespace_trait_methods { +macro_rules! trait_methods { ( + $trait:ident; $( $(#[$attr:meta])* - $name:ident; - )* + $name:ident $(: $($arg:literal),*)*; + )+ ) => { - $( - $(#[$attr])* - const $name: AttributeDiscription = ( - stringify!($name), - None, - false - ); - )* - }; -} -macro_rules! style_trait_methods { - ( - $( - $(#[$attr:meta])* - $name:ident: $lit:literal, - )* - ) => { - $( - $(#[$attr])* - const $name: AttributeDiscription = ( - $lit, - Some("style"), - false - ); - )* - }; -} -macro_rules! aria_trait_methods { - ( - $( - $(#[$attr:meta])* - $name:ident: $lit:literal, - )* - ) => { - $( - $(#[$attr])* - const $name: AttributeDiscription = ( - $lit, - None, - false - ); - )* + pub trait $trait { + $( + $(#[$attr])* + const $name: AttributeDiscription = trait_methods! { $name $(: $($arg),*)*; }; + )* + } }; + + // Rename the incoming ident and apply a custom namespace + ( $name:ident: $lit:literal, $ns:literal; ) => { ($lit, Some($ns), false) }; + + // Rename the incoming ident + ( $name:ident: $lit:literal; ) => { ($lit, None, false ) }; + + // Don't rename the incoming ident + ( $name:ident; ) => { (stringify!($name), None, false) }; } -pub trait GlobalAttributes { +trait_methods! { + GlobalAttributes; + /// Prevent the default action for this element. /// /// For more information, see the MDN docs: /// + prevent_default: "dioxus-prevent-default"; - const prevent_default: AttributeDiscription = ("dioxus-prevent-default", None, false); - no_namespace_trait_methods! { - accesskey; - autocapitalize; - autofocus; - /// The HTML class attribute is used to specify a class for an HTML element. - /// - /// ## Details - /// Multiple HTML elements can share the same class. - /// - /// The class global attribute is a space-separated list of the case-sensitive classes of the element. - /// Classes allow CSS and Javascript to select and access specific elements via the class selectors or - /// functions like the DOM method document.getElementsByClassName. - /// - /// ## Example - /// - /// ### HTML: - /// ```html - ///

Above point sounds a bit obvious. Remove/rewrite?

- /// ``` - /// - /// ### CSS: - /// ```css - /// .note { - /// font-style: italic; - /// font-weight: bold; - /// } - /// - /// .editorial { - /// background: rgb(255, 0, 0, .25); - /// padding: 10px; - /// } - /// ``` - class; - contenteditable; - data; - dir; - draggable; - enterkeyhint; - exportparts; - hidden; - id; - inputmode; - is; - itemid; - itemprop; - itemref; - itemscope; - itemtype; - lang; - nonce; - part; - role; - slot; - spellcheck; - style; - tabindex; - title; - translate; + /// + accesskey: "accesskey"; - /// dangerous_inner_html is Dioxus's replacement for using innerHTML in the browser DOM. In general, setting - /// HTML from code is risky because it’s easy to inadvertently expose your users to a cross-site scripting (XSS) - /// attack. So, you can set HTML directly from Dioxus, but you have to type out dangerous_inner_html to remind - /// yourself that it’s dangerous - dangerous_inner_html; - } + + /// + autocapitalize: "autocapitalize"; + + + /// + autofocus; + + /// The HTML class attribute is used to specify a class for an HTML element. + /// + /// ## Details + /// Multiple HTML elements can share the same class. + /// + /// The class global attribute is a space-separated list of the case-sensitive classes of the element. + /// Classes allow CSS and Javascript to select and access specific elements via the class selectors or + /// functions like the DOM method document.getElementsByClassName. + /// + /// ## Example + /// + /// ### HTML: + /// ```html + ///

Above point sounds a bit obvious. Remove/rewrite?

+ /// ``` + /// + /// ### CSS: + /// ```css + /// .note { + /// font-style: italic; + /// font-weight: bold; + /// } + /// + /// .editorial { + /// background: rgb(255, 0, 0, .25); + /// padding: 10px; + /// } + /// ``` + /// + class; + + /// + contenteditable; + + /// + data; + + /// + dir; + + /// + draggable; + + /// + enterkeyhint; + + /// + exportparts; + + ///