Lazarus

Programming => Widgetset => Carbon => Topic started by: VTwin on February 21, 2011, 06:05:02 pm

Title: Why are TButtons square?
Post by: VTwin on February 21, 2011, 06:05:02 pm
Does anyone know why a TButton is square and flat? I found a bug report from 2009 (0012256) about square buttons in panels, but others were normal. The resolution of that issue was "It is Mac OS X issue, which we can't work around."

I'm finding all TButtons to be square though. I'm using OS X 10.6.5 and Lazarus 0.9.31. All TButtons are square using the Carbon widget set. They show up as standard rounded Aqua-style buttons in Qt.

Thanks, appreciate any thoughts.
Title: Re: Why are TButtons square?
Post by: Phil on February 21, 2011, 06:10:33 pm
Just set the button Height properly:

http://web.me.com/macpgmr/ObjP/MacXPlatform_Part8.html#Buttons

Thanks.

-Phil
Title: Re: Why are TButtons square?
Post by: VTwin on February 21, 2011, 06:34:35 pm
That does the trick.

Thanks Phil!
Title: Re: Why are TButtons square?
Post by: VTwin on February 21, 2011, 07:22:30 pm
I'm trying out the TButton options and have a few more questions.

I figured out that:
Setting Cancel = true allows pressing Esc to trigger the button action.
Setting TabOrder = 0 allows pressing Enter to trigger the action.

But don't understand:
Is there a way to highlight the default button? It is normally blue in OS X.
Is it possible to set the font size? I can't do it.
The default button font, I'm guessing Lucida Grande 12, is not centered correctly. It is several pixels too far up. Is there a way to center it or set the baseline?
Title: Re: Why are TButtons square?
Post by: VTwin on February 21, 2011, 07:37:13 pm
Curiously, TBitBtn text is correctly centered vertically, TButton text is not.
Title: Re: Why are TButtons square?
Post by: Phil on February 21, 2011, 07:42:44 pm
I'm trying out the TButton options and have a few more questions.

I figured out that:
Setting Cancel = true allows pressing Esc to trigger the button action.
Setting TabOrder = 0 allows pressing Enter to trigger the action.

But don't understand:
Is there a way to highlight the default button? It is normally blue in OS X.
I noticed that also, but haven't gotten around to looking at it.

Is it possible to set the font size? I can't do it.
The default button font, I'm guessing Lucida Grande 12, is not centered correctly. It is several pixels too far up. Is there a way to center it or set the baseline?

You should be able to set the font and font size.

I'm not sure what default font the Carbon widgetset uses, but setting the size correctly should center it okay. Are you talking about font Height or Size? In my app, Height=-13 vertically centers nicely when Lucida Grande is used - Lucida Grande is the one to use on Mac.

With my app, I run a script that converts the forms to eliminate some of the Lazarus non-standard behavior. It uses the DfmToLfm converter from the XDev Toollkit. This converter can also convert .lfm to .lfm too. The idea here, as I outlined in the article, is that you have two sets of forms. One set is what you design with, perhaps Windows if that's where you start. Then any time you make a change to a form there, you convert the forms to a different set used on Mac. They can have a different name if you want to keep them separate to avoid confusion.

So if you convert a form with the converter's -m -s switches, it will also do font substitution to make sure you're using Lucida Grande or other Mac fonts instead of typical MS Sans Serif or Arial that is often used on Windows.

http://web.me.com/macpgmr/XDev/XDevStatus.html

Thanks.

-Phil
Title: Re: Why are TButtons square?
Post by: VTwin on February 21, 2011, 08:17:02 pm
I had left the Font Name = default. If I change it to Name = Lucida Grande, I can indeed change the Height. Thanks.

Oddly, there is a difference in the vertical centering between TButton and TBitBtn. The text is vertically centered in a TBitBtn, but is too high in a TButton. I will just use a TBitBtn, but perhaps I should report it as a cosmetic bug.

I have tried setting TBitBtn.Default = true, and thought it might highlight the default button, but it doesn't. Maybe I should submit this as a request?

I'm still figuring out Lazarus and pretty sure I will eventually port three applications from REALbasic. I'm slowing migrating one now on OS X, but will need to figure out Windows as well if I am to do all three. Your article is helpful, and I'm trying to build in conditional compiles as I go. Maybe I will need multiple forms as well.

