Skip to content

PastableWidget

Namespace: Hex1b.Widgets

Assembly: Hex1b.dll

A container widget that intercepts bracketed paste events for all descendants. When paste data arrives and no child handles it, the receives the for streaming processing.

csharp
public sealed record PastableWidget : Hex1bWidget, IEquatable<Hex1bWidget>, IEquatable<PastableWidget>

Inheritance

ObjectHex1bWidgetPastableWidget

Implements

Constructors

PastableWidget(Hex1bWidget)

A container widget that intercepts bracketed paste events for all descendants. When paste data arrives and no child handles it, the receives the for streaming processing.

Parameters:

csharp
public PastableWidget(Hex1bWidget Child)

Properties

Child

Returns: Hex1bWidget

csharp
public Hex1bWidget Child { get; init; }

Methods

OnPaste(Action<PasteEventArgs>)

Sets the async paste handler using a synchronous action.

Parameters:

Returns: PastableWidget

csharp
public PastableWidget OnPaste(Action<PasteEventArgs> handler)

OnPaste(Func<PasteEventArgs, Task>)

Sets the async paste handler that receives streaming paste data.

Parameters:

Returns: PastableWidget

csharp
public PastableWidget OnPaste(Func<PasteEventArgs, Task> handler)

WithMaxSize(int)

Sets the maximum paste size in characters. If exceeded, the paste is auto-cancelled.

Parameters:

Returns: PastableWidget

csharp
public PastableWidget WithMaxSize(int maxCharacters)

WithTimeout(TimeSpan)

Sets a timeout for the paste operation. If exceeded, the paste is auto-cancelled.

Parameters:

Returns: PastableWidget

csharp
public PastableWidget WithTimeout(TimeSpan timeout)

Examples

csharp
ctx.Pastable(
    child: ctx.VStack(v => [
        v.Text("Drop zone"),
        v.TextBlock($"Received: {bytesReceived} bytes"),
    ]),
    onPaste: async paste =>
    {
        await foreach (var chunk in paste.ReadChunksAsync())
        {
            bytesReceived += chunk.Length;
        }
    }
)

Released under the MIT License.