Hi, all.
There's been some talk of a native macOS GUI implementation over the years, but I don't recall much coming from those discussions.
Necessity being the mother of invention, I decided to give it a go.
NimCocoa is my attempt at implementing a native macOS GUI module for Nim.
Let me know what you think....
AIR.
Wow really good. I just tried it. The examples worked great! Instead of wrapping actual ObjC with nim you wrap them first in .m files and call that API. I think thats a better model. Its a pain crating all these NSStrings, NSColor, etc...
Some things I noticed:
I really wish some one would just wrap Metal Graphics API.
Hi, treeform.
Thanks for checking this out.
On macOS, most apps don't quit when the window is closed.
In this case, just do "COMMAND-Q" to exit as you would for most mac apps.
In the case of the upper-case 'Thesaurus', on macOS the first letter of each word in the app filename is typically capitalized...you could simply change the associated nim file name if you like.
The spinning on search might mean that that particular dictionary isn't available for queries, even though it is part of the list of dictionaries published by dict.org....
AIR.
"I really wish some one would just wrap Metal Graphics API." There are wrappers that allow OpenGL and Vulkan that are used for cross platform game programming.
I know for sure that ImGui supports OS X so it should be viable for that use case. It is obviously not a "native" UI but I would personally prefer somethings that has it's own renderer so that it looks the same across platforms. It is portable, slim, fast and work with games. It lacks some features that more application oriented UI:s such as Qt has. While Qt also renders directly on hardware it is rather bloated and for some platforms such as Raspberry Pi it is not free to use.
again, the big deals is done!
is it possible to make a kind of tree-view or expandable view widget?
Maybe, I'll have to look into it
the app is starting with terminal window behind main window even with --app:gui key - how to fix it?
macOS uses Application Bundles for it's GUI applications. You'll need to create the bundle to avoid launching via the terminal.
The git repository has an examples/AppBundler folder. Edit the console version to reflect your name, etc and compile. (you'll need to add the 'plists' module if you don't already have it)
Then execute it in the same folder as the binary you want to bundle (or add it to your path), passing the name of the Nim generated binary you wish to bundle. It will create the app bundle for you.
I should probably add it as a step in the nimble file, still learning how to use it!
what are future plans about other widgets(tabs, menus), layout tools, callbacks?
Menus already exist. Other widgets will be added.
Layout tools? If by this you mean controlling how a gui object responds to the window resizing, that's already in place via the 'anchor' keyword.
On the other hand, if you mean some sort of designer, I'm experimenting with using Interface Builder to create a xib file, and parsing that into something this module can use. It's looking promising so far.
Regarding callbacks: if you mean an action that, for example a button calls, that is also already in place.
I apologize for not documenting all of this yet, but will work on it over the next few days...
Thanks for the feedback!
AIR.
Bumped to v. 0.1.1
Added GroupBox, TabView, and RadioButton objects.
Uploaded examples of each in action.
Uploaded file detailing the functions available in NSFunctions module.
This module doesn't use a Box/Container paradigm, so laying out objects like that doesn't translate from modules that do.
On macOS, whether you use Storyboards or Xib files, the actual objects are laid out by positional coordinates, and you 'anchor' them to sides of the displayed parent object.
Old Delphi users will immediately recognize this; Lazarus is the same.
I mentioned previously that I'm looking into leveraging Interface Builder from Xcode to lay out the GUI. Just a basic xml parser running against a Xib file. Interesting side note is that Storyboards are also in XML. Both show absolute positioning of objects in my testing.
More to come.....
AIR.
AIR, thank you for you reply and for your efforts: I really believe that good GUI libs make our lovely Nim-lang more stronger and popular!
Well, menu items behavior was not obvious but now it is fine. BTW, shortkey commands like Cmd-S, Cmd-O, Cmd-N need to be set up separately?
Regarding NSTableView: perfect, actually my idea is to make hierarchical data control which can be collapsed and expanded. As I understand it is NSOutlineView, a subclass of NSTableView with single column, correct if I'm wrong.
I like you approach to collect all widget controls into class methods like . addRow, .delRow, .somecellproperty, .font, .background etc.
BTW, shortkey commands like Cmd-S, Cmd-O, Cmd-N need to be set up separately?
In general, yes, as part of creating the menuitems.
I'm thinking of approaching this a bit differently, though.
What would your thoughts be if I created a proc that would create the menu for you, along with the associated Cocoa callbacks and shortcuts in place?
Something like newFileMenu, newEditMenu, etc with the standard Apple menus provided?
Less coding on the part of the user of the library, a bit more for me up front.
One would still have the ability to create custom menus (I'd have to work out modifying the 'boiler-plate' menus above, if requested) with custom callbacks.
Regarding NSTableView: perfect, actually my idea is to make hierarchical data control which can be collapsed and expanded. As I understand it is NSOutlineView, a subclass of NSTableView with single column, correct if I'm wrong
There's an NSTableView implementation in the repository, still in the early stages, but supports adding/loading/saving at the moment. Had to work out some of the basics before moving on to the Outline view, which should be an interesting journey in itself.
AIR.
I added newEditMenu and newFormatMenu procs to auto-generate Edit and Font menus.
Uploaded editor.nim to showcase them. Remember to bundle the app so the menus are accessible.
Edit menu has:
Format menu has:
Keyboard shortcuts are working where/when applicable.
I really need to start documenting, but I'm having too much fun coding......
AIR.
Great library!
I'm also interested playing with WKWebView, JSBridge and other Web/Webkit related APIs for wrapping advanced web apps with custom UIs <3
Thanks @georgelemon.
All, I have switched the repository over to GitHub, and have updated the original post.
Of note: The dev branch is configured so that a static library is used in place of the discreet modules, which leads to faster compilation. A simple import Cocoa is all that's needed.
You can still use the discreet modules if you like, but need to specify the modules to load in the import statement. For example: import Cocoa / [NSWindow, NSFunctions].
I'm working on documentation, but was disappointed to find that nimdoc doesn't output to .md files, which I would need for the associated Wiki. I'll work this out soon...
AIR.
I've merged the dev branch with master, so now a static lib gets created when using nimble.
I've also uploaded a preliminary xib file converter to the examples folder. It doesn't do all of the objects this library has yet, but has a demo.xib file included so you can try it.
Any input on the converter is very welcome!
AIR.
Hello,
Just wonder if there is any progress with Outline View sub widget? Also regarding Table View: it would be awesome to have click/select call-backs as well as move/del of row/column functionality...