Jump to content
Sign in to follow this  
DavidRM

Setting Label Cursor

Recommended Posts

I wanted a simple hyperlink. So I used a TW3Label, gave it caption, set the underline, gave it an OnClick event, etc.

First, I discovered that setting the label's Font.Style to [fsUnderline] didn't work. Instead, I had to dig in the forums and learn to use TextNode.style. What's the point of the Font.Style property if it's not going to set the font style?

Second: How do I set the mouse cursor? The "Cursor" property doesn't seem to be doing it.

This is what I have:

  FForgotPassword := TW3Label.Create(Self);
  FForgotPassword.AutoSize := True;
  FForgotPassword.AlignText := taCenter;
  FForgotPassword.Transparent := False;
  FForgotPassword.Font.Color := clRed;
  FForgotPassword.Caption := 'Forgot Password?';
  FForgotPassword.OnClick := ForgotPasswordClicked;
  FForgotPassword.TextNode.style.setProperty('text-decoration', 'underline');
  FForgotPassword.Cursor := crPointer;

On a whim, I just added this:

  FForgotPassword.TextNode.style.setProperty('cursor', 'pointer');

And that solves my problem.

But now I want to know: Is there a reason those other properties exist? Is this a bug? Or am I missing something?

Thanks.

-David

Share this post


Link to post
Share on other sites

Ah yes this is a classic one.

When we made the label control the whole font thing came up and bit us in the bottom. Because Delphi fonts and HTML fonts are very different.
You have the "normal" font stuff, but you also have something called CSS fonts, which a lot of people uses.
So to avoid killing the option for smart users using css-fonts (and glyphs) in their labels, I isolated the underline/bold etc as a function you call with the caption.

If you look in the font class, all the way back to TW3CustomFont (unit System.Fonts), you find this function:

 

function StyleText(const Text: string): string; virtual;

What you do is the following:

  • Set the font styles you need
  • Assign the caption via the function above, like this:
Label.Caption := StyleText("This is styled text");

I think its time we get rid of this and instead go for "normal" delphi styling. It will require a bit more scaffolding for CSS glyphs and fonts, but at least people can set styles as they are used to.

As for the cursor, this is a bug. The label contains sub-constructs that somehow "hide" the underlying element where the cursor is set.
So we just need to tell these constructs to inherit whatever cursor the parent has, and it will be gone.

So Ill try to get this done in our next update

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×