cacao/src/quicklook/mod.rs
Ryan McGrath 121a2f938e
Some updates. API still in flux, but you can build
- Added support for Image
- Added a QuickLook feature, to enable thumbnail generation.
- Added support for NSButton.
- Fixed a bug where App activation under Big Sur would leave menus
  without the ability to be used.
- Added the ability for Buttons and ToolbarItems to execute callbacks.
- Added support for Labels and TextFields.
- Added support for MenuItems to have callbacks as well.
- Preliminary ListView support; you have to cache your ListViewRow items
  yourself for the time being, but it works.
- Animation support for ListView operations.
- Support for ScrollViews.
- Helpers for dispatching actions to the main thread (for UI work).
- Updated the Dispatcher trait to make thread handling simpler.
- Basic font support.
2021-01-16 17:11:04 -08:00

47 lines
1.3 KiB
Rust

use objc::runtime::{Object};
use objc::{class, msg_send, sel, sel_impl};
use objc_id::ShareId;
use block::ConcreteBlock;
use url::Url;
use crate::error::Error;
use crate::foundation::{id, NSUInteger};
use crate::image::Image;
mod config;
pub use config::{ThumbnailConfig, ThumbnailQuality};
#[derive(Debug)]
pub struct ThumbnailGenerator(pub ShareId<Object>);
impl ThumbnailGenerator {
pub fn shared() -> Self {
ThumbnailGenerator(unsafe {
ShareId::from_ptr(msg_send![class!(QLThumbnailGenerator), sharedGenerator])
})
}
pub fn generate<F>(&self, url: &Url, config: ThumbnailConfig, callback: F)
where
//F: Fn(Result<(Image, ThumbnailQuality), Error>) + Send + Sync + 'static
F: Fn(Result<(Image, ThumbnailQuality), Error>) + Send + Sync + 'static
{
let block = ConcreteBlock::new(move |thumbnail: id, thumbnail_type: NSUInteger, error: id| {
unsafe {
let image = Image::with(msg_send![thumbnail, NSImage]);
callback(Ok((image, ThumbnailQuality::Low)));
}
});
let block = block.copy();
let request = config.to_request(url);
unsafe {
let _: () = msg_send![&*self.0, generateRepresentationsForRequest:request
updateHandler:block];
}
}
}