Class TCastleLabel

Unit

Declaration

type TCastleLabel = class(TCastleUserInterfaceFont)

Description

Label with possibly multiline text. See manual about displaying text and fonts.

Hierarchy

Overview

Fields

Public nested const DefaultLineSpacing = 2;

Methods

Protected procedure PreferredSize(var PreferredWidth, PreferredHeight: Single); override;
Protected function GetInternalText: String; override;
Protected procedure SetInternalText(const Value: String); override;
Protected procedure UIScaleChanged; override;
Protected procedure TranslateProperties(const TranslatePropertyEvent: TTranslatePropertyEvent); override;
Protected procedure Loaded; override;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure Render; override;
Public procedure EditorAllowResize( out ResizeWidth, ResizeHeight: Boolean; out Reason: String); override;
Public function PropertySections(const PropertyName: String): TPropertySections; override;
Public procedure FontChanged; override;
Public function DisplayChars: Cardinal;

Properties

Public property Color: TCastleColor read FColor write FColor;
Public property FrameColor: TCastleColor read FFrameColor write FFrameColor; deprecated 'display frame around label using Border or parent UI control';
Published property AutoSize: boolean read FAutoSize write SetAutoSize default true;
Published property Text: TStrings read FText write SetText;
Published property Caption: String read GetCaption write SetCaption stored false;
Published property PaddingHorizontal: Single read FPaddingHorizontal write SetPaddingHorizontal default 0;
Published property PaddingVertical: Single read FPaddingVertical write SetPaddingVertical default 0;
Published property Padding: Single read FPadding write SetPadding default 0;
Published property LineSpacing: Single read FLineSpacing write FLineSpacing default DefaultLineSpacing;
Published property Html: boolean read FHtml write SetHtml default false;
Published property Tags: boolean read FHtml write SetHtml stored false default false; deprecated 'use Html instead';
Published property Frame: boolean read FFrame write FFrame default false; deprecated 'display frame around label using Border or parent UI control';
Published property MaxWidth: Single read FMaxWidth write SetMaxWidth default 0;
Published property Alignment: THorizontalPosition read FAlignment write SetAlignment default hpLeft;
Published property VerticalAlignment: TVerticalPosition read FVerticalAlignment write SetVerticalAlignment default vpBottom;
Published property MaxDisplayChars: Integer read FMaxDisplayChars write SetMaxDisplayChars default -1;
Published property CaptionTranslate: Boolean read FCaptionTranslate write FCaptionTranslate default true;
Published property ColorPersistent: TCastleColorPersistent read FColorPersistent ;
Published property FrameColorPersistent: TCastleColorPersistent read FFrameColorPersistent ;

Description

Fields

Public nested const DefaultLineSpacing = 2;

This item has no description.

Methods

Protected procedure PreferredSize(var PreferredWidth, PreferredHeight: Single); override;

This item has no description. Showing description inherited from TCastleUserInterface.PreferredSize.

Controls that have a preferred size should override this. By default this contains values derived from Width, WidthFraction, Height, HeightFraction, with Border subtracted.

Note that the arguments should be already scaled, i.e. multiplied by UIScale, i.e. expressed in final device pixels.

Note that the returned PreferredWidth and PreferredHeight must not include the space for Border. Border size will be added later.

Protected function GetInternalText: String; override;

This item has no description.

Protected procedure SetInternalText(const Value: String); override;

This item has no description.

Protected procedure UIScaleChanged; override;

This item has no description.

Protected procedure TranslateProperties(const TranslatePropertyEvent: TTranslatePropertyEvent); override;

This item has no description. Showing description inherited from TCastleComponent.TranslateProperties.

Enumerate all properties that are possible to translate in this component. E.g. in TCastleLabel it will return TCastleLabel.Caption, in TCastleEdit it will return TCastleEdit.Text and TCastleEdit.Placeholder.

Returns only non-empty properties, thus assuming that if current (by convention, English) text is empty, then there is no point in translating it. Moreover descendants may define boolean properties to exclude particular text from translating, e.g. TCastleLabel.CaptionTranslate, TCastleEdit.TextTranslate, TCastleEdit.PlaceholderTranslate.

