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 706b65a8f6
commit 11a1026074
4 changed files with 941 additions and 939 deletions

View File

@@ -8260,7 +8260,6 @@ LGraphNode.prototype.executeAction = function(action)
var margin = 15; var margin = 15;
for (var i = 0; i < widgets.length; ++i) { for (var i = 0; i < widgets.length; ++i) {
var h = H;
var w = widgets[i]; var w = widgets[i];
var y = posY; var y = posY;
if (w.y) { if (w.y) {
@@ -8431,11 +8430,11 @@ LGraphNode.prototype.executeAction = function(action)
break; break;
default: default:
if (w.draw) { if (w.draw) {
h = w.draw(ctx, node, width, y, H) || H; w.draw(ctx, node, width, y, H);
} }
break; break;
} }
posY += h + 4; posY += (w.computeSize ? w.computeSize(width)[1] : H) + 4;
ctx.globalAlpha = this.editor_alpha; ctx.globalAlpha = this.editor_alpha;
} }
@@ -8467,7 +8466,8 @@ LGraphNode.prototype.executeAction = function(action)
var w = node.widgets[i]; var w = node.widgets[i];
if(!w || w.disabled) if(!w || w.disabled)
continue; 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 //inside widget
switch (w.type) { switch (w.type) {
case "button": case "button":
@@ -8601,7 +8601,7 @@ LGraphNode.prototype.executeAction = function(action)
break; break;
default: default:
if (w.mouse) { if (w.mouse) {
w.mouse(ctx, event, [x, y], node); this.dirty_canvas = w.mouse(event, [x, y], node);
} }
break; break;
} //end switch } //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, width: number,
posY: number, posY: number,
height: number height: number
): number | undefined; ): void;
/** /**
* Called by `LGraphCanvas.processNodeWidgets` * Called by `LGraphCanvas.processNodeWidgets`
* https://github.com/jagenjo/litegraph.js/issues/76 * https://github.com/jagenjo/litegraph.js/issues/76
*/ */
mouse?( mouse?(
ctx: undefined,
event: MouseEvent, event: MouseEvent,
pos: Vector2, pos: Vector2,
node: LGraphNode node: LGraphNode
): void; ): boolean;
/** Called by `LGraphNode.computeSize` */ /** Called by `LGraphNode.computeSize` */
computeSize?(width: number): [number, number]; computeSize?(width: number): [number, number];
} }

View File

@@ -8260,7 +8260,6 @@ LGraphNode.prototype.executeAction = function(action)
var margin = 15; var margin = 15;
for (var i = 0; i < widgets.length; ++i) { for (var i = 0; i < widgets.length; ++i) {
var h = H;
var w = widgets[i]; var w = widgets[i];
var y = posY; var y = posY;
if (w.y) { if (w.y) {
@@ -8431,11 +8430,11 @@ LGraphNode.prototype.executeAction = function(action)
break; break;
default: default:
if (w.draw) { if (w.draw) {
h = w.draw(ctx, node, width, y, H) || H; w.draw(ctx, node, width, y, H);
} }
break; break;
} }
posY += h + 4; posY += (w.computeSize ? w.computeSize(width)[1] : H) + 4;
ctx.globalAlpha = this.editor_alpha; ctx.globalAlpha = this.editor_alpha;
} }
@@ -8467,7 +8466,8 @@ LGraphNode.prototype.executeAction = function(action)
var w = node.widgets[i]; var w = node.widgets[i];
if(!w || w.disabled) if(!w || w.disabled)
continue; 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 //inside widget
switch (w.type) { switch (w.type) {
case "button": case "button":
@@ -8601,7 +8601,7 @@ LGraphNode.prototype.executeAction = function(action)
break; break;
default: default:
if (w.mouse) { if (w.mouse) {
w.mouse(ctx, event, [x, y], node); this.dirty_canvas = w.mouse(event, [x, y], node);
} }
break; break;
} //end switch } //end switch