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

Create custom components #18

Open
Sadzeih opened this issue Jul 26, 2018 · 6 comments
Open

Create custom components #18

Sadzeih opened this issue Jul 26, 2018 · 6 comments

Comments

@Sadzeih
Copy link

Sadzeih commented Jul 26, 2018

Is it possible to create custom components that always have some pre-existing behaviour.

I'd like to create and visual programming interface with blocks that can be linked to each other. A bit like Unreal Engine 4 Blueprints.

So I'd like to make for example a FloatBlock component that always has some particular behaviour.

@ronnyek
Copy link

ronnyek commented Jul 30, 2018

I'm too looking into this. We'll undoubtedly need to create components that have templates defined, and define interactions within.

I'd like to do:

<ko-stage...>
  <ko-layer>
      <my-component></my-component>
  </ko-layer>
</ko stage>

And then just have my component be rendered as a a ko-group with its own components.

I tried to inherit from CoreShapeComponent, but library itself didn't appear to want to support that much at all. If we could that, it should be fairly easy to expose relative/absolute coordinates to do things like anchor lines at places on those components.

I tried forking and seeing issues with adding that, but mostly because I just don't quite understand how all of ng2-konva works.

@Sadzeih
Copy link
Author

Sadzeih commented Jul 30, 2018

Happy to see I'm not the only one trying to do that.
I tried too but didn't get anywhere. I don't know much about the internals of ng2-konva either so I'd be of little help but I do hope someone can help us.

@ronnyek
Copy link

ronnyek commented Aug 1, 2018

I've played with this a bunch more, and made changes to allow inheritance from CoreShapeComponent (making some of the properties protected etc). I made it so inheritors could just set the shape for the component as "Group", and my custom components seem to at least not be complained about.

I could however not get my custom component to draw its own internals. I think if there were some way to say render this component as if it were a ko-group and the contents would be just more shapes that get shoved into konva tree, that would be huge.

@rafaesc do you have any ideas about how to achieve such a thing? I'd love to use this to build a little workflow diagram editor, but I'd need some way of building a workflow item component, and have it have some inclusive functionality and sub shapes.

@orlyapps
Copy link

orlyapps commented Oct 1, 2018

I got the same problem. And it looks like the react/vue Wrapper has this feature.

@ronnyek
Copy link

ronnyek commented Oct 29, 2018

@rafaesc any ideas? It'd be really sweet to be able to do something like this

@conblem
Copy link

conblem commented Jun 17, 2019

parent.component.html

<ko-stage [config]="configStage"> 
  <ko-layer> 
    <app-place></app-place>  <!-- Custom component -->
  </ko-layer> 
</ko-stage> 

This is our custom component:

place.component.ts

import { 
  Component, 
  ElementRef, 
  forwardRef, 
  QueryList, 
  AfterContentInit, 
  ViewChildren, 
  AfterViewInit, 
} from '@angular/core'; 
import { of, Observable } from 'rxjs'; 
import { CoreShapeComponent } from 'ng2-konva'; 
  
@Component({ 
  selector: 'app-place', 
  templateUrl: './place.component.html', 
  styleUrls: ['./place.component.scss'], 
  providers: [ 
    { 
      provide: CoreShapeComponent, 
      useExisting: forwardRef(() => PlaceComponent), 
    }, 
  ], 
}) 
export class PlaceComponent extends CoreShapeComponent implements AfterViewInit, AfterContentInit { 
  @ViewChildren(CoreShapeComponent) 
  public shapes: QueryList<CoreShapeComponent> = new QueryList<CoreShapeComponent>(); 

  public configCircle: Observable<any> = of({ 
    x: 100, 
    y: 100, 
    radius: 70, 
    fill: 'black', 
  }); 

  constructor(elementRef: ElementRef) { 
    super(elementRef); 
    this.nameNode = 'Group'; 
    this.config = of({ 
      x: 100, 
      y: 100, 
    }); 
  } 

  public ngAfterViewInit(): void { 
    super.ngAfterContentInit(); 
  } 

  public ngAfterContentInit(): void {} 
} 

place.component.html

<ko-circle [config]="configCircle"></ko-circle> 

@Sadzeih
@ronnyek
@orlyapps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants