Re: Aligning baseline of NS controls
On Jul 10, 2014, at 9:03 AM, Keary Suska wrote: > On Jul 10, 2014, at 2:02 AM, Aandi Inston wrote: > >> Suppose a dialog is to contain a line with multiple controls like >> >> [ ] Add seconds [before/after] >> Each of these controls contains text, and the aim here is to align the text >> so it does not jump up and down - to align the text baseline. > > Umm, Auto Layout? You can easily align elements by baseline... And even if you don't use auto layout as such, there were methods introduced to support it that you can use anyway. In particular, -[NSView alignmentRectForFrame:] to get the alignment rectangle and -baselineOffsetFromBottom to find the baseline relative to that alignment rectangle. Regards, Ken ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Aligning baseline of NS controls
On Jul 10, 2014, at 2:02 AM, Aandi Inston wrote: > I am porting a library for dynamic dialog creation to Cocoa. > The implementation is using various standard controls such as > NSTextField and NSButton. I have a question. > > Suppose a dialog is to contain a line with multiple controls like > > [ ] Add seconds [before/after] > > Here > [ ] Add is a check box > _ is an editable text field > seconds is a noneditable text field > [before/after] is a popup button > > Each of these controls contains text, and the aim here is to align the text > so it does not jump up and down - to align the text baseline. If the top of > the controls, or the bottom of the controls, are aligned then the text > itself will not be aligned. > > Two possibilities suggest themselves > - fixed constants, based on experiments (which will perhaps go awry if the > system configuration changes) > - work out the height of each of these controls, assume padding is equal > top and bottom, and adjust alignment by half of the difference (this is an > attractive idea, but I note in a single experiment that the height of > noneditable text was 16 while editable text was 21, a difference of 2.5 > pixels which is awkward). > > Is there a better way to do this? I imagine it's a problem faced before. Umm, Auto Layout? You can easily align elements by baseline... HTH, Keary Suska Esoteritech, Inc. "Demystifying technology for your home or business" ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Aligning baseline of NS controls
I am porting a library for dynamic dialog creation to Cocoa. The implementation is using various standard controls such as NSTextField and NSButton. I have a question. Suppose a dialog is to contain a line with multiple controls like [ ] Add seconds [before/after] Here [ ] Add is a check box _ is an editable text field seconds is a noneditable text field [before/after] is a popup button Each of these controls contains text, and the aim here is to align the text so it does not jump up and down - to align the text baseline. If the top of the controls, or the bottom of the controls, are aligned then the text itself will not be aligned. Two possibilities suggest themselves - fixed constants, based on experiments (which will perhaps go awry if the system configuration changes) - work out the height of each of these controls, assume padding is equal top and bottom, and adjust alignment by half of the difference (this is an attractive idea, but I note in a single experiment that the height of noneditable text was 16 while editable text was 21, a difference of 2.5 pixels which is awkward). Is there a better way to do this? I imagine it's a problem faced before. Thanks in advance. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com