Class TCastleEdit
Unit
Declaration
type TCastleEdit = class(TCastleUserInterfaceFont)
Description
Edit box to input a single line of text. The contents are in the Text property, you can get or set them at any time.
Note that you should set a suitable TCastleUserInterface.Width of the edit box, to nicely display a typical content. The height is by default auto-calculated (see AutoSizeHeight) looking at font size (and other properties, like padding and frame size), and usually is reasonable automatically.
Hierarchy
- TObject
- TPersistent
- TComponent
- TCastleComponent
- TCastleUserInterface
- TCastleUserInterfaceFont
- TCastleEdit
Overview
Fields
nested const DefaultPadding = 4; |
|
nested const DefaultAutoOnScreenKeyboard = false; |
Methods
procedure PreferredSize(var PreferredWidth, PreferredHeight: Single); override; |
|
function GetInternalText: String; override; |
|
procedure SetInternalText(const Value: String); override; |
|
procedure DoChange; virtual; |
|
procedure TranslateProperties(const TranslatePropertyEvent: TTranslatePropertyEvent); override; |
|
constructor Create(AOwner: TComponent); override; |
|
destructor Destroy; override; |
|
procedure Render; override; |
|
function Press(const Event: TInputPressRelease): boolean; override; |
|
procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override; |
|
function CapturesEventsAtPosition(const Position: TVector2): boolean; override; |
|
procedure SetFocused(const Value: boolean); override; |
|
procedure EditorAllowResize( out ResizeWidth, ResizeHeight: Boolean; out Reason: String); override; |
|
function PropertySections(const PropertyName: String): TPropertySections; override; |
Properties
property FocusedColor: TCastleColor read FFocusedColor write SetFocusedColor; |
|
property UnfocusedColor: TCastleColor read FUnfocusedColor write SetUnfocusedColor; |
|
property PlaceholderColor: TCastleColor read FPlaceholderColor write SetPlaceholderColor; |
|
property BackgroundColor: TCastleColor read FBackgroundColor write SetBackgroundColor; |
|
property AllowedChars: TSetOfChars read FAllowedChars write FAllowedChars; |
|
property MaxLength: Cardinal read FMaxLength write FMaxLength; |
|
property Text: String read FText write SetText; |
|
property PaddingHorizontal: Single
read FPaddingHorizontal write SetPaddingHorizontal default 0; |
|
property PaddingVertical: Single
read FPaddingVertical write SetPaddingVertical default 0; |
|
property Padding: Single
read FPadding write SetPadding default DefaultPadding; |
|
property Frame: boolean read FFrame write SetFrame default true; |
|
property CaptureAllInput: boolean read FCaptureAllInput write FCaptureAllInput; deprecated 'use Container.ForceCaptureInput instead of this'; |
|
property AutoOnScreenKeyboard: Boolean
read FAutoOnScreenKeyboard write FAutoOnScreenKeyboard
default DefaultAutoOnScreenKeyboard; |
|
property AutoSizeHeight: Boolean
read FAutoSizeHeight write SetAutoSizeHeight default true; |
|
property Placeholder: String
read FPlaceholder write SetPlaceholder; |
|
property OnChange: TNotifyEvent read FOnChange write FOnChange; |
|
property PasswordChar: Char
read FPasswordChar write SetPasswordChar default #0; |
|
property TextTranslate: Boolean read FTextTranslate write FTextTranslate default true; |
|
property PlaceholderTranslate: Boolean read FPlaceholderTranslate write FPlaceholderTranslate default true; |
|
property Alignment: THorizontalPosition
read FAlignment write SetAlignment default hpLeft; |
|
property Enabled: boolean read FEnabled write SetEnabled default true; |
|
property FocusedColorPersistent: TCastleColorPersistent read FFocusedColorPersistent ; |
|
property UnfocusedColorPersistent: TCastleColorPersistent read FUnfocusedColorPersistent ; |
|
property PlaceholderColorPersistent: TCastleColorPersistent read FPlaceholderColorPersistent ; |
|
property BackgroundColorPersistent: TCastleColorPersistent read FBackgroundColorPersistent ; |
Description
Fields
nested const DefaultPadding = 4; |
|
This item has no description. |
nested const DefaultAutoOnScreenKeyboard = false; |
|
This item has no description. |
Methods
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. |
function GetInternalText: String; override; |
|
This item has no description. |
procedure SetInternalText(const Value: String); override; |
|
This item has no description. |
procedure DoChange; virtual; |
|
This item has no description. |
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. |
constructor Create(AOwner: TComponent); override; |
|
This item has no description. |
destructor Destroy; override; |
|
This item has no description. |
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:
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). |
function Press(const Event: TInputPressRelease): boolean; override; |
|
This item has no description. Showing description inherited from TCastleUserInterface.Press.
Override this method to react to user pressing a key, mouse button or mouse wheel. Return When implementing in descendants it is best to override it like this: function TMyControl.Press(const Event: TInputPressRelease): boolean; begin Result := inherited; if Result then Exit; // exit if ancestor already handled this event if Event.IsKey(keyEnter) then begin // do something in reaction to Enter key ... // let engine know that this input event was handled Exit(true); end; if Event.IsMouseButton(buttonLeft) then begin // do something in reaction to left mouse button press ... // let engine know that this input event was handled Exit(true); end; end;
These events are generated for all UI controls, whether they are considered "interactive" or not. These events are generated for non-interactive controls like TCastleRectangleControl or TCastleLabel as well. For example, these events ignore the TCastleButton.Enabled state, they are generated always (see https://github.com/castle-engine/castle-engine/issues/413 ). Use instead TCastleButton.OnClick to detect clicks on a button in a way that honors the TCastleButton.Enabled state. When a control returns The events Press and Release are passed to the parent only after the children had a chance to process this event. Overriding them makes sense if you draw something that "looks clickable" in TCastleUserInterface.Render, which is the standard place you should draw stuff. For example our TCastleButton draws there. In contrast, the events PreviewPress and PreviewRelease are passed first to the parent control, before children have a chance to process this event. In partcular, overriding them makes sense if you draw something that "looks clickable" in TCastleUserInterface.RenderOverChildren. |
procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override; |
|
This item has no description. Showing description inherited from TCastleUserInterface.Update. Control may do here anything that must be continuously repeated. E.g. camera handles here falling down due to gravity, rotating model in Examine mode, and many more.
This method may be used, among many other things, to continuously react to the fact that user pressed some key (or mouse button). For example, if holding some key should move some 3D object, you should do something like: if HandleInput then begin if Container.Pressed[keyArrowRight] then begin Transform.Position := Transform.Position + Vector3(SecondsPassed * 10, 0, 0); HandleInput := false; end; end;
Instead of directly using a key code, consider also using TInputShortcut that makes the input key nicely configurable. See engine tutorial about handling inputs. Multiplying movement by SecondsPassed makes your operation frame-rate independent. Object will move by 10 units in a second, regardless of how many FPS your game has. The code related to HandleInput is important if you write a generally-useful control that should nicely cooperate with all other controls, even when placed on top of them or under them. The correct approach is to only look at pressed keys/mouse buttons if HandleInput is Note that to handle a single press / release (like "switch light on when pressing a key") you should rather use Press and Release methods. Use this method only for continuous handling (like "holding this key makes the light brighter and brighter"). To understand why such HandleInput approach is needed, realize that the "Update" events are called differently than simple mouse and key events like "Press" and "Release". "Press" and "Release" events return whether the event was somehow "handled", and the container passes them only to the controls under the mouse (decided by TCastleUserInterface.CapturesEventsAtPosition). And as soon as some control says it "handled" the event, other controls (even if under the mouse) will not receive the event. This approach is not suitable for Update events. Some controls need to do the Update job all the time, regardless of whether the control is under the mouse and regardless of what other controls already did. So all controls (well, all controls that exist, in case of TCastleUserInterface, see TCastleUserInterface.Exists) receive Update calls. So the "handled" status is passed through HandleInput. If a control is not under the mouse, it will receive HandleInput = |
function CapturesEventsAtPosition(const Position: TVector2): boolean; override; |
|
This item has no description. Showing description inherited from TCastleUserInterface.CapturesEventsAtPosition.
Does this control capture events under this container position. The default implementation simply checks whether Position is inside RenderRect. It also checks whether CapturesEvents is Always treated like |
procedure SetFocused(const Value: boolean); override; |
|
This item has no description. Showing description inherited from TCastleUserInterface.SetFocused. Called when this control becomes or stops being focused, that is: under the mouse cursor and will receive events. This updates Focused property. This also calls OnInternalMouseEnter / OnInternalMouseLeave. |
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. |
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. |
Properties
property FocusedColor: TCastleColor read FFocusedColor write SetFocusedColor; |
|
Focused text color. By default it's black. |
property UnfocusedColor: TCastleColor read FUnfocusedColor write SetUnfocusedColor; |
|
Unfocused text color. By default it's dark gray. |
property PlaceholderColor: TCastleColor read FPlaceholderColor write SetPlaceholderColor; |
|
Color for Placeholder. By default it's light gray. |
property BackgroundColor: TCastleColor read FBackgroundColor write SetBackgroundColor; |
|
Background color. Fills the area under Text and the padding. By default it's white. Note that it can be transparent, in which case it will show the tiEdit image underneath (if Frame is |
property AllowedChars: TSetOfChars read FAllowedChars write FAllowedChars; |
|
Allowed characters that user can input. Note that this only restricts the user input, it does not prevent from programmatically setting Text to include disallowed characters. |
property MaxLength: Cardinal read FMaxLength write FMaxLength; |
|
Max length of user input. Value of 0 (default) means "no limit". Note that this only restricts the user input, it does not prevent from programmatically setting Text to be longer. |
property Text: String read FText write SetText; |
|
Currently input text. |
property PaddingHorizontal: Single
read FPaddingHorizontal write SetPaddingHorizontal default 0; |
|
Inside the box rectangle, padding between the borders (or frame, if Frame) and text. Total horizontal padding is the sum |
property PaddingVertical: Single
read FPaddingVertical write SetPaddingVertical default 0; |
|
This item has no description. |
property Padding: Single
read FPadding write SetPadding default DefaultPadding; |
|
This item has no description. |
property Frame: boolean read FFrame write SetFrame default true; |
|
Draw frame around the box. Frame uses theme image tiEdit, see TCastleTheme.Images if you want to customize it. |
property AutoOnScreenKeyboard: Boolean
read FAutoOnScreenKeyboard write FAutoOnScreenKeyboard
default DefaultAutoOnScreenKeyboard; |
|
Shows the software (on-screen) keyboard on mobile devices automatically when the edit box gets focused. For now, this only works on Android (not iOS yet – see https://github.com/castle-engine/castle-engine/issues/554). This requires adding |
property AutoSizeHeight: Boolean
read FAutoSizeHeight write SetAutoSizeHeight default true; |
|
This item has no description. |
property Placeholder: String
read FPlaceholder write SetPlaceholder; |
|
Displayed when Text is empty. |
property OnChange: TNotifyEvent read FOnChange write FOnChange; |
|
Event sent when Text value was changed by a user. Note that this is not called when you change Text property programmatically. |
property TextTranslate: Boolean read FTextTranslate write FTextTranslate default true; |
|
Should the Text be localized (translated into other languages). Determines if the property is enumerated by TCastleComponent.TranslateProperties, which affects the rest of localization routines. |
property PlaceholderTranslate: Boolean read FPlaceholderTranslate write FPlaceholderTranslate default true; |
|
Should the Placeholder be localized (translated into other languages). Determines if the property is enumerated by TCastleComponent.TranslateProperties, which affects the rest of localization routines. |
property Alignment: THorizontalPosition
read FAlignment write SetAlignment default hpLeft; |
|
Horizontal alignment of the text. |
property Enabled: boolean read FEnabled write SetEnabled default true; |
|
Enabled control can be focused and edited, is not grayed-out. |
property FocusedColorPersistent: TCastleColorPersistent read FFocusedColorPersistent ; |
|
FocusedColor 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 FocusedColor directly. See also
|
property UnfocusedColorPersistent: TCastleColorPersistent read FUnfocusedColorPersistent ; |
|
UnfocusedColor 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 UnfocusedColor directly. See also
|
property PlaceholderColorPersistent: TCastleColorPersistent read FPlaceholderColorPersistent ; |
|
PlaceholderColor 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 PlaceholderColor directly. See also
|
property BackgroundColorPersistent: TCastleColorPersistent read FBackgroundColorPersistent ; |
|
BackgroundColor 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 BackgroundColor directly. See also
|
Generated by PasDoc 0.16.0-snapshot.