Dart Documentationdock_spawnSplitterPanel

SplitterPanel Class

A splitter panel manages the child containers inside it with splitter bars. It can be stacked horizontally or vertically

Constructors

Code new SplitterPanel(List<IDockContainer> childContainers, bool stackedVertical) #

SplitterPanel(this.childContainers, this.stackedVertical) {
  panelElement = new DivElement();
  spiltterBars = new List<SplitterBar>();
  _buildSplitterDOM();
}

Methods

Code void destroy() #

void destroy() {
  removeFromDOM();
  panelElement.remove();
}

Code void performLayout(List<IDockContainer> children) #

void performLayout(List<IDockContainer> children)  {
  removeFromDOM();
  
  // rebuild
  this.childContainers = children;
  _buildSplitterDOM();
}

Code void removeFromDOM() #

void removeFromDOM() {
  childContainers.forEach((container) {
    if (container.containerElement != null) {
      container.containerElement.classes.remove("splitter-container-vertical");
      container.containerElement.classes.remove("splitter-container-horizontal");
      container.containerElement.remove();
    }
  });
  spiltterBars.forEach((bar) => bar.barElement.remove());
}

Code void resize(int width, int height) #

void resize(int width, int height) {
  if (childContainers.length <= 1) return;
  
  // Adjust the fixed dimension that is common to all (i.e. width, if stacked vertical; height, if stacked horizontally)
  for (int i = 0; i < childContainers.length; i++) {
    var childContainer = childContainers[i];
    if (stackedVertical) {
      childContainer.resize(width, childContainer.height);
    } else {
      childContainer.resize(childContainer.width, height);
    }
    
    if (i < spiltterBars.length) {
      var splitBar = spiltterBars[i];
      if (stackedVertical) {
        splitBar.barElement.style.width = "${width}px";
      } else {
        splitBar.barElement.style.height = "${height}px";
      }
    }
  }
  
  // Adjust the varying dimension
  int totalChildPanelSize = 0;
  // Find out how much space existing child containers take up (excluding the splitter bars)
  childContainers.forEach((container) {
    int size = stackedVertical ? 
        container.height : 
        container.width;
    totalChildPanelSize += size;
  });
  
  // Get the thickness of the bar
  int barSize = stackedVertical ? spiltterBars[0].barElement.$dom_clientHeight : spiltterBars[0].barElement.$dom_clientWidth;
  
  // Find out how much space existing child containers will take after being resized (excluding the splitter bars)  
  int targetTotalChildPanelSize = stackedVertical ? height : width;
  targetTotalChildPanelSize -= barSize * spiltterBars.length;
  
  // Get the scale multiplier 
  totalChildPanelSize = Math.max(totalChildPanelSize, 1);
  num scaleMultiplier = targetTotalChildPanelSize / totalChildPanelSize;
  
  // Update the size with this multiplier
  int updatedTotalChildPanelSize = 0;
  for (int i = 0; i < childContainers.length; i++) {
    var child = childContainers[i];
    int original = stackedVertical ? 
        child.containerElement.$dom_clientHeight : 
        child.containerElement.$dom_clientWidth;

    int newSize = (original * scaleMultiplier).toInt();
    updatedTotalChildPanelSize += newSize;
    
    // If this is the last node, add any extra pixels to fix the rounding off errors and match the requested size
    if (i == childContainers.length - 1) {
      newSize += targetTotalChildPanelSize - updatedTotalChildPanelSize;
    }
    
    // Set the size of the panel
    if (stackedVertical) {
      child.resize(child.width, newSize);
    } else {
      child.resize(newSize, child.height);
    }
  }
  
  panelElement.style.width = "${width}px";
  panelElement.style.height = "${height}px";
}

Code void setContainerRatio(IDockContainer container, num ratio) #

Sets the percentage of space the specified container takes in the split panel The percentage is specified in ratio and is between 0..1

void setContainerRatio(IDockContainer container, num ratio) {
  num splitPanelSize = stackedVertical ? panelElement.$dom_clientHeight : panelElement.$dom_clientWidth;
  num newContainerSize = splitPanelSize * ratio;
  int barSize = stackedVertical ? spiltterBars[0].barElement.$dom_clientHeight : spiltterBars[0].barElement.$dom_clientWidth;

  num otherPanelSizeQuota = splitPanelSize - newContainerSize - barSize * spiltterBars.length;
  num otherPanelScaleMultipler = otherPanelSizeQuota / splitPanelSize;
  
  childContainers.forEach((child) {
    num size;
    if (child != container) {
      size = stackedVertical ? child.containerElement.$dom_clientHeight : child.containerElement.$dom_clientWidth;
      size *=  otherPanelScaleMultipler;
    } else {
      size = newContainerSize;
    }
    
    if (stackedVertical) {
      child.resize(child.width, size.toInt());
    } else {
      child.resize(size.toInt(), child.height);
    }
  });
}

Fields

Code List<IDockContainer> childContainers #

List<IDockContainer> childContainers;

Code DivElement panelElement #

DivElement panelElement;

Code List<SplitterBar> spiltterBars #

List<SplitterBar> spiltterBars;

Code bool stackedVertical #

bool stackedVertical;