public class Editor.Widget : Editor.QObject
A generic widget.
Related Guides
Broader workflow and conceptual references connected to this API.
When creating your own Classes/Structs/Assets/ect, you'll sometimes want custom editors that pair with them. For example, a Gradient Editor so you can visually see what the Gradient looks like instead of editing the Gradient as if it were a Struct with a list of Colours.
Editor Events are events that are broadcast globally throughout the editor and can be listened to/fired from any Editor Project. These are useful for creating your own custom Editor Tools and making sure they can work in tandem with existing systems.
When creating a Tool or Editor Project, it's common to want to be able to trigger certain actions with a key press or combined keystroke (Like O to enter Object Mode, or SHIFT+B to enter the Block Tool).
You can create your own editor tool to help you create your game. Your tool needs to be created in an editor project.
Editor UI is built entirely out of Widgets. Widgets are different from Panels, which are used for in-game UI. Widgets can be various elements or components, such as labels, buttons, text boxes, trees, or images.
The s&box editor is your workspace for building games — scene editing, asset management, visual scripting, and more.
Constructors
Showing 2 constructors
No results match this filter.
Methods
Showing 76 methods
public void AdjustSize()
Adjusts the size of the widget to fit its contents.
public virtual void AlignToParent(Sandbox.TextFlag alignment, Vector2 offset = null)
Align this widget to its parents edge, with an offset.
Parameters
offset: Default: null
public void Blur()
Clear keyboard focus from this widget.
public virtual void ChildValuesChanged(Editor.Widget source)
public void ClearContext(string key)
Remove a context on this widget. This will NOT remove contexts set from parent objects.
public virtual void Close()
If a window - will close
public void ConstrainTo(Sandbox.Rect parentRect)
Reposition this widget to ensure it is within the given rectangle.
Parameters
parentRect: Rectangle to constraint to, relative to the parent widget.
public void ConstrainToScreen()
Constrain this widget to the screen it's currently on.
public void DestroyChildren()
Destroys all child widgets of this widget.
public void DisableWindowActivation()
Calling this will set the WS_EX_NOACTIVATE flag on the window internally, which will stop it taking focus away from other windows.
protected virtual void DoLayout()
Called to make sure all child panels are in correct positions and have correct sizes. This is typically called when the size of this widget changes, but there are other cases as well.
public void Focus(bool activateWindow = True)
Parameters
activateWindow: Default: True
protected virtual bool FocusNext()
Called when Tab is pressed to find the next widget to focus. Return true to prevent focusing.
protected virtual bool FocusPrevious()
Called when Shift + Tab is pressed to find the next widget to focus. Return true to prevent focusing.
public Vector2 FromScreen(Vector2 p)
Transform coordinates relative to the monitors's top left corner, to coordinates relative to panel's top left corner.
Parameters
p: Position relative to the monitors top left corner.
Returns
The same position on the panel, relative it its top left corner.
public T GetAncestor()
Find the closest ancestor widget of type
public T GetContext(string key, T defaultIfMissing = null)
Find a context on this widget. If not found, look at the parent. If not found, look at the parent. This is useful for passing information down to child widgets without any effort.
Parameters
defaultIfMissing: Default: null
public System.Collections.Generic.IEnumerable`1<T> GetDescendants()
Get all descendants of type T
public Editor.Widget GetWindow()
Get the top level window widget
public virtual void Hide()
Make this widget not visible.
public bool IsAncestorOf(Editor.Widget child)
Returns whether or not the specified Widget is an ancestor of this Widget.
public bool IsDescendantOf(Editor.Widget parent)
Returns whether or not the specified Widget is a descendent of this Widget.
public bool IsModal()
Returns true if this is a modal window. This means it will appear on top of everything and block input to everything else.
public void Lower()
Lowers the widget to the bottom of the parent widget's stack. After this call the widget will be visually behind (and therefore obscured by) any overlapping sibling widgets.
public void MakeMaximized()
public void MakeMinimized()
public void MakeSignal(string name)
public void MakeWindowed()
protected virtual Vector2 MinimumSizeHint()
Return the minimum size this widget wants to be
protected virtual void OnBlur(Editor.FocusChangeReason reason)
Called when the widget loses keyboard focus.
protected virtual bool OnClose()
Called when a window is about to be closed.
protected virtual void OnClosed()
Called when a window is closed.
protected virtual void OnContextMenu(Editor.ContextMenuEvent e)
Called after `Editor.Widget.OnMouseRightClick(Editor.MouseEvent)`, for the purposes of opening a context menu.
protected virtual void OnDoubleClick(Editor.MouseEvent e)
Called when the widget was double clicked with any mouse button.
public virtual void OnDragDrop(Editor.Widget.DragEvent ev)
Something was dragged and dropped on this widget. Apply the data here, if its valid. Requires `Editor.Widget.AcceptDrops` to function.
Parameters
ev: The drag event info.
public virtual void OnDragHover(Editor.Widget.DragEvent ev)
Cursor with drag and drop data moved on this widget. Requires `Editor.Widget.AcceptDrops` to function.
Parameters
ev: The drag event info.
public virtual void OnDragLeave()
Cursor with drag and drop data left the bounds of this widget. Requires `Editor.Widget.AcceptDrops` to function.
protected virtual void OnDragStart()
Called when dragging. `Editor.Widget.IsDraggable` should be true.
protected virtual void OnFocus(Editor.FocusChangeReason reason)
Called when the widget gains keyboard focus.
protected virtual void OnKeyPress(Editor.KeyEvent e)
A key has been pressed. Your widget needs keyboard focus for this to be called - see FocusMode.
protected virtual void OnKeyRelease(Editor.KeyEvent e)
A key has been released.
protected virtual void OnMouseClick(Editor.MouseEvent e)
Called when this widget is left clicked (on mouse release).
protected virtual void OnMouseEnter()
Mouse cursor entered the bounds of this widget.
protected virtual void OnMouseLeave()
Mouse cursor exited the bounds of this widget.
protected virtual void OnMouseMove(Editor.MouseEvent e)
Called when the mouse cursor is moved while being over this widget.
protected virtual void OnMousePress(Editor.MouseEvent e)
Called when mouse is pressed over this widget.
protected virtual void OnMouseReleased(Editor.MouseEvent e)
Called when mouse is released over this widget.
protected virtual void OnMouseRightClick(Editor.MouseEvent e)
Called when this widget is right clicked (on mouse release).
protected virtual void OnMouseWheel(Editor.WheelEvent e)
Mouse wheel was scrolled while the mouse cursor was over this widget.
protected virtual void OnMoved()
Called when the widget was moved to a new position relative to it's parent.
protected virtual void OnPaint()
Override to custom paint your widget, for example using `Editor.Paint`. Can be overwritten by `Editor.Widget.OnPaintOverride`.
Implementations
protected virtual void OnResize()
Called when the widgets' size was changed.
protected virtual void OnShortcutPressed(Editor.KeyEvent e)
A shortcut has been activated. This is called on the focused control so they can override it.
protected virtual void OnVisibilityChanged(bool visible)
Called when the visibility of this widget changes.
protected virtual void OnWheel(Editor.WheelEvent e)Obsolete
Mouse wheel was scrolled while the mouse cursor was over this widget.
Obsolete: Use OnMouseWheel
public void PostKeyEvent(Editor.KeyCode key)
public void Raise()
Raises this widget to the top of the parent widget's stack. After this call the widget will be visually in front of any overlapping sibling widgets.
public void RestoreGeometry(string state)
Restore position and size previously stored via `Editor.Widget.SaveGeometry`.
public string SaveGeometry()
Serialize position and size of this widget to a string, which can then be passed to `Editor.Widget.RestoreGeometry(System.String)`.
public void SetContext(string key, object value)
Set a context value on this widget. This context will be available to its children via FindContext.
public void SetEffectOpacity(float f)
public void SetModal(bool on, bool application = False)
Set this window to be modal. This means it will appear on top of everything and block input to everything else.
Parameters
application: Default: False
public void SetStyles(string sheet)
Directly set CSS style sheet(s) for this widget. Same format as a .css file.
public void SetStylesheetFile(string filename)
Set a file to load CSS for this widget from.
public virtual void Show()
Make this widget visible.
protected virtual void Signal(Editor.WidgetSignal signal)
protected void SignalValuesChanged()
When a value on this widget changed due to user input (ie, checking a box, editing a form) this is called, which sends a signal up the parent widgets.
protected virtual Vector2 SizeHint()
Should return the size this widget really wants to be if it can its way. The default is that you don't care - and just to return whatever the base value is.
public Vector2 ToScreen(Vector2 p)
Transform coordinates relative to the panel's top left corner, to coordinates relative to monitors's top left corner.
Parameters
p: Position on the panel, relative it its top left corner.
Returns
The same position relative to the monitors top left corner.
public virtual void Update()
Tell this widget that shit changed and it needs to redraw
public void UpdateGeometry()
Tell everything that the geometry of this has changed
No results match this filter.
Properties
Showing 63 properties
public bool Editor.Widget.AcceptDrops { get; set; }
Accept drag and dropping shit on us
public System.Collections.Generic.IEnumerable`1<Editor.Widget> Editor.Widget.Children { get; set; }
Child widgets of this widget.
public bool Editor.Widget.ContextMenuEnabled { get; set; }
Enables or disables the context menu on this widget.
public virtual Editor.CursorShape Editor.Widget.Cursor { get; set; }
Cursor override for this widget.
public bool Editor.Widget.DebugModeEnabled { get; set; }
Enable debug mode on this widget.
public bool Editor.Widget.DeleteOnClose { get; set; }
Delete this widget when close is pressed
public float Editor.Widget.DpiScale { get; set; }
The scale this widget is using (multiplying Size by this value gives the actual native size)
public bool Editor.Widget.Enabled { get; set; }
Makes the widget not interactable. This is also usually be reflected visually by the widget. The widget will not process any keyboard or mouse inputs. Applies retroactively to all children.
public float Editor.Widget.FixedHeight { get; set; }
Sets the fixed height for this widget
public float Editor.Widget.FixedWidth { get; set; }
Sets the fixed width for this widget
public Editor.FocusMode Editor.Widget.FocusMode { get; set; }
Sets the focus mode for this widget. This determines both how it will get focus and whether it will receive keyboard input.
public bool Editor.Widget.HasMaximizeButton { get; set; }
public float Editor.Widget.Height { get; set; }
Utility to interact with a widget's width - use Size where possible
public bool Editor.Widget.Hidden { get; set; }
Whether this widget is hidden. This differs from Visible because this will return the state for this particular widget, where as Visible returns false if a parent is hidden etc.
public bool Editor.Widget.IsActiveWindow { get; set; }
public bool Editor.Widget.IsBeingDroppedOn { get; set; }
Whether something is being dragged over this widget.
public bool Editor.Widget.IsDraggable { get; set; }
Whether this widget can be drag and dropped onto other widgets.
public bool Editor.Widget.IsFocused { get; set; }
Whether this widget has keyboard focus.
public bool Editor.Widget.IsFramelessWindow { get; set; }
public bool Editor.Widget.IsMaximized { get; set; }
public bool Editor.Widget.IsMinimized { get; set; }
public bool Editor.Widget.IsPopup { get; set; }
public bool Editor.Widget.IsPressed { get; set; }
Whether this widget is currently being pressed down or not.
public bool Editor.Widget.IsTooltip { get; set; }
public bool Editor.Widget.IsUnderMouse { get; set; }
public bool Editor.Widget.IsWindow { get; set; }
public float Editor.Widget.MaximumHeight { get; set; }
This widgets height should never be larger than the given value.
public Vector2 Editor.Widget.MaximumSize { get; set; }
Sets `Editor.Widget.MaximumWidth` and `Editor.Widget.MaximumHeight` simultaneously.
public float Editor.Widget.MaximumWidth { get; set; }
This widgets width should never be larger than the given value.
public float Editor.Widget.MinimumHeight { get; set; }
This widgets height should never be smaller than the given value.
public Vector2 Editor.Widget.MinimumSize { get; set; }
Sets `Editor.Widget.MinimumWidth` and `Editor.Widget.MinimumHeight` simultaneously.
public float Editor.Widget.MinimumWidth { get; set; }
This widgets width should never be smaller than the given value.
public bool Editor.Widget.MouseTracking { get; set; }
public string Editor.Widget.Name { get; set; }
Name of the widget, usually for debugging purposes.
public bool Editor.Widget.NoSystemBackground { get; set; }
public Editor.Widget Editor.Widget.Parent { get; set; }
Parent widget. If non null, position of this widget will be relative to the parent widget. Certain events will also propagate to the parent widget if unhandled.
public virtual Editor.Pixmap Editor.Widget.PixmapCursor { get; set; }
Custom cursor override for this widget. Will override `Editor.Widget.Cursor` with `Editor.CursorShape.CustomCursor`.
public Vector2 Editor.Widget.Position { get; set; }
Position of this widget, relative to its parent if it has one.
public virtual bool Editor.Widget.ProvidesDebugMode { get; set; }
If true then this widget has a debug mode that can be activated
public virtual bool Editor.Widget.ReadOnly { get; set; }
Makes the widget read only. I.e. You can copy text of a text entry, but can't edit it. Applies retroactively to all children.
public Sandbox.Rect Editor.Widget.ScreenGeometry { get; set; }
Returns the geometry of the screen this widget is currently on.
public Vector2 Editor.Widget.ScreenPosition { get; set; }
Position of the widget relative to the monitor's top left corner.
public bool Editor.Widget.ShowWithoutActivating { get; set; }
public string Editor.Widget.StatusTip { get; set; }
If set, hovering over this widget will set the text of a `Editor.StatusBar` of the window the widget belongs to.
public virtual string Editor.Widget.ToolTip { get; set; }
If set, this text will be displayed after a certain delay of hovering this widget with the mouse cursor.
public bool Editor.Widget.TranslucentBackground { get; set; }
public bool Editor.Widget.TransparentForMouseEvents { get; set; }
public bool Editor.Widget.UpdatesEnabled { get; set; }
If true, Update will call
public bool Editor.Widget.Visible { get; set; }
Whether this widget is visible or not, in the tree. This will return false if a parent is hidden. You might want to set Hidden if you're looking to check local visible status on a widget.
public float Editor.Widget.Width { get; set; }
Utility to interact with a widget's width - use Size where possible
public Editor.WindowFlags Editor.Widget.WindowFlags { get; set; }
public float Editor.Widget.WindowOpacity { get; set; }
public virtual string Editor.Widget.WindowTitle { get; set; }
No results match this filter.
Metadata
| Field | Value |
|---|---|
| Namespace | Editor |
| Type | class |
| Assembly | Sandbox.Tools |
| Doc ID | T:Editor.Widget |