Skip to content

Editor

keyed_extras.editor

Editor

Bases: Base

A customizable editor window component for displaying content in a scene.

The Editor provides a window-like container that can house other drawable objects, complete with a title bar, control buttons, scrolling functionality, and customizable styling. It's useful for creating code editor interfaces, text displays, or any content that requires a contained viewing area.

Parameters:

Name Type Description Default
scene Scene

The scene to which the editor belongs.

required
x HasValue[float] | None

X-coordinate of the editor's top-left corner.

None
y HasValue[float] | None

Y-coordinate of the editor's top-left corner.

None
width float

Width of the editor window.

1920
height float

Height of the editor window.

1080
title str | None

Optional title to display in the title bar.

None
font str

Font family to use for the title bar text.

'Anonymous Pro'
menu_height float

Height of the title bar.

40
scroll_width float

Width of the scroll bar.

40
draw_scroll_bar bool

Whether to draw the scroll bar.

True
radius float

Corner radius of the editor window.

20
outline_color tuple[float, float, float] | Color

Color of the window outline.

(1, 1, 1)
window_color tuple[float, float, float] | Color

Background color of the main window area.

(0.1, 0.1, 0.1)
bar_color tuple[float, float, float] | Color

Background color of the title bar.

(0.2, 0.2, 0.2)
scroll_color tuple[float, float, float] | Color

Background color of the scroll bar.

(0.3, 0.3, 0.3)
scroll_indicator_color tuple[float, float, float] | Color

Color of the scroll indicator.

(0.8, 0.8, 0.8)
text_color tuple[float, float, float] | Color

Color of the text.

(1, 1, 1)

add

add(*objects)

Add a drawable object to the editor's content area.

This method adds an object to be displayed within the editor window's content area (below the title bar). Objects are positioned relative to the editor's internal coordinate system, with (0,0) being the top-left corner of the content area.

Objects added to the editor will be affected by the editor's scroll position.

Tip

Do not add objects to the Scene if you want to draw them within the Editor. Otherwise, they will be drawn in both places.

Parameters:

Name Type Description Default
objects Base

A drawable object (derived from keyed.Base) to add to the editor.

()

scroll_to

scroll_to(progress, start, end, ease=cubic_in_out)

Animate the editor's scroll position to a specified progress value.

This method creates an animation that smoothly scrolls the editor's content from its current scroll position to the target position specified by the progress parameter. The scrolling animation will begin at the start frame and complete by the end frame, following the specified easing function.

Parameters:

Name Type Description Default
progress float

Target scroll position as a normalized value between 0.0 and 1.0, where 0.0 represents the top of the content and 1.0 represents the bottom of the content.

required
start int

The frame number at which to start the scrolling animation.

required
end int

The frame number at which to complete the scrolling animation.

required
ease EasingFunctionT

The easing function to use for the animation.

cubic_in_out

Returns:

Name Type Description
Self Self

Returns the editor instance to allow method chaining.

Notes
  • If the content fits entirely within the editor (no scrolling needed), the progress value won't have any visible effect.
  • Multiple scroll_to calls can be chained to create complex scrolling sequences.
  • The visible content is determined by both the editor height and the total height of all objects added to the editor.
Example
# Scroll from top to bottom gradually
editor.scroll_to(1.0, start=30, end=90)

# Quickly scroll back to the middle
editor.scroll_to(0.5, start=100, end=110)

resize

resize(width=None, height=None, start=0, end=0, ease=cubic_in_out, animation_type=ABSOLUTE)

Animate the editor window's size.

This method creates an animation that resizes the editor window from its current dimensions to the specified target dimensions.

Parameters:

Name Type Description Default
width float | None

Target width. The meaning of this value depends on animation_type.

None
height float | None

Target height. The meaning of this value depends on animation_type.

None
start int

Starting frame for the animation

0
end int

Ending frame for the animation

0
ease EasingFunctionT

Easing function to use

cubic_in_out
animation_type AnimationType

How to apply the width/height values:

  • ABSOLUTE: Set exact dimensions
  • ADDITIVE: Add to current dimensions
  • MULTIPLICATIVE: Multiply current dimensions
ABSOLUTE

Returns:

Type Description
Self

Self

Example
# Resize to exact dimensions over 30 frames
editor.resize(width=800, height=600, start=10, end=40)

# Double the width while keeping the same height
editor.resize(
    width=2.0,
    height=None,
    start=50,
    end=70,
    animation_type=AnimationType.MULTIPLY
)

# Add 50 pixels to height
editor.resize(
    width=None,
    height=50,
    start=80,
    end=100,
    animation_type=AnimationType.ADD
)

# Instant resize on frame 120
editor.resize(width=500, height=400, start=120, end=120)