fix: change hooks name

This commit is contained in:
mrxiaozhuox committed 2022-02-01 08:39:31 +08:00
1 parent 7ca92be015
commit f1fe8f1d2a
2 files changed
+6 -6

No files matched your search

+4 -4
View File
@@ -7,13 +7,13 @@ fn main() {
} }
fn app(cx: Scope) -> Element { fn app(cx: Scope) -> Element {
let desktop = dioxus::desktop::desktop_context::use_desktop_context(&cx); let window = dioxus::desktop::desktop_context::use_window(&cx);
cx.render(rsx!( cx.render(rsx!(
link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", rel:"stylesheet" } link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", rel:"stylesheet" }
header { header {
class: "text-gray-400 bg-gray-900 body-font", class: "text-gray-400 bg-gray-900 body-font",
onmousedown: move |_| desktop.drag_window(), onmousedown: move |_| window.drag(),
div { div {
class: "container mx-auto flex flex-wrap p-5 flex-col md:flex-row items-center", class: "container mx-auto flex flex-wrap p-5 flex-col md:flex-row items-center",
a { class: "flex title-font font-medium items-center text-white mb-4 md:mb-0", a { class: "flex title-font font-medium items-center text-white mb-4 md:mb-0",
@@ -23,13 +23,13 @@ fn app(cx: Scope) -> Element {
button { button {
class: "inline-flex items-center bg-gray-800 border-0 py-1 px-3 focus:outline-none hover:bg-gray-700 rounded text-base mt-4 md:mt-0", class: "inline-flex items-center bg-gray-800 border-0 py-1 px-3 focus:outline-none hover:bg-gray-700 rounded text-base mt-4 md:mt-0",
onmousedown: |evt| evt.cancel_bubble(), onmousedown: |evt| evt.cancel_bubble(),
onclick: move |_| desktop.minimize(true), onclick: move |_| window.minimize(true),
"Minimize" "Minimize"
} }
button { button {
class: "inline-flex items-center bg-gray-800 border-0 py-1 px-3 focus:outline-none hover:bg-gray-700 rounded text-base mt-4 md:mt-0", class: "inline-flex items-center bg-gray-800 border-0 py-1 px-3 focus:outline-none hover:bg-gray-700 rounded text-base mt-4 md:mt-0",
onmousedown: |evt| evt.cancel_bubble(), onmousedown: |evt| evt.cancel_bubble(),
onclick: move |_| desktop.close(), onclick: move |_| window.close(),
"Close" "Close"
} }
} }
+2 -2
View File
@@ -34,7 +34,7 @@ impl DesktopContext {
/// ```rust /// ```rust
/// onmousedown: move |_| { desktop.drag_window(); } /// onmousedown: move |_| { desktop.drag_window(); }
/// ``` /// ```
pub fn drag_window(&self) { pub fn drag(&self) {
let _ = self.proxy.send_event(UserWindowEvent::DragWindow); let _ = self.proxy.send_event(UserWindowEvent::DragWindow);
} }
@@ -60,7 +60,7 @@ impl DesktopContext {
} }
/// use this function can get the `DesktopContext` context. /// use this function can get the `DesktopContext` context.
pub fn use_desktop_context(cx: &ScopeState) -> &Rc<DesktopContext> { pub fn use_window(cx: &ScopeState) -> &Rc<DesktopContext> {
cx.use_hook(|_| cx.consume_context::<DesktopContext>()) cx.use_hook(|_| cx.consume_context::<DesktopContext>())
.as_ref() .as_ref()
.unwrap() .unwrap()