fixed mouse function for custom widget : take custom height into account

This commit is contained in:
altarfinch
2020-05-08 01:40:15 +02:00
parent 7ba41d1d75
commit 4fe32687d2
4 changed files with 941 additions and 939 deletions

View File

@@ -20511,7 +20511,6 @@ LGraphNode.prototype.executeAction = function(action)
var margin = 15;
for (var i = 0; i < widgets.length; ++i) {
var h = H;
var w = widgets[i];
var y = posY;
if (w.y) {
@@ -20682,11 +20681,11 @@ LGraphNode.prototype.executeAction = function(action)
break;
default:
if (w.draw) {
h = w.draw(ctx, node, width, y, H) || H;
w.draw(ctx, node, width, y, H);
}
break;
}
posY += h + 4;
posY += (w.computeSize ? w.computeSize(width)[1] : H) + 4;
ctx.globalAlpha = this.editor_alpha;
}
@@ -20718,7 +20717,8 @@ LGraphNode.prototype.executeAction = function(action)
var w = node.widgets[i];
if(!w || w.disabled)
continue;
if ( w == active_widget || (x > 6 && x < width - 12 && y > w.last_y && y < w.last_y + LiteGraph.NODE_WIDGET_HEIGHT) ) {
var widget_height = w.computeSize ? w.computeSize(width)[1] : LiteGraph.NODE_WIDGET_HEIGHT;
if ( w == active_widget || (x > 6 && x < width - 12 && y > w.last_y && y < w.last_y + widget_height) ) {
//inside widget
switch (w.type) {
case "button":
@@ -20852,7 +20852,7 @@ LGraphNode.prototype.executeAction = function(action)
break;
default:
if (w.mouse) {
w.mouse(ctx, event, [x, y], node);
this.dirty_canvas = w.mouse(event, [x, y], node);
}
break;
} //end switch

1855
build/litegraph.min.js vendored

File diff suppressed because it is too large Load Diff

5
src/litegraph.d.ts vendored
View File

@@ -62,17 +62,16 @@ export interface IWidget<TValue = any, TOptions = any> {
width: number,
posY: number,
height: number
): number | undefined;
): void;
/**
* Called by `LGraphCanvas.processNodeWidgets`
* https://github.com/jagenjo/litegraph.js/issues/76
*/
mouse?(
ctx: undefined,
event: MouseEvent,
pos: Vector2,
node: LGraphNode
): void;
): boolean;
/** Called by `LGraphNode.computeSize` */
computeSize?(width: number): [number, number];
}

View File

@@ -8257,7 +8257,6 @@ LGraphNode.prototype.executeAction = function(action)
var margin = 15;
for (var i = 0; i < widgets.length; ++i) {
var h = H;
var w = widgets[i];
var y = posY;
if (w.y) {
@@ -8428,11 +8427,11 @@ LGraphNode.prototype.executeAction = function(action)
break;
default:
if (w.draw) {
h = w.draw(ctx, node, width, y, H) || H;
w.draw(ctx, node, width, y, H);
}
break;
}
posY += h + 4;
posY += (w.computeSize ? w.computeSize(width)[1] : H) + 4;
ctx.globalAlpha = this.editor_alpha;
}
@@ -8464,7 +8463,8 @@ LGraphNode.prototype.executeAction = function(action)
var w = node.widgets[i];
if(!w || w.disabled)
continue;
if ( w == active_widget || (x > 6 && x < width - 12 && y > w.last_y && y < w.last_y + LiteGraph.NODE_WIDGET_HEIGHT) ) {
var widget_height = w.computeSize ? w.computeSize(width)[1] : LiteGraph.NODE_WIDGET_HEIGHT;
if ( w == active_widget || (x > 6 && x < width - 12 && y > w.last_y && y < w.last_y + widget_height) ) {
//inside widget
switch (w.type) {
case "button":
@@ -8598,7 +8598,7 @@ LGraphNode.prototype.executeAction = function(action)
break;
default:
if (w.mouse) {
w.mouse(ctx, event, [x, y], node);
this.dirty_canvas = w.mouse(event, [x, y], node);
}
break;
} //end switch