API Reference 0.7.1rikulo_viewViewUtil

ViewUtil class

A collection of View utilities.

class ViewUtil {
 /** Returns the view of the given node, or null if not found.
  *
  * Notice it searches only the mounted views, i.e.,
  * `inDocument` is true.
  *
  * If the given node doesn't belong to any view,
  * the nearest view containing it will be returned.
  * For example, if the given node is the content of an instance of [TextView],
  * the [TextView] instance will be returned.
  */
 static View getView(Node node) {
   var view;
   do {
     if ((view = _views[node]) != null)
       return view;
   } while ((node = node.parent) != null && node is! Document);
 }
 static final Map<Element, View> _views = new HashMap();

 /** Handles the layouts of views queued by [View.requestLayout].
  *
  * Notice that it is static, i.e., all queued requests will be handled.
  */
 static void flushRequestedLayouts() {
   layoutManager.flush(null, true);
 }

 /** Returns the root view of the given view.
  */
 static View getRoot(View view) {
   for (View w; (w = view.parent) != null; view = w)
     ;
   return view;
 }
 /** Returns the rectangle enclosing all views in the given list.
  * Views in [children] must belong to the same parent.
  *
  * It doesn't count the child views that are anchored or [View.shallLayout_]
  * returns false.
  */
 static Rect getRect(List<View> children) {
   int left = 0, top = 0, right = 0, bottom = 0;
   for (final View child in children) {
     if ((child.parent == null || child.parent.shallLayout_(child))
     && child.profile.anchorView == null) {
       final String pos = child.style.position;
       if (pos != "static" && pos != "fixed") {
         if (child.left < left) left = child.left;
         int val = child.width;
         if (val != null && (val += child.left) > right)
           right = val;

         if (child.top < top) top = child.top;
         val = child.height;
         if (val != null && (val += child.top) > bottom)
           bottom = val;
       }
     }
   }
   return new Rect(left, top, right - left, bottom - top);
 }

 /** Returns an ID that uniquely identifying this application.
  * In other words, every dart application in the same browser
  * will have an unique [appId].
  */
 static int get appId {
   if (_appId == null) {
     final body = document.body;
     if (body == null)
       throw new UIError("document not ready yet");

     final dataset = body.dataset;
     String sval = dataset[_APP_COUNT];
     if (sval != null) {
       _appId = int.parse(sval);
       dataset[_APP_COUNT] = (_appId + 1).toString();
     } else {
       _appId = 0;
       dataset[_APP_COUNT] = "1";
     }
   }
   return _appId;
 }
 static int _appId;
 static const _APP_COUNT = "rk_apps";
}

Static Properties

final int appId #

Returns an ID that uniquely identifying this application. In other words, every dart application in the same browser will have an unique appId.

static int get appId {
 if (_appId == null) {
   final body = document.body;
   if (body == null)
     throw new UIError("document not ready yet");

   final dataset = body.dataset;
   String sval = dataset[_APP_COUNT];
   if (sval != null) {
     _appId = int.parse(sval);
     dataset[_APP_COUNT] = (_appId + 1).toString();
   } else {
     _appId = 0;
     dataset[_APP_COUNT] = "1";
   }
 }
 return _appId;
}

Static Methods

View getView(Node node) #

Returns the view of the given node, or null if not found.

Notice it searches only the mounted views, i.e., inDocument is true.

If the given node doesn't belong to any view, the nearest view containing it will be returned. For example, if the given node is the content of an instance of TextView, the TextView instance will be returned.

static View getView(Node node) {
 var view;
 do {
   if ((view = _views[node]) != null)
     return view;
 } while ((node = node.parent) != null && node is! Document);
}

void flushRequestedLayouts() #

Handles the layouts of views queued by View.requestLayout.

Notice that it is static, i.e., all queued requests will be handled.

static void flushRequestedLayouts() {
 layoutManager.flush(null, true);
}

View getRoot(View view) #

Returns the root view of the given view.

static View getRoot(View view) {
 for (View w; (w = view.parent) != null; view = w)
   ;
 return view;
}

Rect getRect(List<View> children) #

Returns the rectangle enclosing all views in the given list. Views in children must belong to the same parent.

It doesn't count the child views that are anchored or View.shallLayout_ returns false.

static Rect getRect(List<View> children) {
 int left = 0, top = 0, right = 0, bottom = 0;
 for (final View child in children) {
   if ((child.parent == null || child.parent.shallLayout_(child))
   && child.profile.anchorView == null) {
     final String pos = child.style.position;
     if (pos != "static" && pos != "fixed") {
       if (child.left < left) left = child.left;
       int val = child.width;
       if (val != null && (val += child.left) > right)
         right = val;

       if (child.top < top) top = child.top;
       val = child.height;
       if (val != null && (val += child.top) > bottom)
         bottom = val;
     }
   }
 }
 return new Rect(left, top, right - left, bottom - top);
}