Git Product home page Git Product logo

tauri-nspanel's Introduction

Swizzle Tauri's NSWindow to NSPanel

Install

There are three general methods of installation that we can recommend.

  • Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked)
  • Pull sources directly from Github using git tags / revision hashes (most secure)
  • Git submodule install this repo in your tauri project and then use file protocol to ingest the source (most secure, but inconvenient to use)

Install the plugin by adding the following to your Cargo.toml file:

[dependencies]
tauri-nspanel = { git = "https://github.com/ahkohd/ns-panel" }

Usage

  1. First you need to register the core plugin with Tauri:

src-tauri/src/main.rs

fn main() {
    tauri::Builder::default()
        .plugin(tauri_nspanel::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
  1. To swizzle a window's NSWindow to NSPanel, use the to_panel() method:
use tauri_nspanel::WindowExt;

// ...
let panel = window.to_panel().unwrap();

The window will be swizzled to NSPanel.

Only call the to_panel() method once a window.

  1. To access your panels, use the app_handle.get_panel("label"):
use tauri_nspanel::ManagerExt;

// ...

let my_panel = app_handle.get_panel("main");
  1. To respond to panel events, such as resizing, moving, exposing, and minimizing (See the exhaustive list), you need to setup a NSWindowDelegate for your panel.

Use the panel_delegate!() macro to do this:

use tauri_nspanel::{objc_id::Id, panel_delegate, ManagerExt, Panel, WindowExt};

// ...

// Define your handlers
// See, https://developer.apple.com/documentation/appkit/nswindowdelegate?language=objc
// for an exhaustive list of handlers.
//
// Example: to respond to windowWillBeginSheet:
// declare the function in snake case:
// fn window_will_begin_sheet(_: Panel) { }

fn window_did_become_key(_: Panel) {
  println!("[info]: panel becomes key window!");
}

fn window_did_resign_key(_: Panel) {
  println!("[info]: panel resigned from key window!");
}

// Use the `panel_delegate!()` macro to create your custom delegate
let delegate = panel_delegate!(MyPanelDelegate {
  window_did_become_key,
  window_did_resign_key
});

// Give the delegate a reference to your panel
delegate.set_panel(panel.to_owned());

// Set your panel's delegate
panel.set_delegate(delegate);

Related

The following are projects related to this plugin:

Contributing

PRs accepted. Please make sure to read the Contributing Guide before making a pull request.

License

MIT or MIT/Apache 2.0 where applicable.

tauri-nspanel's People

Contributors

ahkohd avatar renovate[bot] avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.