mamaral / Neon

A powerful Swift programmatic UI layout framework.
MIT License
4.58k stars 389 forks source link

Can I use this framework for Mac OSX application? #3

Open ttruongatl opened 9 years ago

ttruongatl commented 9 years ago

Dear,

Neon is really excellent framework for UI design. But I do not know it is possible for mac os application or not?

Thanks.

mamaral commented 9 years ago

I've never messed with OSX applications before, but I do believe that the origin { 0,0 } is different on OSX apps than iOS apps, lower-left vs. upper-left respectively, so I'm guessing it would not work out of the box, although I'm looking into making a simple fix that will make it work properly on both.

ttruongatl commented 9 years ago

Thanks for your working. Hoping you will completer this framework for both, iOS & OSX.

RohanNagar commented 8 years ago

Would love to use this framework on OS X. Please let me know if you make any progress on that front.

thomjordan commented 8 years ago

Neon looks like a great framework ! I installed it into my project via Carthage this morning, and have been trying to figure out why the subview I've been trying to anchor to the top edge kept showing up centered on the left side with half of the view offscreen. I just realized that the coordinate system on OS X must be different from iOS.. Lol.

mamaral commented 8 years ago

Yeah @thomjordan I still need to look into making this work out of the box for both systems.

thomjordan commented 8 years ago

Great to hear, thanks for the update !

thomjordan commented 8 years ago

There's a read-only Bool property in NSView called flipped that can change the traditional OS X coordinates to a new basis whose origin is in the upper-left.

It defaults to false but can be overridden in a custom subclass of NSView or within an extension to an existing subclass of NSView:

public class NSFlippedView : NSView {
    override public var flipped: Bool {
        return true
    }
}

extension NSTextField  {
    override public var flipped: Bool {
        return true
    }
}

After setting these, Neon now seems to be working perfectly on OS X as far as I can tell, at least within the scope of my limited use of it yesterday. I should be trying out more of the framework over the next few days.

BTW, a quick way to utilize existing NSView-derived classes whose content might depend on the traditional coordinate system is to set the frame and bounds of an traditional view instance to however you want it to look, then add it as a subview of a fresh NSFlippedView object, setting its frame and bounds to fit the size of the inner object's frame, and their origins to (0,0). Neon then can correctly utilize the outer NSFlippedView while the frame and bounds of the inner object may be adjusted in the old coordinate system if needed. I've done this with a few custom view classes and it's been working outstandingly well ! Thanks for sharing this amazing and long needed framework.

mamaral commented 8 years ago

@thomjordan That is awesome! Any chance you'd be able to throw that in a pull request?

thomjordan commented 8 years ago

I can sure try.. I'm not that familiar with Git yet but I can look into it more over the next few days..

On Sun, Nov 8, 2015 at 5:19 PM, Mike Amaral notifications@github.com wrote:

@thomjordan https://github.com/thomjordan That is awesome! Any chance you'd be able to throw that in a pull request?

— Reply to this email directly or view it on GitHub https://github.com/mamaral/Neon/issues/3#issuecomment-154881507.

mamaral commented 8 years ago

@thomjordan No problem, let me know if you need any assistance.

thomjordan commented 8 years ago

I forked Neon to my GitHub page, then cloned it to my local system. On my local copy, I added some lines to the #ifdef in Neon.swift, a few times, but each time I save, close then open the file again the changes are gone. I think I know now how to do the rest, submitting the pull request, etc. I just seem to be stuck on this one part.. how to be able to make changes in the first place. There's no diffs available to be staged either. I tried working directly from the clone, and I also tried do a separate checkout after the clone. I've got to be missing something very obvious. I'll try again tomorrow.

thomjordan commented 8 years ago

I've seen very good results using this version of Neon modified for OS X. I still haven't figured out how to initiate pull requests in Git, so instead here's a zip attachment of the Neon source folder circa mid-November 2015, modified for the default OS X coordinate system with a lower-left origin. I basically just switched around some of the enum cases and turned some "+" signs into "-", et al. It took less than an hour which was surprising, becoming largely mechanical once deciding on a short sequence of steps for repeatedly applying the geometrical reflection within the code. Since then any time I've used the module in OS X I've seen no errors or unpredictable behavior. In the zip archive below, the source files show where each modification was made, by commenting out and preserving the original expressions made for the iOS coordinate system. Thanks for creating Neon and sharing it on here !

NeonSource(OSX).zip

mamaral commented 8 years ago

@thomjordan Excellent, I'll see what you did there and see if I can conditionalize it. Honestly, the reason why I haven't done this yet is because I've actually never built an OSX app, and have no idea how to set it up with a simple widow for testing. I spent like 30 minutes one night last year and gave up, then forgot about it since.

thomjordan commented 8 years ago

I used Neon to help achieve a quick, balanced UI look early on within this large-scale application I'm working on, and then moved on to other areas of the app. I'm in the midst of some heavy refactoring this week, and looking back at some previously-written code it's obvious to me now that I've achieved better, more consistent results using Neon than what I could get using Auto Layout, and much more quickly too. I recently got NSStackView working correctly with the right settings of Auto Layout constraints for my project, and I can see using a mixture of stack views and Neon to achieve some truly superb results. Thanks again !

mamaral commented 8 years ago

@thomjordan Thanks for the feedback! :)