Class TCastleSwitchControl

Unit

Declaration

type TCastleSwitchControl = class(TCastleUserInterface)

Description

Warning: this symbol is deprecated: use TCastleCheckbox or TCastleButton with TCastleButton.Toggle=true and custom backgrounds

Touch-friendly checkbox control representing on/off state.

Hierarchy

Overview

Fields

Public nested const DefaultSwitchControlWidth = 50;
Public nested const DefaultSwitchControlHeight = 28;

Methods

Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure Render; override;
Public function Press(const Event: TInputPressRelease): boolean; override;
Public function Release(const Event: TInputPressRelease): boolean; override;
Public function PropertySections(const PropertyName: String): TPropertySections; override;

Properties

Public property IsOn: boolean read FChecked write SetChecked default false; deprecated 'use Checked instead, consistent with LCL TCheckBox.Checked';
Published property Checked: boolean read FChecked write SetChecked default false;
Published property Enabled: boolean read FEnabled write SetEnabled default true;
Published property OnChange: TNotifyEvent read FOnChange write FOnChange;
Published property Width default DefaultSwitchControlWidth;
Published property Height default DefaultSwitchControlHeight;

Description

Fields

Public nested const DefaultSwitchControlWidth = 50;

This item has no description.

Public nested const DefaultSwitchControlHeight = 28;

This item has no description.

Methods

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 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 True if the event was handled, which prevents from passing this event to other UI controls.

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 True from Press, it means it starts to "capture" subsequent mouse events: subsequent mouse moves and release will be send to this control even if mouse will move outside of this control.

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.

Public function Release(const Event: TInputPressRelease): boolean; override;

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

Override this method to react to user releasing a key, mouse button. Return True if the event was handled, which prevents from passing this event to other UI controls.

This is counterpart to Press method. See Press for more details.

Note: We'd like this method to also be called when user releases a mouse wheel. But currently releasing of the mouse wheel is not reported now by any backend. Only releasing of keys and mouse buttons is reported.

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.

Properties

Public property IsOn: boolean read FChecked write SetChecked default false; deprecated 'use Checked instead, consistent with LCL TCheckBox.Checked';

Warning: this symbol is deprecated: use Checked instead, consistent with LCL TCheckBox.Checked

This item has no description.

Published property Checked: boolean read FChecked write SetChecked default false;

Switch state.

Published property Enabled: boolean read FEnabled write SetEnabled default true;

This item has no description.

Published property OnChange: TNotifyEvent read FOnChange write FOnChange;

Event sent when Checked value was changed by a user click. Note that this is not called when you change Checked property programmatically by setting the property.

Published property Width default DefaultSwitchControlWidth;

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

These properties determine the control size. See the EffectiveRect documentation for details how the size is calculated.

Published property Height default DefaultSwitchControlHeight;

This item has no description.


Generated by PasDoc 0.16.0-snapshot.