Class TCastleButton

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TCastleButton = class(TUIControlFont)

Description

Button inside OpenGL context.

This is TUIControl descendant, so to use it just add it to the TCastleWindowCustom.Controls or TCastleControlCustom.Controls list. You will also usually want to adjust position (TCastleButton.Left, TCastleButton.Bottom), TCastleButton.Caption, and assign TCastleButton.OnClick (or ovevrride TCastleButton.DoClick).

Hierarchy

Overview

Fields

Public internal const DefaultImageMargin = 10;
Public internal const DefaultPaddingHorizontal = 10;
Public internal const DefaultPaddingVertical = 10;

Methods

Protected procedure FontChanged; override;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure Render; override;
Public function PositionInside(const Position: TVector2Single): boolean; override;
Public procedure GLContextOpen; override;
Public procedure GLContextClose; override;
Public function Press(const Event: TInputPressRelease): boolean; override;
Public function Release(const Event: TInputPressRelease): boolean; override;
Public function Rect: TRectangle; override;
Public procedure DoClick; virtual;
Public procedure SetFocused(const Value: boolean); override;

Properties

Public property Image: TCastleImage read FImage write SetImage;
Public property OwnsImage: boolean read FOwnsImage write FOwnsImage default false;
Public property MinImageWidth: Cardinal read FMinImageWidth write FMinImageWidth default 0;
Public property MinImageHeight: Cardinal read FMinImageHeight write FMinImageHeight default 0;
Published property Width: Cardinal read FWidth write SetWidth default 0;
Published property Height: Cardinal read FHeight write SetHeight default 0;
Published property PaddingHorizontal: Cardinal read FPaddingHorizontal write FPaddingHorizontal default DefaultPaddingHorizontal;
Published property PaddingVertical: Cardinal read FPaddingVertical write FPaddingVertical default DefaultPaddingVertical;
Published property AutoSize: boolean read FAutoSize write SetAutoSize default true;
Published property AutoSizeWidth: boolean read FAutoSizeWidth write SetAutoSizeWidth default true;
Published property AutoSizeHeight: boolean read FAutoSizeHeight write SetAutoSizeHeight default true;
Published property MinWidth: Cardinal read FMinWidth write SetMinWidth default 0;
Published property MinHeight: Cardinal read FMinHeight write SetMinHeight default 0;
Published property OnClick: TNotifyEvent read FOnClick write FOnClick;
Published property Caption: string read FCaption write SetCaption;
Published property Toggle: boolean read FToggle write FToggle default false;
Published property Pressed: boolean read FPressed write SetPressed default false;
Published property ImageLayout: TCastleButtonImageLayout read FImageLayout write SetImageLayout default ilLeft;
Published property ImageAlphaTest: boolean read FImageAlphaTest write FImageAlphaTest default false;
Published property ImageMargin: Cardinal read FImageMargin write SetImageMargin default DefaultImageMargin;

Description

Fields

Public internal const DefaultImageMargin = 10;
 
Public internal const DefaultPaddingHorizontal = 10;
 
Public internal const DefaultPaddingVertical = 10;
 

Methods

Protected procedure FontChanged; override;
 
Public constructor Create(AOwner: TComponent); override;
 
Public destructor Destroy; override;
 
Public procedure Render; override;
 
Public function PositionInside(const Position: TVector2Single): boolean; override;
 
Public procedure GLContextOpen; override;
 
Public procedure GLContextClose; override;
 
Public function Press(const Event: TInputPressRelease): boolean; override;
 
Public function Release(const Event: TInputPressRelease): boolean; override;
 
Public function Rect: TRectangle; override;
 
Public procedure DoClick; virtual;

Called when user clicks the button. In this class, simply calls OnClick callback.

Public procedure SetFocused(const Value: boolean); override;
 

Properties

Public property Image: TCastleImage read FImage write SetImage;

Set this to non-nil to display an image on the button.

Public property OwnsImage: boolean read FOwnsImage write FOwnsImage default false;

Should we free the Image when you set another one or at destructor.

Public property MinImageWidth: Cardinal read FMinImageWidth write FMinImageWidth default 0;

Auto-size routines (see AutoSize) may treat the image like always having at least these minimal sizes. Even if the Image is empty (Nil). This is useful when you have a row of buttons (typical for toolbar), and you want them to have the same height, and their captions to be displayed at the same level, regardless of their images sizes.

Public property MinImageHeight: Cardinal read FMinImageHeight write FMinImageHeight default 0;
 
Published property Width: Cardinal read FWidth write SetWidth default 0;
 
Published property Height: Cardinal read FHeight write SetHeight default 0;
 
Published property PaddingHorizontal: Cardinal read FPaddingHorizontal write FPaddingHorizontal default DefaultPaddingHorizontal;
 
Published property PaddingVertical: Cardinal read FPaddingVertical write FPaddingVertical default DefaultPaddingVertical;
 
Published property AutoSize: boolean read FAutoSize write SetAutoSize default true;

When AutoSize is True (the default) then Width/Height are automatically adjusted when you change the Caption and Image. They take into account Caption width/height with current font, Image width/height, and add some margin to make it look good.

To be more precise, Width is adjusted only when AutoSize and AutoSizeWidth. And Height is adjusted only when AutoSize and AutoSizeHeight. This way you can turn off auto-sizing in only one dimension if you want (and when you don't need such flexibility, leave AutoSizeWidth = AutoSizeHeight = True and control both by simple AutoSize).

Note that this adjustment happens only when OpenGL context is initialized (because only then we actually know the font used). So don't depend on Width/Height values calculated correctly before OpenGL context is ready.

Published property AutoSizeWidth: boolean read FAutoSizeWidth write SetAutoSizeWidth default true;
 
Published property AutoSizeHeight: boolean read FAutoSizeHeight write SetAutoSizeHeight default true;
 
Published property MinWidth: Cardinal read FMinWidth write SetMinWidth default 0;

When auto-size is in effect, these properties may force a minimal width/height of the button. This is useful if you want to use auto-size (to make sure that the content fits inside), but you want to force filling some space.

Published property MinHeight: Cardinal read FMinHeight write SetMinHeight default 0;
 
Published property OnClick: TNotifyEvent read FOnClick write FOnClick;
 
Published property Caption: string read FCaption write SetCaption;
 
Published property Toggle: boolean read FToggle write FToggle default false;

Can the button be permanently pressed. Good for making a button behave like a checkbox, that is indicate a boolean state. When Toggle is True, you can set the Pressed property, and the clicks are visualized a little differently.

Published property Pressed: boolean read FPressed write SetPressed default false;

Is the button pressed down. If Toggle is True, you can read and write this property to set the pressed state.

When not Toggle, this property isn't really useful to you. The pressed state is automatically managed then to visualize user clicks. In this case, you can read this property, but you cannot reliably set it.

Published property ImageLayout: TCastleButtonImageLayout read FImageLayout write SetImageLayout default ilLeft;

Where the Image is drawn on a button.

Published property ImageAlphaTest: boolean read FImageAlphaTest write FImageAlphaTest default false;

If the image has alpha channel, should we render with alpha test (simple yes/no transparency) or alpha blending (smootly mix with background using full transparency).

Published property ImageMargin: Cardinal read FImageMargin write SetImageMargin default DefaultImageMargin;
 

Generated by PasDoc 0.14.0.