Thanks Phil
Title: Re: Why are TButtons square?
Post by: VTwin on February 21, 2011, 09:04:20 pm
I just discovered that setting TBitBtn.Kind = bkOK results in a "OK" button glyph with a green checkmark. It would be nice if it were a blue Mac Aqua button, but maybe that is asking too much.
Title: Re: Why are TButtons square?
Post by: vvzh on February 21, 2011, 09:16:54 pm
ShowGlyphMode (http://lazarus-dev.blogspot.com/2009/05/changes-with-button-glyphs.html) is probably what you need to modify.
Title: Re: Why are TButtons square?
Post by: Phil on February 21, 2011, 09:19:52 pm
ShowGlyphMode (http://lazarus-dev.blogspot.com/2009/05/changes-with-button-glyphs.html) is probably what you need to modify.

No, he doesn't want a glyph.

Did you read the link you cite? See the bottom comment about glyphs on Mac.

Thanks.

-Phil
Title: Re: Why are TButtons square?
Post by: Phil on February 21, 2011, 09:39:23 pm
I just discovered that setting TBitBtn.Kind = bkOK results in a "OK" button glyph with a green checkmark. It would be nice if it were a blue Mac Aqua button, but maybe that is asking too much.

That's the garish old Delphi glyphs. I haven't seen apps that use them for years since that's not what Windows buttons look like either.

I'm not sure what the best solution ultimately is. Go ahead and file a bug report at least to document this. Perhaps all that's needed is for the Carbon widgetset to highlight the button that has Default = True.

Thanks.

-Phil
Title: Re: Why are TButtons square?
Post by: Phil on February 21, 2011, 09:50:04 pm
Frederick,

What happens if you set a button's Default to True? Try it with both TButton and TBitBtn. I see this in the Carbon widgetset:

procedure TCarbonCustomButton.SetDefault(ADefault: Boolean);
begin
  OSError(
    SetControlData(ControlRef(Widget), kControlEntireControl,
      kControlPushButtonDefaultTag, SizeOf(Boolean), @ADefault),
    Self, 'SetDefault', SSetData);
end;

procedure TCarbonBitBtn.SetDefault(ADefault: Boolean);
begin
  // not supported
end;

So it seems like it should work with TButton but not with TBitBtn. If not, include your sample app that demonstrates the problem with your bug report.

Thanks.

-Phil
Title: Re: Why are TButtons square?
Post by: VTwin on February 21, 2011, 10:28:37 pm
That does work Phil. Thanks, I don't know why I didn't see that. Too long staring at the screen I guess.

Should that behavior be implemented in a TBitBtn?

That leaves just the minor cosmetic issue of vertical text centering. It is obvious if you create a TButton and a TBitBtn both with Height = 22 and identical text. A minor point perhaps, but it makes the TButtons look slightly odd, something users notice when evaluating a program.

Title: Re: Why are TButtons square?
Post by: Phil on February 21, 2011, 10:48:24 pm
That's probably why I wasn't seeing it, because I'm using TBitBtn.

It would be nice if TBitBtn supported the Default property. Not sure what that comment in the code means. Normally if a property is not supported, there will be an entry in the widgetset's issues.xml file, but I don't see anything about TBitBtn.Default in carbon's issues.xml.

You might want to post two different bug reports since the two issues are not related. That makes it easier for closing an issue if only one of them gets fixed.

Thanks.

-Phil
Title: Re: Why are TButtons square?
Post by: VTwin on February 21, 2011, 10:54:28 pm
Thanks Phil, I really appreciate your help. I will file two reports with sample code.

Regards,
Frederick
Title: Re: Why are TButtons square?
Post by: Phil on February 21, 2011, 10:57:38 pm
I'm still figuring out Lazarus and pretty sure I will eventually port three applications from REALbasic. I'm slowing migrating one now on OS X, but will need to figure out Windows as well if I am to do all three. Your article is helpful, and I'm trying to build in conditional compiles as I go. Maybe I will need multiple forms as well.

You could probably go the other way as well (Mac form --> Windows form) if you want. The DfmToLfm converter only does 3 things currently to forms (presumably from Windows) if the -m and -s switches are used:
  - Reduces button Height.
  - Sets TabStop = False for controls that can't receive keyboard focus.
  - Substitutes Mac fonts.

Going the other way should be possible too:
  - Set TabStop = True
  - Substitute Windows fonts (Lucida Grande is not a normal Windows font).

That way you could do all design changes on Mac and just auto-convert forms to Windows.

I don't see any alternative to having many IFDEF's in your code. There are too many things that have to be worked around to get a true Mac-like look and feel, so that the app doesn't look ridiculous to Mac users.

Thanks.

-Phil
Title: Re: Why are TButtons square?
Post by: VTwin on February 26, 2011, 04:02:08 pm
Thanks for the explanation of DfmToLfm.

I will try to avoid maintaining multiple forms if possible, as I can see myself getting confused. I will try to solve the interface tweaking by planning ahead, and using IFDEFS as needed. Your article has some helpful tips, such as CheckOKCancelBtns.
TinyPortal © 2005-2018