Last active
May 15, 2023 13:49
-
-
Save preinpost/9ade66d7fdcef54c2540d58ca559ffef to your computer and use it in GitHub Desktop.
mac app entry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use cacao::appkit::{App, AppDelegate}; | |
use cacao::appkit::window::Window; | |
use cacao::color::Color; | |
#[derive(Default)] | |
struct BasicApp { | |
} | |
impl AppDelegate for BasicApp { | |
fn did_finish_launching(&self) { | |
let window = Window::default(); | |
window.set_minimum_content_size(200, 200); | |
window.set_background_color(Color::SystemBlack); | |
window.set_title("Hello World!!"); | |
window.show(); | |
} | |
} | |
fn main() { | |
App::new("com.hello.world", BasicApp::default()).run(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
import Foundation | |
class AppDelegate: NSObject, NSApplicationDelegate { | |
var window: NSWindow? | |
func applicationDidFinishLaunching(_ aNotification: Notification) { | |
let frame = CGRect( | |
x: 10.0, | |
y: 10.0, | |
width: 400.0, | |
height: 400.0 | |
) | |
let win = NSWindow(contentRect: frame, styleMask: [ | |
.closable, .fullSizeContentView, .miniaturizable, .fullScreen, | |
.resizable, .unifiedTitleAndToolbar | |
], backing: .buffered, defer: true) | |
win.center() | |
win.title = "Hello world" | |
win.makeKeyAndOrderFront(nil) | |
window = win | |
} | |
} | |
let app = NSApplication.shared | |
let delegate = AppDelegate() | |
app.delegate = delegate | |
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate cocoa; | |
use cocoa::base::{selector, nil, NO}; | |
use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, | |
NSString}; | |
use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, | |
NSBackingStoreBuffered, NSMenu, NSMenuItem, NSWindowStyleMask, | |
NSRunningApplication, NSApplicationActivateIgnoringOtherApps}; | |
fn main() { | |
unsafe { | |
let _pool = NSAutoreleasePool::new(nil); | |
let app = NSApp(); | |
app.setActivationPolicy_(NSApplicationActivationPolicyRegular); | |
// create Menu Bar | |
let menubar = NSMenu::new(nil).autorelease(); | |
let app_menu_item = NSMenuItem::new(nil).autorelease(); | |
menubar.addItem_(app_menu_item); | |
app.setMainMenu_(menubar); | |
// create Application menu | |
let app_menu = NSMenu::new(nil).autorelease(); | |
let quit_prefix = NSString::alloc(nil).init_str("Quit "); | |
let quit_title = | |
quit_prefix.stringByAppendingString_(NSProcessInfo::processInfo(nil).processName()); | |
let quit_action = selector("terminate:"); | |
let quit_key = NSString::alloc(nil).init_str("q"); | |
let quit_item = NSMenuItem::alloc(nil) | |
.initWithTitle_action_keyEquivalent_(quit_title, quit_action, quit_key) | |
.autorelease(); | |
app_menu.addItem_(quit_item); | |
app_menu_item.setSubmenu_(app_menu); | |
// create Window | |
let window = NSWindow::alloc(nil) | |
.initWithContentRect_styleMask_backing_defer_(NSRect::new(NSPoint::new(0., 0.), | |
NSSize::new(200., 200.)), | |
NSWindowStyleMask::NSUnifiedTitleAndToolbarWindowMask, | |
NSBackingStoreBuffered, | |
NO) | |
.autorelease(); | |
window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); | |
window.center(); | |
let title = NSString::alloc(nil).init_str("Hello World!"); | |
window.setTitle_(title); | |
window.makeKeyAndOrderFront_(nil); | |
let current_app = NSRunningApplication::currentApplication(nil); | |
current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); | |
app.run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment