partridgejiang / Kekule.js

A Javascript cheminformatics toolkit.
http://partridgejiang.github.io/Kekule.js
MIT License
250 stars 61 forks source link

Locking chemspace size in Composer Widget to containing element size #153

Closed robotoer closed 4 years ago

robotoer commented 4 years ago

I have been trying to find a way to disable the current vertical/horizontal scrolling in the composer widget. I have tried setting the size of any loaded chemdocuments using a ResizeObserver which does prevent scrolling (by shrinking the document to fit the editor minus toolbars):

let ro = new ResizeObserver(entries => {
      for (let entry of entries) {
        const cr = entry.contentRect;
        const cObj = this.widget.getChemObj();
        cObj.setScreenSize({
          x: (cr.width - 46 - 2) * 2.0 / 3.0,
          y: (cr.height - 68 - 30) * 2.0 / 3.0,
        });
        this.widget.setChemObj(cObj);
      }
    });

This unfortunately causes molecules to shift off the document boundaries occasionally (e.g. resizing the window, viewing same chemDocument on computers with different sized windows). Is there an easy way to center molecules within a chemDocument?

I really appreciate all the quick help you have been providing! Keep up the great work

partridgejiang commented 4 years ago

Hi @robotoer, the editor widget provides a scrollClientToObject method itself. In the resize observer callback, you can call it directly:

let editor = this.widget.getEditor();  // suppose this.widget is a composer
editor.scrollClientToObject(editor.getChemObj().getChildren());  // centers the current loaded molecules (childen of chemDocument)
robotoer commented 4 years ago

Awesome! Thanks @partridgejiang