It is not recursive (it doesn't enumerate children properties). Use global TranslateProperties procedure to call this on a hierarchy of TComponent.

You usually don't want to call this method (it is called by other engine routines). But you may find it useful to override this, if you define new component.

Protected procedure Loaded; override;

This item has no description.

Public constructor Create(AOwner: TComponent); override;

This item has no description.

Public destructor Destroy; override;

This item has no description.

Public procedure Render; override;

This item has no description. Showing description inherited from TCastleUserInterface.Render.

Render a control. Called only when Exists and render context is initialized.

Do not call this method. It will be automatically called by the engine when needed. It will be called when UI is part of TCastleContainer.Controls list or rendered (e.g. for off-screen rendering) by TCastleContainer.RenderControl.

You should only override this method.

See https://castle-engine.io/manual_2d_ui_custom_drawn.php for examples what you can put here.

You can depend on some OpenGL state being set before calling this method. You can depend on it being set, and you can carelessly change it. This state we set:

  • Viewport is set to include whole container.

  • Depth test is off.

  • For ancient fixed-function pipeline (see TGLFeatures.RequestCapabilities):

    • The 2D orthographic projection is always set at the beginning. Useful for 2D controls.

    • The modelview matrix is set to identity. The matrix mode is always modelview.

    • The raster position is set to (0,0). The (deprecated) WindowPos is also set to (0,0).

    • Texturing, lighting, fog is off.

Beware that GLSL RenderContext.CurrentProgram has undefined value when this is called. You should always set it, before making direct OpenGL drawing calls (all the engine drawing routines do it already, this is only a concern if you make direct OpenGL / OpenGLES calls).

Public procedure EditorAllowResize( out ResizeWidth, ResizeHeight: Boolean; out Reason: String); override;

This item has no description. Showing description inherited from TCastleUserInterface.EditorAllowResize.

Override this to prevent resizing some dimension in CGE editor.

Public function PropertySections(const PropertyName: String): TPropertySections; override;

This item has no description. Showing description inherited from TCastleComponent.PropertySections.

Section where to show property in the editor.

Public procedure FontChanged; override;

This item has no description. Showing description inherited from TCastleUserInterfaceFont.FontChanged.

Force considering font changed (font instance, or glyphs, or sizes changed).

Usually, you don't need to call this explicitly from the outside. Changing font, like CustomFont or TCastleContainer.DefaultFont or UIFont, or any property that may affect the font is automatically applied.

But there are exceptions: right now, if you call Load on a font, it's measurements will change but some controls using it will not recalculate sizes automatically. In this case, call this method.

Public function DisplayChars: Cardinal;

This item has no description.

Properties

Public property Color: TCastleColor read FColor write FColor;

Text color. By default it's opaque black.

Public property FrameColor: TCastleColor read FFrameColor write FFrameColor; deprecated 'display frame around label using Border or parent UI control';

Warning: this symbol is deprecated: display frame around label using Border or parent UI control

Color tint of the background image, see Frame. By default white.

Published property AutoSize: boolean read FAutoSize write SetAutoSize default true;

Should we automatically adjust size to the text size. The size of the label determines where does it display the Frame, where does it catch events, to what width is it aligned (see Alignment) and so on.

When this is True (the default) then Width, Height, FullSize values are ignored.

Published property Text: TStrings read FText write SetText;

Caption displayed on the label, each line as a String. Setting this property merely copies the contents using TStrings.Assign.

Published property Caption: String read GetCaption write SetCaption stored false;

Caption displayed on the label. This is just a shortcut to get/set Text as a single String.

Use LineEnding or NL constant when setting this to indicate a newline. The two examples below are equivalent:

// one way
Label1.Text.Clear;
Label1.Text.Add('First line');
Label1.Text.Add('Second line');

// alternative way to do the same
Label1.Caption := 'First line' + LineEnding + 'Second line';

Published property PaddingHorizontal: Single read FPaddingHorizontal write SetPaddingHorizontal default 0;

Inside the label rectangle, padding between rect borders and text. Total horizontal padding is the sum PaddingHorizontal + Padding, total vertical padding is the sum PaddingVertical + Padding.

Published property PaddingVertical: Single read FPaddingVertical write SetPaddingVertical default 0;

This item has no description.

Published property Padding: Single read FPadding write SetPadding default 0;

This item has no description.

Published property LineSpacing: Single read FLineSpacing write FLineSpacing default DefaultLineSpacing;

Extra spacing between lines. May be negative to squeeze lines tighter together.

Published property Html: boolean read FHtml write SetHtml default false;

Does the text use HTML markup. This allows to easily change colors or use bold, italic text.

See the example examples/fonts/html_text.lpr and examples/fonts/html_text_demo.html for a demo of what HTML tags can do. See TCastleAbstractFont.PrintStrings documentation for a list of support HTML markup.

Note that to see the bold/italic font variants in the HTML markup, you need to set the font to be TCastleFontFamily with bold/italic variants. See the example mentioned above, examples/fonts/html_text.lpr, for a code how to do it.

Published property Tags: boolean read FHtml write SetHtml stored false default false; deprecated 'use Html instead';

Warning: this symbol is deprecated: use Html instead

This item has no description.

Published property Frame: boolean read FFrame write FFrame default false; deprecated 'display frame around label using Border or parent UI control';

Warning: this symbol is deprecated: display frame around label using Border or parent UI control

Draw frame around the text. Frame uses theme image tiLabel, see TCastleTheme.Images if you want to customize it.

Published property MaxWidth: Single read FMaxWidth write SetMaxWidth default 0;

If non-zero, limit the width of resulting label. The text will be broken in the middle of lines, to make it fit (together with PaddingHorizontal) inside MaxWidth.

Published property Alignment: THorizontalPosition read FAlignment write SetAlignment default hpLeft;

Horizontal alignment of the text.

Published property VerticalAlignment: TVerticalPosition read FVerticalAlignment write SetVerticalAlignment default vpBottom;

Vertical alignment of the text. Usually you don't want to use this, instead leave AutoSize = True and align the label to the parent using anchors, like MyLabel.Anchor(vpMiddle); or MyLabel.Anchor(vpTop);.

This property is useful if you really need to manually control the size. It only matters when AutoSize is False. Then it controls where the text is, with respect to it's rectangle defined by properties like Height or FullSize.

Published property MaxDisplayChars: Integer read FMaxDisplayChars write SetMaxDisplayChars default -1;

Limit the displayed label text, if not -1. This doesn't affect the label size, only the rendered text. It's nice to show the animation of text "expanding", filling some area. Use DisplayChars as the maximum sensible value for this.

Published property CaptionTranslate: Boolean read FCaptionTranslate write FCaptionTranslate default true;

Should the Caption be localized (translated into other languages). Determines if the property is enumerated by TCastleComponent.TranslateProperties, which affects the rest of localization routines.

Published property ColorPersistent: TCastleColorPersistent read FColorPersistent ;

Color that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write Color directly.

See also
Color
Text color.
Published property FrameColorPersistent: TCastleColorPersistent read FFrameColorPersistent ;

FrameColor that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write FrameColor directly.

See also
FrameColor
Color tint of the background image, see Frame.

Generated by PasDoc 0.16.0-snapshot.