Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cocoa: Add NSTextField #121

Merged
merged 1 commit into from
Jul 5, 2023
Merged

cocoa: Add NSTextField #121

merged 1 commit into from
Jul 5, 2023

Conversation

tmc
Copy link
Sponsor Collaborator

@tmc tmc commented Jul 5, 2023

Fixes #120

@tmc tmc requested review from mgood and progrium July 5, 2023 17:49
@progrium progrium merged commit 66a4d6e into progrium:main Jul 5, 2023
0 of 2 checks passed
@programmingkidx
Copy link
Contributor

programmingkidx commented Jul 5, 2023

I'm not sure why but I could not make my program run. It uses NSTextField so I was hoping it would work now. Here it is:

package main

import "github.com/progrium/macdriver/cocoa"
import "github.com/progrium/macdriver/objc"
import "github.com/progrium/macdriver/core"

func main() {
	app := cocoa.NSApp_WithDidLaunch(func(n objc.Object) {
		win := cocoa.NSWindow_New()
		win.SetTitle("Hello world")
		label := cocoa.NSTextField_alloc()
		rect := core.NSMakeRect(10,10,70,20)
		label.InitWithFrame__asNSControl(rect)
		message := core.NSString_FromString("Hello from label")
		label.SetStringValue_(message)
		win.ContentView().AddSubview_(label)
		win.MakeKeyAndOrderFront(nil)
	})
	
	app.SetActivationPolicy(cocoa.NSApplicationActivationPolicyRegular)
	app.ActivateIgnoringOtherApps(true)
	app.Run()
}

I recreated my project several times. I start with running 'go mod init program'. Then I use these commands:

  • go get github.com/progrium/macdriver/cocoa
  • go get github.com/progrium/macdriver/core
  • go get github.com/progrium/macdriver/objc

For some reason I still keep seeing this error:
./main.go:11:18: undefined: cocoa.NSTextField_alloc

The mod file says I am using MacDriver 0.3.0. Hopefully a new tag will make things clearer in the future. I could be still using an old version of MacDriver but I don't know how to check. Does anyone know what is wrong?

@progrium
Copy link
Owner

progrium commented Jul 6, 2023

use go get github.com/progrium/macdriver/cocoa@main to work with latest.

@programmingkidx
Copy link
Contributor

@progrium Thank you! It works now 😁.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request: Add NSTextField class
3 participants