Advertisement
Guest User

Untitled

a guest
May 26th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 4.93 KB | None | 0 0
  1.     @:access(Component)
  2.     public function refresh() {
  3.         trace('Layout::refresh - ${component.id}, autoWidth: ${component.autoWidth}, autoHeight: ${component.autoHeight}, layoutDirty: ${component.layoutDirty}, childrenLayedOut: ${component.childrenLayedOut}');
  4.        
  5.         if (component.layoutDirty == false) {
  6.             trace('    skipping, layout not dirty');
  7.             return;
  8.         }
  9.        
  10.         /*
  11.         if (component.childrenLayedOut == false && (component.autoWidth == true || component.autoHeight == true)) {
  12.             trace('    skipping, children not layed out and auto width/height is true');
  13.             return;
  14.         }
  15.         */
  16.        
  17.         if (component.childrenLayedOut == false) {
  18.             trace('    skipping, children not layed out');
  19.             return;
  20.         }
  21.        
  22.         /*
  23.         if (component.percentWidth != null && component.parentComponent.percentWidth != null) {
  24.             //return;
  25.         }
  26.         */
  27.        
  28.        
  29.         var calculatedWidth:Null<Float> = null;
  30.         var calculatedHeight:Null<Float> = null;
  31.        
  32.         if (component.autoWidth == true || component.autoHeight == true) {
  33.             var size:Size = calcAutoSize();
  34.             if (component.autoWidth == true) {
  35.                 calculatedWidth = size.width;
  36.             }
  37.             if (component.autoHeight == true) {
  38.                 calculatedHeight = size.height;
  39.             }
  40.         }
  41.        
  42.         if (component.percentWidth != null) {
  43.             if (component.parentComponent.percentWidth == null) {
  44.                 /*
  45.                 var ucx = component.parentComponent.width - component.parentComponent.padding * 2;
  46.                 trace(">>>>>>>>>>>>>>>>>>> component.id " + component.id);
  47.                 trace(">>>>>>>>>>>>>>>>>>> parent.id " + component.parentComponent.id);
  48.                 for (child in component.parentComponent.children) {
  49.                     if (child.percentWidth == null) {
  50.                         ucx -= child.width + component.spacing;
  51.                     }
  52.                 }
  53.                 */
  54.                 var ucx = component.parentComponent.layout.calcUsableSize().width;
  55.                 calculatedWidth = (ucx * component.percentWidth) / 100;
  56.             }
  57.         }
  58.        
  59.         if (component.percentHeight != null) {
  60.             if (component.parentComponent.percentHeight == null) {
  61.                 /*
  62.                 var ucy = component.parentComponent.height - component.parentComponent.padding * 2;
  63.                 for (child in component.children) {
  64.                     if (child.percentHeight == null) {
  65.                         ucy -= child.height + component.spacing;
  66.                     }
  67.                 }
  68.                 */
  69.                 var ucy = component.parentComponent.layout.calcUsableSize().height;
  70.                 calculatedHeight = (ucy * component.percentHeight) / 100;
  71.             }
  72.         }
  73.        
  74.         if (component.autoWidth == false && component.percentWidth == null) {
  75.             calculatedWidth = component.width;
  76.         }
  77.         if (component.autoHeight == false && component.percentHeight == null) {
  78.             calculatedHeight = component.height;
  79.         }
  80.        
  81.         if (layoutRefreshStats.exists(component.id) == false) {
  82.             layoutRefreshStats.set(component.id, 0);
  83.         }
  84.         layoutRefreshStats.set(component.id, layoutRefreshStats.get(component.id) + 1);
  85.        
  86.         component.layoutDirty = false;
  87.         //if (component.parentComponent != null && (component.parentComponent.autoWidth == true || component.parentComponent.autoHeight == true)) {
  88.         if (component.parentComponent != null) {
  89.             component.parentComponent.layoutDirty = true;
  90.         }
  91.         if (calculatedWidth != component._componentWidth || calculatedHeight != component._componentHeight) {
  92.             //component.resize(calculatedWidth, calculatedHeight);
  93.         }
  94.         component.resize(calculatedWidth, calculatedHeight);
  95.        
  96.         //repositionChildren();
  97.        
  98.         for (child in component.children) {
  99.             var ucx = component.layout.calcUsableSize().width;// component.width - component.padding * 2 - ((component.children.length - 1) * component.spacing);
  100.             var ucy = component.layout.calcUsableSize().height;// component.height - component.padding * 2;// - ((component.children.length - 1) * component.spacing);
  101.             calculatedWidth = null;
  102.             calculatedHeight = null;
  103.             if (child.percentWidth != null) {
  104.                 calculatedWidth = (ucx * child.percentWidth) / 100;
  105.             }
  106.             if (child.percentHeight != null) {
  107.                 calculatedHeight = (ucy * child.percentHeight) / 100;
  108.             }
  109.            
  110.             child.resize(calculatedWidth, calculatedHeight);
  111.             child.layout.repositionChildren();
  112.         }
  113.        
  114.         repositionChildren();
  115.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement