Class TCastleButton
Unit
CastleControls
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
Methods
Properties
 |
property Image: TCastleImage read FImage write SetImage; |
 |
property OwnsImage: boolean read FOwnsImage write FOwnsImage default false; |
 |
property MinImageWidth: Cardinal read FMinImageWidth write FMinImageWidth default 0; |
 |
property MinImageHeight: Cardinal read FMinImageHeight write FMinImageHeight default 0; |
 |
property Width: Cardinal read FWidth write SetWidth default 0; |
 |
property Height: Cardinal read FHeight write SetHeight default 0; |
 |
property PaddingHorizontal: Cardinal
read FPaddingHorizontal write FPaddingHorizontal default DefaultPaddingHorizontal; |
 |
property PaddingVertical: Cardinal
read FPaddingVertical write FPaddingVertical default DefaultPaddingVertical; |
 |
property AutoSize: boolean read FAutoSize write SetAutoSize default true; |
 |
property AutoSizeWidth: boolean read FAutoSizeWidth write SetAutoSizeWidth default true; |
 |
property AutoSizeHeight: boolean read FAutoSizeHeight write SetAutoSizeHeight default true; |
 |
property MinWidth: Cardinal read FMinWidth write SetMinWidth default 0; |
 |
property MinHeight: Cardinal read FMinHeight write SetMinHeight default 0; |
 |
property OnClick: TNotifyEvent read FOnClick write FOnClick; |
 |
property Caption: string read FCaption write SetCaption; |
 |
property Toggle: boolean read FToggle write FToggle default false; |
 |
property Pressed: boolean read FPressed write SetPressed default false; |
 |
property ImageLayout: TCastleButtonImageLayout
read FImageLayout write SetImageLayout default ilLeft; |
 |
property ImageAlphaTest: boolean
read FImageAlphaTest write FImageAlphaTest default false; |
 |
property ImageMargin: Cardinal read FImageMargin write SetImageMargin
default DefaultImageMargin; |
Description
Fields
 |
internal const DefaultImageMargin = 10; |
|
 |
internal const DefaultPaddingHorizontal = 10; |
|
 |
internal const DefaultPaddingVertical = 10; |
|
Methods
 |
procedure FontChanged; override; |
|
 |
constructor Create(AOwner: TComponent); override; |
|
 |
destructor Destroy; override; |
|
 |
procedure Render; override; |
|
 |
function PositionInside(const Position: TVector2Single): boolean; override; |
|
 |
procedure GLContextOpen; override; |
|
 |
procedure GLContextClose; override; |
|
 |
procedure DoClick; virtual; |
Called when user clicks the button. In this class, simply calls OnClick callback.
|
 |
procedure SetFocused(const Value: boolean); override; |
|
Properties
 |
property Image: TCastleImage read FImage write SetImage; |
Set this to non-nil to display an image on the button.
|
 |
property OwnsImage: boolean read FOwnsImage write FOwnsImage default false; |
Should we free the Image when you set another one or at destructor.
|
 |
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.
|
 |
property MinImageHeight: Cardinal read FMinImageHeight write FMinImageHeight default 0; |
|
 |
property Width: Cardinal read FWidth write SetWidth default 0; |
|
 |
property Height: Cardinal read FHeight write SetHeight default 0; |
|
 |
property PaddingVertical: Cardinal
read FPaddingVertical write FPaddingVertical default DefaultPaddingVertical; |
|
 |
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.
|
 |
property AutoSizeWidth: boolean read FAutoSizeWidth write SetAutoSizeWidth default true; |
|
 |
property AutoSizeHeight: boolean read FAutoSizeHeight write SetAutoSizeHeight default true; |
|
 |
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.
|
 |
property MinHeight: Cardinal read FMinHeight write SetMinHeight default 0; |
|
 |
property OnClick: TNotifyEvent read FOnClick write FOnClick; |
|
 |
property Caption: string read FCaption write SetCaption; |
|
 |
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.
|
 |
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.
|
 |
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).
|
 |
property ImageMargin: Cardinal read FImageMargin write SetImageMargin
default DefaultImageMargin; |
|
|