Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: samples/swarm/Views.dart

Issue 11748016: Make ~/, round, ceil, floor, truncate return ints. Remove toInt. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Checked mode fixes. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of swarmlib; 5 part of swarmlib;
6 6
7 // This file contains View framework classes. 7 // This file contains View framework classes.
8 // As it grows, it may need to be split into multiple files. 8 // As it grows, it may need to be split into multiple files.
9 9
10 /** A factory that creates a view from a data model. */ 10 /** A factory that creates a view from a data model. */
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 return itemLength * (_data.length - 1) + Math.max(viewLength, itemLength); 663 return itemLength * (_data.length - 1) + Math.max(viewLength, itemLength);
664 } 664 }
665 } 665 }
666 666
667 int getOffset(int index) { 667 int getOffset(int index) {
668 return index * _itemLength; 668 return index * _itemLength;
669 } 669 }
670 670
671 int getPageLength(int viewLength) { 671 int getPageLength(int viewLength) {
672 final itemsPerPage = (viewLength / _itemLength).floor(); 672 final itemsPerPage = (viewLength / _itemLength).floor();
673 return (Math.max(1, itemsPerPage) * _itemLength).toInt(); 673 return (Math.max(1, itemsPerPage) * _itemLength);
674 } 674 }
675 675
676 int getPage(int index, int viewLength) { 676 int getPage(int index, int viewLength) {
677 return (getOffset(index) / getPageLength(viewLength)).floor().toInt(); 677 return (getOffset(index) / getPageLength(viewLength)).floor();
Lasse Reichstein Nielsen 2013/01/04 10:29:42 ~/ ?
678 } 678 }
679 679
680 int getPageStartIndex(int page, int viewLength) { 680 int getPageStartIndex(int page, int viewLength) {
681 return (getPageLength(viewLength) / _itemLength).toInt() * page; 681 return (getPageLength(viewLength) ~/ _itemLength) * page;
682 } 682 }
683 683
684 int getSnapIndex(num offset, int viewLength) { 684 int getSnapIndex(num offset, int viewLength) {
685 int index = (-offset / _itemLength).round().toInt(); 685 int index = (-offset / _itemLength).round();
686 if (_paginate) { 686 if (_paginate) {
687 index = getPageStartIndex(getPage(index, viewLength), viewLength); 687 index = getPageStartIndex(getPage(index, viewLength), viewLength);
688 } 688 }
689 return GoogleMath.clamp(index, 0, _data.length - 1); 689 return GoogleMath.clamp(index, 0, _data.length - 1);
690 } 690 }
691 691
692 Interval computeVisibleInterval( 692 Interval computeVisibleInterval(
693 num offset, num viewLength, num bufferLength) { 693 num offset, num viewLength, num bufferLength) {
694 num targetIntervalStart = 694 num targetIntervalStart =
695 Math.max(0,((-offset - bufferLength) / _itemLength).floor()); 695 Math.max(0, (-offset - bufferLength) ~/ _itemLength);
696 num targetIntervalEnd = GoogleMath.clamp( 696 num targetIntervalEnd = GoogleMath.clamp(
697 ((-offset + viewLength + bufferLength) / _itemLength).ceil(), 697 ((-offset + viewLength + bufferLength) / _itemLength).ceil(),
698 targetIntervalStart, 698 targetIntervalStart,
699 _data.length); 699 _data.length);
700 return new Interval(targetIntervalStart.toInt(), 700 return new Interval(targetIntervalStart, targetIntervalEnd.truncate());
701 targetIntervalEnd.toInt());
702 } 701 }
703 } 702 }
704 703
705 /** 704 /**
706 * Simple list view class where each item has fixed width and height. 705 * Simple list view class where each item has fixed width and height.
707 */ 706 */
708 class ListView<D> extends GenericListView<D> { 707 class ListView<D> extends GenericListView<D> {
709 708
710 /** 709 /**
711 * Creates a new ListView for the given data. If [:_data:] is an 710 * Creates a new ListView for the given data. If [:_data:] is an
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 // Estimate length by taking the average of the lengths 798 // Estimate length by taking the average of the lengths
800 // of the known views. 799 // of the known views.
801 num lengthFromAllButLastElement = 0; 800 num lengthFromAllButLastElement = 0;
802 if (_itemOffsets.length > 2) { 801 if (_itemOffsets.length > 2) {
803 lengthFromAllButLastElement = 802 lengthFromAllButLastElement =
804 (getOffset(_itemOffsets.length - 2) - 803 (getOffset(_itemOffsets.length - 2) -
805 getOffset(0)) * 804 getOffset(0)) *
806 (_data.length / (_itemOffsets.length - 2)); 805 (_data.length / (_itemOffsets.length - 2));
807 } 806 }
808 return (lengthFromAllButLastElement + 807 return (lengthFromAllButLastElement +
809 Math.max(viewLength, _lengths[_lengths.length - 1])).toInt(); 808 Math.max(viewLength, _lengths[_lengths.length - 1])).truncate();
810 } else { 809 } else {
811 if (_lengths.length == 1) { 810 if (_lengths.length == 1) {
812 return Math.max(viewLength, _lengths[0]); 811 return Math.max(viewLength, _lengths[0]);
813 } else { 812 } else {
814 return viewLength; 813 return viewLength;
815 } 814 }
816 } 815 }
817 } 816 }
818 817
819 int getLength(int viewLength) { 818 int getLength(int viewLength) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 for (int i = 1; i < _data.length; i++) { 854 for (int i = 1; i < _data.length; i++) {
856 if (getOffset(i) + getOffset(i - 1) > -offset * 2) { 855 if (getOffset(i) + getOffset(i - 1) > -offset * 2) {
857 return i - 1; 856 return i - 1;
858 } 857 }
859 } 858 }
860 return _data.length - 1; 859 return _data.length - 1;
861 } 860 }
862 861
863 Interval computeVisibleInterval( 862 Interval computeVisibleInterval(
864 num offset, num viewLength, num bufferLength) { 863 num offset, num viewLength, num bufferLength) {
865 offset = offset.toInt(); 864 offset = offset.truncate();
866 int start = _findFirstItemBefore( 865 int start = _findFirstItemBefore(
867 -offset - bufferLength, 866 -offset - bufferLength,
868 _lastVisibleInterval != null ? _lastVisibleInterval.start : 0); 867 _lastVisibleInterval != null ? _lastVisibleInterval.start : 0);
869 int end = _findFirstItemAfter( 868 int end = _findFirstItemAfter(
870 -offset + viewLength + bufferLength, 869 -offset + viewLength + bufferLength,
871 _lastVisibleInterval != null ? _lastVisibleInterval.end : 0); 870 _lastVisibleInterval != null ? _lastVisibleInterval.end : 0);
872 _lastVisibleInterval = new Interval(start, Math.max(start, end)); 871 _lastVisibleInterval = new Interval(start, Math.max(start, end));
873 _lastOffset = offset; 872 _lastOffset = offset;
874 return _lastVisibleInterval; 873 return _lastVisibleInterval;
875 } 874 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 975
977 container = node.query('.dialog-body'); 976 container = node.query('.dialog-body');
978 container.nodes.add(_content.node); 977 container.nodes.add(_content.node);
979 978
980 return node; 979 return node;
981 } 980 }
982 981
983 /** Override to handle dialog done. */ 982 /** Override to handle dialog done. */
984 void onDone() { } 983 void onDone() { }
985 } 984 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698