Skip to main content

LensStudio:Ui.MouseEvent

Class

Event object containing mouse interaction data.

Index

Example

export class MouseEventPanel extends PanelPlugin {
connections: any[];
static descriptor() {
const d = new Descriptor();
d.id = 'com.docs.UiMouseEventExample';
d.name = 'MouseEvent Example';
d.defaultDockState = DockState.Detached;
d.defaultSize = new Size(350, 250);
return d;
}
constructor(pluginSystem: Editor.PluginSystem, descriptor?: Descriptor) {
super(pluginSystem, descriptor);
this.connections = [];
}
createWidget(parent: Widget): Widget {
const root = new Widget(parent);
const layout = new BoxLayout();
layout.setDirection(Direction.TopToBottom);
layout.spacing = 8;
root.layout = layout;

const title = new Label(root);
title.text = 'MouseEvent Demo';
title.fontRole = FontRole.TitleBold;
layout.addWidget(title);

const info = new Label(root);
info.text = 'Click anywhere in this panel to see mouse event data.';
info.wordWrap = true;
layout.addWidget(info);

const clickArea = new Widget(root);
clickArea.setMinimumHeight(100);
clickArea.toolTip = 'Click here';
layout.addWidget(clickArea);

// MouseEvent is delivered via onMousePress signal
this.connections.push(
clickArea.onMousePress.connect((event: MouseEvent) => {
const btnName = event.button === MouseButton.LeftButton ? 'Left'
: event.button === MouseButton.RightButton ? 'Right'
: 'Other';
info.text = `Click: (${event.x}, ${event.y}) button=${btnName}`;
event.accept();
})
);

return root;
}
deinit(): void {
this.connections.forEach((c: any) => c?.disconnect());
this.connections = [];
}
}

Extends

Properties

button

readonly button: MouseButton

NEW


buttons

readonly buttons: MouseButton

NEW


globalX

readonly globalX: number

NEW


globalY

readonly globalY: number

NEW


modifiers

readonly modifiers: KeyboardModifier

NEW


x

readonly x: number

NEW


y

readonly y: number

NEW

Methods

accept()

accept(): void

Marks the event as handled so it will not propagate further.

Returns

void

Inherited from

Event.accept


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

Event.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Event.getTypeName


ignore()

ignore(): void

Marks the event as unhandled so it propagates to parent widgets.

Returns

void

Inherited from

Event.ignore


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Event.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Event.isSame