Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(): isNotVisible + rename to isVisible #9574

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- fix(): `isNotVisible` + rename to `isVisible` [#9574](https://github.com/fabricjs/fabric.js/pull/9574)
- fix() Addressing path cloning slowness ( partially ) [#9573](https://github.com/fabricjs/fabric.js/pull/9573)
- feat(): Add save/restore ability to group LayoutManager [#9564](https://github.com/fabricjs/fabric.js/pull/9564)
- fix() Remove unwanted set type warning [#9569](https://github.com/fabricjs/fabric.js/pull/9569)
Expand Down
2 changes: 1 addition & 1 deletion src/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export function createCollectionMixin<TBase extends Constructor>(Base: TBase) {
const object = this._objects[i] as unknown as InteractiveFabricObject;
if (
object.selectable &&
object.visible &&
object.isVisible() &&
((includeIntersecting && object.intersectsWithRect(tl, br)) ||
object.isContainedWithinRect(tl, br) ||
(includeIntersecting && object.containsPoint(tl)) ||
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/SelectableCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents>
_checkTarget(obj: FabricObject, pointer: Point): boolean {
if (
obj &&
obj.visible &&
obj.isVisible() &&
obj.evented &&
this._pointIsInObjectSelectionArea(
obj,
Expand Down
10 changes: 4 additions & 6 deletions src/shapes/Object/Object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,11 +739,9 @@ export class FabricObject<
* @memberOf FabricObject.prototype
* @return {Boolean}
*/
isNotVisible() {
isVisible() {
return (
this.opacity === 0 ||
(!this.width && !this.height && this.strokeWidth === 0) ||
!this.visible
this.visible && this.opacity > 0 && this.width > 0 && this.height > 0
);
}

Expand All @@ -753,7 +751,7 @@ export class FabricObject<
*/
render(ctx: CanvasRenderingContext2D) {
// do not render if width/height are zeros or object is not visible
if (this.isNotVisible()) {
if (!this.isVisible()) {
return;
}
if (
Expand Down Expand Up @@ -978,7 +976,7 @@ export class FabricObject<
* on parent canvas.
*/
isCacheDirty(skipCanvas = false) {
if (this.isNotVisible()) {
if (!this.isVisible()) {
return false;
}
if (
Expand Down
4 changes: 2 additions & 2 deletions src/shapes/Text/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ export class FabricText<
*/
_render(ctx: CanvasRenderingContext2D) {
const path = this.path;
path && !path.isNotVisible() && path._render(ctx);
path && path.isVisible() && path._render(ctx);
this._setTextStyles(ctx);
this._renderTextLinesBackground(ctx);
this._renderTextDecoration(ctx, 'underline');
Expand Down Expand Up @@ -1679,7 +1679,7 @@ export class FabricText<
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
render(ctx: CanvasRenderingContext2D) {
if (!this.visible) {
if (!this.isVisible()) {
return;
}
if (
Expand Down
6 changes: 3 additions & 3 deletions test/unit/ellipse.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@
});
});

QUnit.test('isNotVisible', function(assert) {
QUnit.test('isVisible', function(assert) {
var ellipse = new fabric.Ellipse();
ellipse.set('rx', 0);
ellipse.set('ry', 0);

assert.equal(ellipse.isNotVisible(), false, 'isNotVisible false when rx/ry are 0 because strokeWidth is > 0');
assert.equal(ellipse.isVisible(), true, 'isVisible false when rx/ry are 0 because strokeWidth is > 0');

ellipse.set('strokeWidth', 0);

assert.equal(ellipse.isNotVisible(), true, 'should not render anymore with also strokeWidth 0');
assert.equal(ellipse.isVisible(), false, 'should not render anymore with also strokeWidth 0');

});

Expand Down
12 changes: 6 additions & 6 deletions test/unit/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -1210,17 +1210,17 @@
object._set('fill', 'blue');
assert.equal(object.dirty, false, 'dirty is not raised');
});
QUnit.test('isNotVisible', function(assert) {
QUnit.test('isVisible', function(assert) {
var object = new fabric.Object({ fill: 'blue', width: 100, height: 100 });
assert.equal(object.isNotVisible(), false, 'object is default visible');
assert.equal(object.isVisible(), true, 'object is default visible');
object = new fabric.Object({ fill: 'blue', width: 0, height: 0, strokeWidth: 1 });
assert.equal(object.isNotVisible(), false, 'object is visible with width and height equal 0, but strokeWidth 1');
assert.equal(object.isVisible(), false, 'object is visible with width and height equal 0, but strokeWidth 1');
object = new fabric.Object({ opacity: 0, fill: 'blue' });
assert.equal(object.isNotVisible(), true, 'object is not visible with opacity 0');
assert.equal(object.isVisible(), false, 'object is not visible with opacity 0');
object = new fabric.Object({ fill: 'blue', visible: false });
assert.equal(object.isNotVisible(), true, 'object is not visible with visible false');
assert.equal(object.isVisible(), false, 'object is not visible with visible false');
object = new fabric.Object({ fill: 'blue', width: 0, height: 0, strokeWidth: 0 });
assert.equal(object.isNotVisible(), true, 'object is not visible with also strokeWidth equal 0');
assert.equal(object.isVisible(), false, 'object is not visible with also strokeWidth equal 0');
});
QUnit.test('shouldCache', function(assert) {
var object = new fabric.Object();
Expand Down