Castle Game EngineIntroduction Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers
|
Class TCastleButton
Unit
CastleControls
Declaration
type TCastleButton = class(TUIControlFont)
Description
Clickable button.
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
Description
Fields
 |
internal const DefaultImageMargin = 10; |
|
 |
internal const DefaultPaddingHorizontal = 10; |
|
 |
internal const DefaultPaddingVertical = 10; |
|
 |
internal const DefaultLineSpacing = 2; |
|
 |
internal const DefaultTextAlignment = hpMiddle; |
|
Methods
 |
procedure SetPressed(const Value: boolean); virtual; |
|
 |
procedure UIScaleChanged; override; |
|
 |
constructor Create(AOwner: TComponent); override; |
|
 |
destructor Destroy; override; |
|
 |
procedure Render; override; |
|
 |
procedure GLContextOpen; override; |
|
 |
procedure GLContextClose; override; |
|
 |
function Motion(const Event: TInputMotion): boolean; override; |
|
 |
procedure FontChanged; 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 TintPressed : TCastleColor read FTintPressed write FTintPressed; |
Color tint when button is pressed (regardless if enabled or disabled). Opaque white by default.
|
 |
property TintDisabled: TCastleColor read FTintDisabled write FTintDisabled; |
Color tint when button is disabled (and not pressed). Opaque white by default.
|
 |
property TintFocused : TCastleColor read FTintFocused write FTintFocused; |
Color tint when button is focused. Opaque white by default.
|
 |
property TintNormal : TCastleColor read FTintNormal write FTintNormal; |
Color tint when button is enabled, but neither pressed nor focused. Opaque white by default.
|
 |
property CustomBackground: boolean read FCustomBackground write FCustomBackground default false; |
Use custom background images. If True , we use properties
. They are rendered as 3x3 images (see TGLImageCore.Draw3x3) with corners specified by CustomBackgroundCorners.
|
 |
property CustomBackgroundPressed: TCastleImage read FCustomBackgroundPressed write SetCustomBackgroundPressed; |
Background image on the pressed button. See CustomBackground for details.
|
 |
property OwnsCustomBackgroundPressed: boolean read FOwnsCustomBackgroundPressed write FOwnsCustomBackgroundPressed default false; |
Should we free CustomBackgroundPressed image when you set another one or at destructor.
|
 |
property CustomBackgroundDisabled: TCastleImage read FCustomBackgroundDisabled write SetCustomBackgroundDisabled; |
Background image on the disabled button. See CustomBackground for details.
|
 |
property OwnsCustomBackgroundDisabled: boolean read FOwnsCustomBackgroundDisabled write FOwnsCustomBackgroundDisabled default false; |
Should we free CustomBackgroundDisabled image when you set another one or at destructor.
|
 |
property CustomBackgroundFocused: TCastleImage read FCustomBackgroundFocused write SetCustomBackgroundFocused; |
Background image on the focused button. See CustomBackground for details.
|
 |
property OwnsCustomBackgroundFocused: boolean read FOwnsCustomBackgroundFocused write FOwnsCustomBackgroundFocused default false; |
Should we free CustomBackgroundFocused image when you set another one or at destructor.
|
 |
property CustomBackgroundNormal: TCastleImage read FCustomBackgroundNormal write SetCustomBackgroundNormal; |
Background image on the normal button. See CustomBackground for details.
|
 |
property OwnsCustomBackgroundNormal: boolean read FOwnsCustomBackgroundNormal write FOwnsCustomBackgroundNormal default false; |
Should we free CustomBackgroundNormal image when you set another one or at destructor.
|
 |
property CustomBackgroundCorners: TVector4Integer read FCustomBackgroundCorners write FCustomBackgroundCorners; |
Corners used when rendering custom background images. See CustomBackground for details. Zero by default.
|
 |
property CustomTextColorUse: boolean read FCustomTextColorUse write FCustomTextColorUse; |
Should we use custom text color in CustomTextColor instead of Theme.TextColor or Theme.DisabledTextColor .
|
 |
property CustomTextColor: TCastleColor read FCustomTextColor write FCustomTextColor; |
Text color to use if CustomTextColorUse is True . Black by default, just like Theme.TextColor .
|
 |
property LineSpacing: Integer read FLineSpacing write SetLineSpacing
default DefaultLineSpacing; |
For multi-line Caption, the extra spacing between lines. May also be negative to squeeze lines tighter.
|
 |
property Html: boolean read FHtml write SetHtml default false; |
Enable HTML tags in the Caption. 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 TCastleFont.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 TFontFamily with bold/italic variants. See the example mentioned above, examples/fonts/html_text.lpr, for a code how to do it.
|
 |
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; |
Horizontal distance between text or Image and the button border.
|
 |
property PaddingVertical: Cardinal
read FPaddingVertical write FPaddingVertical default DefaultPaddingVertical; |
Vertical distance between text or Image and the button border.
|
 |
property AutoSize: boolean read FAutoSize write SetAutoSize default true; |
When AutoSize is True (the default) then button sizes are automatically calculated when you change the Caption and Image. The calculated size takes into account the Caption text size (with current font), and Image size, plus some margin to make it look nice.
Width is auto-calculated only when AutoSize and AutoSizeWidth (otherwise we just use Width property value). Likewise, Height is calculated only when AutoSize and AutoSizeHeight (otherwise we just use Height property value). 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 ).
If needed, you can query the resulting button size with the standard TUIControl methods like TUIControl.CalculatedWidth and TUIControl.CalculatedHeight. Note that they may not be available before the button is actually added to the container, and the container size is initialized (we need to know the size of container, for UI scaling to determine the font size).
|
 |
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; |
Caption to display on the button. The text may be multiline (use the LineEnding or NL constants to mark newlines).
|
 |
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; |
Distance between text and Image. Unused if Image not set.
|
 |
property Enabled: boolean read FEnabled write SetEnabled default true; |
|
 |
property EnableParentDragging: boolean
read FEnableParentDragging write FEnableParentDragging default false; |
Enable to drag a parent control, for example to drag a TCastleScrollView that contains this button. To do this, you need to turn on TCastleScrollView.EnableDragging, and set EnableParentDragging =True on all buttons inside. In effect, buttons will cancel the click operation once you start dragging, which allows the parent to handle all the motion events for dragging.
|
Generated by PasDoc 0.15.0.
|