├── LICENSE.txt ├── README.md ├── samples ├── 01_SimpleList │ ├── README.md │ └── src │ │ ├── Button.as │ │ ├── Main.as │ │ └── SampleCell.as ├── 02_RemovableList │ ├── README.md │ └── src │ │ ├── Main.as │ │ └── SampleCell.as ├── 03_SortableList │ ├── README.md │ └── src │ │ ├── DragIcon.as │ │ ├── Main.as │ │ └── SampleCell.as ├── 04_CustomizeScrollbar │ ├── README.md │ └── src │ │ ├── Main.as │ │ ├── SampleBar.as │ │ └── SampleCell.as ├── README.md └── demo │ ├── README.md │ └── src │ ├── Demo.as │ ├── SimpleCell.as │ └── SimpleScrollBar.as └── src └── com └── takumus └── ui ├── events ├── ListCellMouseEvent.as └── ListEvent.as └── list ├── CellData.as ├── List.as ├── ListCell.as ├── ScrollBar.as ├── _ClickableListCell.as ├── _Debugger.as ├── _ListCell.as └── _SortableListCell.as /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 takumus (http://takumus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # What is this? 2 | 3 | Simple and Fast listUI library for as3. 4 | 5 | # Use for 6 | 7 | - Flash contents. 8 | - AIR Application. 9 | - AIR for mobile. 10 | 11 | # Demo 12 | 13 | 14 | 15 | # How to use 16 | 17 | I am currently developing this library. 18 | -------------------------------------------------------------------------------- /samples/01_SimpleList/README.md: -------------------------------------------------------------------------------- 1 | #01 SimpleList 2 | demo -------------------------------------------------------------------------------- /samples/01_SimpleList/src/Button.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import flash.display.Sprite; 4 | import flash.text.TextField; 5 | 6 | public class Button extends Sprite 7 | { 8 | private var _label:TextField; 9 | private var _background:uint; 10 | public function Button(background:uint, label:String) 11 | { 12 | super(); 13 | _background = background; 14 | _label = new TextField(); 15 | _label.mouseEnabled = false; 16 | _label.autoSize = "left"; 17 | _label.text = label; 18 | this.addChild(_label); 19 | } 20 | public function resize(width:Number, height:Number):void 21 | { 22 | _label.x = width / 2 - _label.width / 2; 23 | _label.y = height / 2 - _label.height / 2; 24 | this.graphics.clear(); 25 | this.graphics.beginFill(_background); 26 | var round:Number = (width < height ? width : height)*0.4; 27 | this.graphics.drawRoundRect(0, 0, width, height, round, round); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /samples/01_SimpleList/src/Main.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import com.takumus.ui.events.ListEvent; 4 | import com.takumus.ui.list.List; 5 | 6 | import flash.display.Sprite; 7 | import flash.display.StageAlign; 8 | import flash.display.StageScaleMode; 9 | import flash.events.Event; 10 | import flash.text.TextField; 11 | 12 | [SWF(frameRate="60")] 13 | public class Main extends Sprite 14 | { 15 | private var _list:List; 16 | private var _textField:TextField; 17 | public function Main() 18 | { 19 | stage.align = StageAlign.TOP_LEFT; 20 | stage.scaleMode = StageScaleMode.NO_SCALE; 21 | 22 | init(); 23 | } 24 | 25 | private function init():void 26 | { 27 | //create List 28 | _list = new List(SampleCell, 60); 29 | addChild(_list); 30 | 31 | //create traceTextField 32 | _textField = new TextField(); 33 | _textField.background = true; 34 | _textField.border = true; 35 | addChild(_textField); 36 | 37 | //create Data 38 | var data:Array = []; 39 | for(var i:int = 0; i < 50; i ++){ 40 | data.push("data" + i); 41 | } 42 | 43 | //set data to List 44 | _list.setData(data); 45 | 46 | //add message event 47 | _list.addEventListener(ListEvent.MESSAGE, function(e:ListEvent):void 48 | { 49 | _textField.text = e.cellData.data + ":" + e.data; 50 | }); 51 | 52 | //resize list to stage 53 | this.stage.addEventListener(Event.RESIZE, function(e:Event):void 54 | { 55 | updateSize(); 56 | }); 57 | updateSize(); 58 | } 59 | 60 | private function updateSize():void 61 | { 62 | _list.resize(stage.stageWidth, stage.stageHeight); 63 | _textField.width = stage.stageWidth/2; 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /samples/01_SimpleList/src/SampleCell.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import com.takumus.ui.events.ListCellMouseEvent; 4 | import com.takumus.ui.list.CellData; 5 | import com.takumus.ui.list.List; 6 | import com.takumus.ui.list.ListCell; 7 | 8 | import flash.text.TextField; 9 | 10 | public class SampleCell extends ListCell{ 11 | private var _label:TextField; 12 | private var _buttonA:Button; 13 | private var _buttonB:Button; 14 | public function SampleCell(list:List):void 15 | { 16 | super(list); 17 | 18 | //label 19 | _label = new TextField(); 20 | _label.mouseEnabled = false; 21 | _label.autoSize = "left"; 22 | _label.text = "A"; 23 | //addChild to "body" 24 | body.addChild(_label); 25 | 26 | //button 27 | _buttonA = new Button(0xCCCCCC, "button A"); 28 | _buttonB = new Button(0xCCCCCC, "button B"); 29 | //addChild to "body" 30 | body.addChild(_buttonA); 31 | body.addChild(_buttonB); 32 | 33 | //body clicked 34 | this.body.addEventListener(ListCellMouseEvent.CLICK, function(e:ListCellMouseEvent):void 35 | { 36 | if(e.eventTarget == _buttonA){ 37 | message("A button clicked"); 38 | }else if(e.eventTarget == _buttonB){ 39 | message("B button clicked") 40 | }else{ 41 | message("body clicked"); 42 | } 43 | }); 44 | } 45 | 46 | //override resize 47 | protected override function resize(width:Number, height:Number):void 48 | { 49 | //render cell 50 | body.graphics.clear(); 51 | body.graphics.lineStyle(1,0xCCCCCC); 52 | body.graphics.beginFill(0xFFFFFF); 53 | body.graphics.drawRect(0,0,width, height); 54 | 55 | //label 56 | _label.y = (height - _label.height) * 0.5; 57 | _label.x = 10; 58 | 59 | //label 60 | _buttonA.x = width * 0.5 + 5; 61 | _buttonB.x = width * 0.75 + 5; 62 | _buttonA.y = 5; 63 | _buttonB.y = 5; 64 | _buttonA.resize(width*0.25 - 10, height - 10); 65 | _buttonB.resize(width*0.25 - 10, height - 10); 66 | } 67 | 68 | //override setData 69 | protected override function setData(data:CellData):void 70 | { 71 | //set data to label 72 | _label.text = data.data.toString(); 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /samples/02_RemovableList/README.md: -------------------------------------------------------------------------------- 1 | #02 RemovableList 2 | Click cell to remove. 3 | Top Left Area is debug window. 4 | List._debug = true; to enable this mode. 5 | demo 6 | -------------------------------------------------------------------------------- /samples/02_RemovableList/src/Main.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import com.takumus.ui.list.List; 4 | 5 | import flash.display.Sprite; 6 | import flash.display.StageAlign; 7 | import flash.display.StageScaleMode; 8 | import flash.events.Event; 9 | 10 | [SWF(frameRate="60")] 11 | public class Main extends Sprite 12 | { 13 | private var _list:List; 14 | 15 | public function Main() 16 | { 17 | stage.align = StageAlign.TOP_LEFT; 18 | stage.scaleMode = StageScaleMode.NO_SCALE; 19 | 20 | init(); 21 | } 22 | 23 | private function init():void 24 | { 25 | //enable debug mode 26 | List._debug = true; 27 | 28 | 29 | //create List 30 | _list = new List(SampleCell, 60); 31 | addChild(_list); 32 | 33 | //create Data 34 | var data:Array = []; 35 | for(var i:int = 0; i < 50; i ++){ 36 | data.push("data" + i); 37 | } 38 | 39 | //set data to List 40 | _list.setData(data); 41 | 42 | //resize list to stage 43 | this.stage.addEventListener(Event.RESIZE, function(e:Event):void 44 | { 45 | updateSize(); 46 | }); 47 | updateSize(); 48 | } 49 | 50 | private function updateSize():void 51 | { 52 | _list.resize(stage.stageWidth, stage.stageHeight); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /samples/02_RemovableList/src/SampleCell.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import com.takumus.ui.events.ListCellMouseEvent; 4 | import com.takumus.ui.list.CellData; 5 | import com.takumus.ui.list.List; 6 | import com.takumus.ui.list.ListCell; 7 | 8 | import flash.text.TextField; 9 | 10 | public class SampleCell extends ListCell{ 11 | private var _label:TextField; 12 | public function SampleCell(list:List):void 13 | { 14 | super(list); 15 | 16 | //label 17 | _label = new TextField(); 18 | _label.mouseEnabled = false; 19 | _label.autoSize = "left"; 20 | _label.text = "A"; 21 | 22 | //addChild to "body" 23 | body.addChild(_label); 24 | 25 | 26 | //click to remove 27 | //* do not use "MouseEvent" 28 | //* use "ListCellMouseEvent" 29 | body.addEventListener(ListCellMouseEvent.CLICK, function(e:ListCellMouseEvent):void 30 | { 31 | //call remove(); to remove this data 32 | remove(); 33 | }); 34 | } 35 | 36 | //override resize 37 | protected override function resize(width:Number, height:Number):void 38 | { 39 | //render cell 40 | body.graphics.clear(); 41 | body.graphics.lineStyle(1,0xCCCCCC); 42 | body.graphics.beginFill(0xFFFFFF); 43 | body.graphics.drawRect(0,0,width, height); 44 | 45 | _label.y = (height - _label.height) * 0.5; 46 | _label.x = 10; 47 | } 48 | 49 | //override setData 50 | protected override function setData(data:CellData):void 51 | { 52 | //set data to label 53 | _label.text = data.data.toString(); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /samples/03_SortableList/README.md: -------------------------------------------------------------------------------- 1 | #03 SortableList 2 | Drag right icon to begin sort. 3 | demo 4 | -------------------------------------------------------------------------------- /samples/03_SortableList/src/DragIcon.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import flash.display.Sprite; 4 | 5 | public class DragIcon extends Sprite{ 6 | public function DragIcon(size:Number):void 7 | { 8 | this.graphics.beginFill(0xCCCCCC); 9 | this.graphics.drawCircle(0, 0, size / 2); 10 | this.graphics.endFill(); 11 | 12 | size *= 0.5; 13 | 14 | this.graphics.lineStyle(3, 0xffffff); 15 | this.graphics.moveTo(-size * 0.5, - size * 0.5); 16 | this.graphics.lineTo(size * 0.5, - size * 0.5); 17 | 18 | this.graphics.moveTo(-size * 0.5, 0); 19 | this.graphics.lineTo(size * 0.5, 0); 20 | 21 | this.graphics.moveTo(-size * 0.5, size * 0.5); 22 | this.graphics.lineTo(size * 0.5, size * 0.5); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /samples/03_SortableList/src/Main.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import com.takumus.ui.list.List; 4 | 5 | import flash.display.Sprite; 6 | import flash.display.StageAlign; 7 | import flash.display.StageScaleMode; 8 | import flash.events.Event; 9 | 10 | [SWF(frameRate="60")] 11 | public class Main extends Sprite 12 | { 13 | private var _list:List; 14 | 15 | public function Main() 16 | { 17 | stage.align = StageAlign.TOP_LEFT; 18 | stage.scaleMode = StageScaleMode.NO_SCALE; 19 | 20 | init(); 21 | } 22 | 23 | private function init():void 24 | { 25 | //enable debug mode 26 | List._debug = true; 27 | 28 | 29 | //create List 30 | _list = new List(SampleCell, 60); 31 | addChild(_list); 32 | 33 | //create Data 34 | var data:Array = []; 35 | for(var i:int = 0; i < 10; i ++){ 36 | data.push(i); 37 | } 38 | 39 | //set data to List 40 | _list.setData(data); 41 | 42 | //resize list to stage 43 | this.stage.addEventListener(Event.RESIZE, function(e:Event):void 44 | { 45 | updateSize(); 46 | }); 47 | updateSize(); 48 | } 49 | 50 | private function updateSize():void 51 | { 52 | _list.resize(stage.stageWidth, stage.stageHeight); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /samples/03_SortableList/src/SampleCell.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import com.takumus.ui.events.ListCellMouseEvent; 4 | import com.takumus.ui.list.CellData; 5 | import com.takumus.ui.list.List; 6 | import com.takumus.ui.list.ListCell; 7 | 8 | import flash.text.TextField; 9 | 10 | public class SampleCell extends ListCell{ 11 | private var _label:TextField; 12 | private var _dragIcon:DragIcon; 13 | public function SampleCell(list:List):void 14 | { 15 | super(list); 16 | 17 | //label 18 | _label = new TextField(); 19 | _label.mouseEnabled = false; 20 | _label.autoSize = "left"; 21 | _label.text = "A"; 22 | 23 | //dragIcon for sort 24 | _dragIcon = new DragIcon(40); 25 | 26 | //addChild to "body" 27 | body.addChild(_label); 28 | body.addChild(_dragIcon); 29 | 30 | 31 | //mouse down to star drag 32 | //* do not use "MouseEvent" 33 | //* use "ListCellMouseEvent" 34 | body.addEventListener(ListCellMouseEvent.MOUSE_DOWN, function(e:ListCellMouseEvent):void 35 | { 36 | //if mouseDown on _dragIcon 37 | //begin sort from this cell. 38 | if(e.eventTarget == _dragIcon){ 39 | beginSort(); 40 | } 41 | }); 42 | } 43 | 44 | //override resize 45 | protected override function resize(width:Number, height:Number):void 46 | { 47 | //render cell 48 | body.graphics.clear(); 49 | body.graphics.lineStyle(1,0xCCCCCC); 50 | body.graphics.beginFill(0xFFFFFF); 51 | body.graphics.drawRect(0,0,width, height); 52 | 53 | _label.y = (height - _label.height) * 0.5; 54 | _label.x = 10; 55 | 56 | _dragIcon.x = width - _dragIcon.width * 0.5; 57 | _dragIcon.y = height * 0.5; 58 | } 59 | 60 | //override setData 61 | protected override function setData(data:CellData):void 62 | { 63 | //set data to label 64 | _label.text = data.data.toString(); 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /samples/04_CustomizeScrollbar/README.md: -------------------------------------------------------------------------------- 1 | #04 CustomizeScrollbar 2 | Customized scrollbar : src/SampleBar.as 3 | demo 4 | -------------------------------------------------------------------------------- /samples/04_CustomizeScrollbar/src/Main.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import com.takumus.ui.list.List; 4 | 5 | import flash.display.Sprite; 6 | import flash.display.StageAlign; 7 | import flash.display.StageScaleMode; 8 | import flash.events.Event; 9 | 10 | [SWF(frameRate="60")] 11 | public class Main extends Sprite 12 | { 13 | private var _list:List; 14 | 15 | public function Main() 16 | { 17 | stage.align = StageAlign.TOP_LEFT; 18 | stage.scaleMode = StageScaleMode.NO_SCALE; 19 | 20 | init(); 21 | } 22 | 23 | private function init():void 24 | { 25 | //create List 26 | //attach SampleBar to List 27 | _list = new List(SampleCell, 60, 0, new SampleBar()); 28 | addChild(_list); 29 | 30 | //create Data 31 | var data:Array = []; 32 | for(var i:int = 0; i < 50; i ++){ 33 | data.push("data" + i); 34 | } 35 | 36 | //set data to List 37 | _list.setData(data); 38 | 39 | //resize list to stage 40 | this.stage.addEventListener(Event.RESIZE, function(e:Event):void 41 | { 42 | updateSize(); 43 | }); 44 | updateSize(); 45 | } 46 | 47 | private function updateSize():void 48 | { 49 | _list.resize(stage.stageWidth, stage.stageHeight); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /samples/04_CustomizeScrollbar/src/SampleBar.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import com.takumus.ui.list.ScrollBar; 4 | 5 | public class SampleBar extends ScrollBar 6 | { 7 | public function SampleBar() 8 | { 9 | super(20); 10 | } 11 | override protected function render(width:Number, height:Number):void 12 | { 13 | //use content 14 | body.graphics.beginFill(0xff0000); 15 | body.graphics.drawRoundRect(0, 0, width, height, 20, 20); 16 | body.graphics.endFill(); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /samples/04_CustomizeScrollbar/src/SampleCell.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import com.takumus.ui.list.CellData; 4 | import com.takumus.ui.list.List; 5 | import com.takumus.ui.list.ListCell; 6 | 7 | import flash.text.TextField; 8 | 9 | public class SampleCell extends ListCell{ 10 | private var _label:TextField; 11 | public function SampleCell(list:List):void 12 | { 13 | super(list); 14 | 15 | //label 16 | _label = new TextField(); 17 | _label.mouseEnabled = false; 18 | _label.autoSize = "left"; 19 | _label.text = "A"; 20 | 21 | //addChild to "body" 22 | body.addChild(_label); 23 | } 24 | 25 | //override resize 26 | protected override function resize(width:Number, height:Number):void 27 | { 28 | //render cell 29 | body.graphics.clear(); 30 | body.graphics.lineStyle(1,0xCCCCCC); 31 | body.graphics.beginFill(0xFFFFFF); 32 | body.graphics.drawRect(0,0,width, height); 33 | 34 | _label.y = (height - _label.height) * 0.5; 35 | _label.x = 10; 36 | } 37 | 38 | //override setData 39 | protected override function setData(data:CellData):void 40 | { 41 | //set data to label 42 | _label.text = data.data.toString(); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /samples/README.md: -------------------------------------------------------------------------------- 1 | #Sample Demos 2 | demo 3 | 01_SimpleList 4 | 02_RemovableList 5 | 03_SortableList 6 | 04_CustomizeScrollbar 7 | -------------------------------------------------------------------------------- /samples/demo/README.md: -------------------------------------------------------------------------------- 1 | #Demo 2 | demo 3 | -------------------------------------------------------------------------------- /samples/demo/src/Demo.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import com.takumus.ui.events.ListEvent; 4 | import com.takumus.ui.list.List; 5 | 6 | import flash.display.Sprite; 7 | import flash.display.StageAlign; 8 | import flash.display.StageScaleMode; 9 | import flash.events.Event; 10 | import flash.text.TextField; 11 | import flash.text.TextFormat; 12 | 13 | [SWF(frameRate="60")] 14 | public class Demo extends Sprite 15 | { 16 | private var _list:List; 17 | private var _log:TextField; 18 | public function Demo() 19 | { 20 | stage.align = StageAlign.TOP_LEFT; 21 | stage.scaleMode = StageScaleMode.NO_SCALE; 22 | init(); 23 | } 24 | 25 | private function init():void 26 | { 27 | _list = new List(SimpleCell, 50, 0, new SimpleScrollBar()); 28 | addChild(_list); 29 | 30 | //add data to list 31 | _list.setData("ABCDEGFHIJKLMNOPQRSTU".split("")); 32 | 33 | //add message event from cell 34 | _list.addEventListener(ListEvent.MESSAGE, function(event:ListEvent):void{ 35 | log("message : {id:"+event.cellData.id + ", message:\"" + event.message + "\"}\n"); 36 | }); 37 | //add update event 38 | _list.addEventListener(ListEvent.UPDATE, function(event:ListEvent):void{ 39 | log("updated : ["); 40 | var tmpData:Array = _list.getData(); 41 | for(var i:int = 0; i < tmpData.length; i ++){ 42 | var data:String = tmpData[i]; 43 | log(data+","); 44 | } 45 | log("]\n"); 46 | }); 47 | //add remove event 48 | _list.addEventListener(ListEvent.REMOVE, function(event:ListEvent):void 49 | { 50 | log("removed : {id:"+event.cellData.id + ", data:" + event.cellData.data.toString() + "}\n"); 51 | }); 52 | 53 | //debug log 54 | _log = new TextField(); 55 | _log.width = _log.height = 400; 56 | _log.alpha = 0.5; 57 | _log.wordWrap = true; 58 | _log.defaultTextFormat = new TextFormat("", 12, 0x000000); 59 | _log.mouseEnabled = false; 60 | _log.border = true; 61 | _log.background = true; 62 | addChild(_log); 63 | 64 | //resize 65 | this.stage.addEventListener(Event.RESIZE, function(e:Event):void 66 | { 67 | resize(); 68 | }); 69 | 70 | resize(); 71 | } 72 | private function log(text:String):void 73 | { 74 | _log.appendText(text); 75 | _log.scrollV = _log.maxScrollV; 76 | } 77 | private function resize():void 78 | { 79 | _list.resize(stage.stageWidth, stage.stageHeight); 80 | _log.x = (stage.stageWidth - _log.width) / 2; 81 | _log.y = (stage.stageHeight - _log.height) / 2; 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /samples/demo/src/SimpleCell.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import com.takumus.ui.events.ListCellMouseEvent; 4 | import com.takumus.ui.list.CellData; 5 | import com.takumus.ui.list.List; 6 | import com.takumus.ui.list.ListCell; 7 | 8 | import flash.text.TextField; 9 | 10 | public class SimpleCell extends ListCell{ 11 | private var _label:TextField; 12 | private var _dragIcon:DragIcon; 13 | private var _removeIcon:RemoveIcon; 14 | public function SimpleCell(list:List):void 15 | { 16 | super(list); 17 | 18 | //label 19 | _label = new TextField(); 20 | 21 | //icons 22 | _dragIcon = new DragIcon(20); 23 | _removeIcon = new RemoveIcon(10); 24 | 25 | body.addChild(_label); 26 | body.addChild(_dragIcon); 27 | body.addChild(_removeIcon); 28 | 29 | _label.mouseEnabled = false; 30 | _label.autoSize = "left"; 31 | _label.text = "A"; 32 | 33 | //mousedown 34 | body.addEventListener(ListCellMouseEvent.MOUSE_DOWN, function(e:ListCellMouseEvent):void 35 | { 36 | 37 | if(body.mouseX > cellWidth - 70){ 38 | //if mousedown on right of cell, begin sort. 39 | beginSort(); 40 | } 41 | 42 | //another example 43 | /* 44 | if(e.eventTarget == _dragIcon){ 45 | beginSort(); 46 | } 47 | */ 48 | }); 49 | 50 | //click 51 | body.addEventListener(ListCellMouseEvent.CLICK, function(e:ListCellMouseEvent):void 52 | { 53 | if(body.mouseX < 70){ 54 | //if click on left of cell, remove this cell. 55 | remove(); 56 | }else if(body.mouseX < cellWidth - 70){ 57 | //if click on center of cell, message. 58 | message("Hi. My data is [" + data.data + "]"); 59 | } 60 | }); 61 | } 62 | //resize 63 | protected override function resize(width:Number, height:Number):void 64 | { 65 | //rerender on resize. 66 | body.graphics.clear(); 67 | body.graphics.lineStyle(1,0xCCCCCC); 68 | body.graphics.beginFill(0xFFFFFF); 69 | body.graphics.drawRect(0,0,width, height); 70 | 71 | //update positions 72 | _label.y = (height - _label.height) * 0.5; 73 | _label.x = 60; 74 | 75 | _dragIcon.x = width - 40; 76 | _dragIcon.y = height * 0.5; 77 | 78 | _removeIcon.x = 30; 79 | _removeIcon.y = height * 0.5; 80 | } 81 | //on set data 82 | protected override function setData(data:CellData):void 83 | { 84 | _label.text = data.data.toString(); 85 | } 86 | } 87 | } 88 | 89 | import flash.display.Shape; 90 | class DragIcon extends Shape{ 91 | public function DragIcon(size:Number):void 92 | { 93 | this.graphics.lineStyle(3, 0xCCCCCC); 94 | this.graphics.moveTo(-size * 0.5, - size * 0.5); 95 | this.graphics.lineTo(size * 0.5, - size * 0.5); 96 | 97 | this.graphics.moveTo(-size * 0.5, 0); 98 | this.graphics.lineTo(size * 0.5, 0); 99 | 100 | this.graphics.moveTo(-size * 0.5, size * 0.5); 101 | this.graphics.lineTo(size * 0.5, size * 0.5); 102 | } 103 | } 104 | 105 | class RemoveIcon extends Shape{ 106 | public function RemoveIcon(size:Number):void 107 | { 108 | this.graphics.lineStyle(3, 0xCCCCCC); 109 | 110 | this.graphics.moveTo(-size * 0.5, -size * 0.5); 111 | this.graphics.lineTo(size * 0.5, size * 0.5); 112 | 113 | this.graphics.moveTo(size * 0.5, -size * 0.5); 114 | this.graphics.lineTo(-size * 0.5, size * 0.5); 115 | } 116 | } -------------------------------------------------------------------------------- /samples/demo/src/SimpleScrollBar.as: -------------------------------------------------------------------------------- 1 | package { 2 | import com.takumus.ui.list.ScrollBar; 3 | 4 | /** 5 | * @author takumus 6 | */ 7 | public class SimpleScrollBar extends ScrollBar { 8 | public function SimpleScrollBar() { 9 | super(10, 50, 10); 10 | } 11 | protected override function render(width:Number, height:Number):void 12 | { 13 | body.graphics.clear(); 14 | body.graphics.beginFill(0x000000, 0.8); 15 | body.graphics.drawRect(0, 0, width, height); 16 | body.graphics.endFill(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/takumus/ui/events/ListCellMouseEvent.as: -------------------------------------------------------------------------------- 1 | package com.takumus.ui.events { 2 | import flash.events.Event; 3 | import flash.events.MouseEvent; 4 | 5 | public final class ListCellMouseEvent extends Event { 6 | public static const MOUSE_DOWN:String = "com.takumus.ui.events.ListCellMouseEvent.MOUSE_DOWN"; 7 | public static const MOUSE_DOWN_OTHER:String = "com.takumus.ui.events.ListCellMouseEvent.MOUSE_DOWN_OTHER"; 8 | public static const MOUSE_UP:String = "com.takumus.ui.events.ListCellMouseEvent.MOUSE_UP"; 9 | public static const MOUSE_UP_OTHER:String = "com.takumus.ui.events.ListCellMouseEvent.MOUSE_UP_OTHER"; 10 | 11 | public static const CLICK:String = "com.takumus.ui.events.ListCellMouseEvent.CLICK"; 12 | private var _parentEvent:MouseEvent; 13 | public function ListCellMouseEvent(type : String, parentEvent:MouseEvent) { 14 | super(type, false, false); 15 | _parentEvent = parentEvent; 16 | } 17 | public function get eventTarget():Object 18 | { 19 | return _parentEvent?_parentEvent.target:null; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/takumus/ui/events/ListEvent.as: -------------------------------------------------------------------------------- 1 | package com.takumus.ui.events { 2 | import com.takumus.ui.list.CellData; 3 | 4 | import flash.events.Event; 5 | 6 | /** 7 | * @author takumus 8 | */ 9 | public final class ListEvent extends Event { 10 | [Deprecated(deprecatedReplacement="MESSAGE")] 11 | public static const SELECT:String = "com.takumus.ui.events.ListEvent.MESSAGE"; 12 | public static const MESSAGE:String = "com.takumus.ui.events.ListEvent.MESSAGE"; 13 | public static const UPDATE:String = "com.takumus.ui.events.ListEvent.UPDATE"; 14 | public static const REMOVE:String = "com.takumus.ui.events.ListEvent.REMOVE"; 15 | public var cellData:CellData; 16 | public var data:Object; 17 | public var message:Object; 18 | public function ListEvent(type : String, bubbles : Boolean = false, cancelable : Boolean = false) { 19 | super(type, bubbles, cancelable); 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com/takumus/ui/list/CellData.as: -------------------------------------------------------------------------------- 1 | package com.takumus.ui.list 2 | { 3 | public class CellData{ 4 | public var id:int; 5 | public var data:Object; 6 | } 7 | } -------------------------------------------------------------------------------- /src/com/takumus/ui/list/List.as: -------------------------------------------------------------------------------- 1 | package com.takumus.ui.list 2 | { 3 | import com.takumus.ui.events.ListEvent; 4 | 5 | import flash.display.Sprite; 6 | import flash.events.Event; 7 | import flash.events.MouseEvent; 8 | 9 | public class List extends Sprite 10 | { 11 | private var _width:Number = 100, _height:Number = 100; 12 | 13 | private var _dataList:Vector.; 14 | private var _cellList:Vector.<_SortableListCell>; 15 | private var _cellListSize:int; 16 | private var _dataListSize:int; 17 | private var _cellHeight:Number; 18 | private var _realCellHeight:Number; 19 | private var _topY:Number = 0; 20 | private var _topYV:Number = 0; 21 | private var _topYVList:Vector.; 22 | private var _topId:int = 0; 23 | private var _contentsHeight:Number = 0; 24 | 25 | private var _mode:String; 26 | private var _mouseY:Number; 27 | private var _prevMouseY:Number; 28 | private var _mouseYV:Number; 29 | 30 | private var _cellForSort:ListCell; 31 | private var _sortInsertId:int = 0; 32 | private var _freezeScrollSort:Boolean; 33 | 34 | private var _cellContainer:Sprite; 35 | 36 | private var CellClass:Class; 37 | 38 | private var _startScrollHeight:Number = 50; 39 | private var _minScrollSpeed:Number = 30; 40 | 41 | private var _scrollBar:ScrollBar; 42 | 43 | private var _cellMode:String; 44 | 45 | public static var _bounceBack:Boolean = false; 46 | public static var _debug:Boolean = false; 47 | 48 | private var _enabled:Boolean; 49 | 50 | private var _backgroundColor:uint; 51 | private var _backgroundVisible:Boolean; 52 | 53 | private var _debugger:_Debugger; 54 | private var _cellSpace:Number; 55 | public function List(CellClass:Class, cellHeight:Number = 50, cellSpace:Number = 0, scrollBar:ScrollBar = null, defaultCellMode:String = "default", backgroundVisible:Boolean = true, backgroundColor:uint = 0xffffff) 56 | { 57 | super(); 58 | 59 | this.CellClass = CellClass; 60 | _cellSpace = cellSpace; 61 | this._backgroundColor = backgroundColor; 62 | this._backgroundVisible = backgroundVisible; 63 | 64 | _dataList = new Vector.(); 65 | _cellList = new Vector.<_SortableListCell>(); 66 | 67 | _topYVList = new Vector.(); 68 | 69 | _cellContainer = new Sprite(); 70 | 71 | if(scrollBar) { 72 | _scrollBar = scrollBar; 73 | }else{ 74 | _scrollBar = new ScrollBar(5, 50, 10); 75 | } 76 | 77 | _cellHeight = cellHeight; 78 | _realCellHeight = cellHeight + cellSpace; 79 | _cellForSort = new CellClass(this); 80 | _cellForSort._parent.visible = false; 81 | _cellForSort.useForSort = true; 82 | _cellMode = defaultCellMode; 83 | 84 | addChild(_cellContainer); 85 | addChild(_cellForSort._parent); 86 | 87 | addChild(_scrollBar._body); 88 | 89 | enabled = true; 90 | _mode = "none"; 91 | 92 | if(_debug) { 93 | _debugger = new _Debugger(200, 200, this); 94 | this.addChild(_debugger); 95 | } 96 | } 97 | public function resize(width:Number, height:Number):void 98 | { 99 | _width = width; 100 | _height = height; 101 | 102 | //前のセル数 103 | var prevCellListSize:int = _cellListSize; 104 | //今のセル数 105 | _cellListSize = int(_height / _realCellHeight + 0.5) + 2; 106 | //セルの差 107 | var cellListSizeDiff:int = _cellListSize - prevCellListSize; 108 | 109 | var cell:_SortableListCell; 110 | var i:int; 111 | if(cellListSizeDiff > 0){ 112 | //前よりもセルの数が多くなったら 113 | 114 | //その分を補う。 115 | for(i = 0; i < cellListSizeDiff; i ++){ 116 | cell = new CellClass(this); 117 | //セルのモードをセット(デフォルトモード) 118 | cell._setMode(_cellMode, true); 119 | _cellList.push(cell); 120 | _cellContainer.addChild(cell._parent); 121 | } 122 | }else if(cellListSizeDiff < 0){ 123 | //前より少なくなったら 124 | 125 | //その分を消す。 126 | for(i = 0; i < -cellListSizeDiff; i ++){ 127 | cell = _cellList.pop(); 128 | _cellContainer.removeChild(cell._parent); 129 | cell._dispose(); 130 | cell = null; 131 | } 132 | } 133 | 134 | //セル達をリサイズ 135 | for(i = 0; i < _cellListSize; i ++){ 136 | _cellList[i]._resize(_width, _cellHeight); 137 | } 138 | //ソート用のセルをリサイズ 139 | _cellForSort._resize(_width, _cellHeight); 140 | 141 | //更新 142 | update(null); 143 | 144 | //スクロールバー更新 145 | _scrollBar._body.x = _width - _scrollBar.width; 146 | _scrollBar.setViewHeight(_height); 147 | 148 | //背景描画 149 | if(_backgroundVisible) renderBackground(_width, _height); 150 | } 151 | public function setData(data:Array):void 152 | { 153 | _dataList.length = 0; 154 | for(var i:int = 0; i < data.length; i ++){ 155 | var cd:CellData = new CellData(); 156 | cd.data = data[i]; 157 | cd.id = i; 158 | _dataList.push(cd); 159 | } 160 | _dataListSize = _dataList.length; 161 | 162 | changeDataSize(); 163 | update(null); 164 | 165 | scrollPosition = 0; 166 | } 167 | public function addData(data:Object, first:Boolean = false):void 168 | { 169 | var cd:CellData = new CellData(); 170 | cd.data = data; 171 | cd.id = _dataListSize; 172 | if(first){ 173 | _dataList.unshift(cd); 174 | for(var i:int = 0; i < _dataList.length; i ++){ 175 | _dataList[i].id = i; 176 | } 177 | }else{ 178 | _dataList.push(cd); 179 | } 180 | _dataListSize = _dataList.length; 181 | changeDataSize(); 182 | } 183 | public function setCellMode(mode:String, def:Boolean = false):void 184 | { 185 | _cellMode = mode; 186 | _cellForSort._setMode(mode, def); 187 | for(var i:int = 0; i < _cellList.length; i ++){ 188 | //defモードでセット 189 | _cellList[i]._setMode(_cellMode, def); 190 | } 191 | } 192 | public function forceUpdateCell():void 193 | { 194 | for(var i:int = 0; i < _cellListSize; i ++){ 195 | var id:int = i + _topId; 196 | if(id < _dataListSize) _cellList[i]._setData(_dataList[id], true); 197 | } 198 | } 199 | public function get scrolling():Boolean{ 200 | return Math.abs(_topYV) > 1; 201 | } 202 | public function get cellMode():String 203 | { 204 | return _cellMode; 205 | } 206 | public function set enabled(value:Boolean):void 207 | { 208 | if(_enabled == value) return; 209 | _enabled = value; 210 | if(_enabled){ 211 | this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown); 212 | this.addEventListener(Event.ENTER_FRAME, update); 213 | }else{ 214 | this.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDown); 215 | this.removeEventListener(Event.ENTER_FRAME, update); 216 | } 217 | 218 | _enabled = value; 219 | } 220 | public function get enabled():Boolean 221 | { 222 | return _enabled; 223 | } 224 | public function getData():Array 225 | { 226 | var data:Array = []; 227 | for(var i:int = 0; i < _dataListSize; i ++){ 228 | data.push(_dataList[i].data); 229 | } 230 | return data; 231 | } 232 | public function getCell():Vector.<_SortableListCell> 233 | { 234 | return _cellList; 235 | } 236 | public function set scrollPosition(value:Number):void 237 | { 238 | if(scrollable){ 239 | _topY = -value * (_contentsHeight-_height); 240 | _topYV = 0; 241 | } 242 | } 243 | public function get scrollPosition():Number 244 | { 245 | return -_topY / (_contentsHeight-_height); 246 | } 247 | public function get cellContainer():Sprite 248 | { 249 | return _cellContainer; 250 | } 251 | 252 | private function renderBackground(width:Number, height:Number):void 253 | { 254 | this.graphics.clear(); 255 | this.graphics.beginFill(_backgroundColor); 256 | this.graphics.drawRect(0, 0, width, height); 257 | this.graphics.endFill(); 258 | } 259 | private function mouseDown(event:MouseEvent):void 260 | { 261 | _prevMouseY = mouseY; 262 | this.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp); 263 | //マウスダウン時はデフォでscrollStartする。 264 | if(_mode == "none") startScroll(); 265 | } 266 | private function mouseUp(event:MouseEvent):void 267 | { 268 | if(_mode == "scroll"){ 269 | stopScroll(); 270 | }else if(_mode == "sort"){ 271 | stopSort(); 272 | } 273 | this.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUp); 274 | } 275 | private function update(event:Event):void 276 | { 277 | _mouseYV = mouseY - _prevMouseY; 278 | if(_mode == "scroll"){ 279 | //----------------------------------------// 280 | //指でつかんでスクロール中 281 | //----------------------------------------// 282 | _topYV = stage.mouseY - _mouseY; 283 | _topYVList.push(_topYV); 284 | if(_topY + _topYV > 0 || !scrollable){ 285 | _topYV *= 0.5; 286 | if(!_bounceBack){ 287 | _topY = 0; 288 | _topYV = 0; 289 | } 290 | }else if(_topY + _topYV < -_contentsHeight + _height){ 291 | _topYV *= 0.5; 292 | if(!_bounceBack){ 293 | _topY = -_contentsHeight + _height; 294 | _topYV = 0; 295 | } 296 | }else{ 297 | 298 | } 299 | _mouseY = stage.mouseY; 300 | _topY += _topYV; 301 | }else if(_mode == "sort"){ 302 | //----------------------------------------// 303 | //指でつかんでソート中 304 | //----------------------------------------// 305 | _cellForSort._parent.y = mouseY - _cellHeight * 0.5; 306 | 307 | var scrollSpeed:Number = _contentsHeight / _height * 2; 308 | var scrollSpeedPer:Number = 0; 309 | var tmpMouseY:Number = 0; 310 | if(scrollSpeed < _minScrollSpeed){ 311 | scrollSpeed = _minScrollSpeed; 312 | } 313 | if(mouseY < _startScrollHeight){ 314 | tmpMouseY = _startScrollHeight - mouseY; 315 | scrollSpeedPer = tmpMouseY / _startScrollHeight; 316 | if(_mouseYV < 0) _freezeScrollSort = false; 317 | }else if(mouseY > _height - _startScrollHeight){ 318 | tmpMouseY = mouseY - (_height - _startScrollHeight); 319 | scrollSpeedPer = -tmpMouseY / _startScrollHeight; 320 | if(_mouseYV > 0) _freezeScrollSort = false; 321 | } 322 | if(_freezeScrollSort) scrollSpeedPer = 0; 323 | 324 | scrollSpeed *= scrollSpeedPer; 325 | _topYV = scrollSpeed; 326 | _topY += _topYV; 327 | 328 | if(_topY > 0 || !scrollable){ 329 | _topY = 0; 330 | _topYV = 0; 331 | }else if(_topY < -_contentsHeight + _height){ 332 | _topY = -_contentsHeight + _height; 333 | _topYV = 0; 334 | } 335 | }else{ 336 | //----------------------------------------// 337 | //指を離して慣性の法則働き中 338 | //----------------------------------------// 339 | _topY += _topYV; 340 | var fixV:Boolean = false; 341 | if(_topY > 0 || !scrollable){ 342 | _topY += (0 - _topY) * 0.15; 343 | 344 | if(_topYV > 0 || !scrollable) fixV = true; 345 | if(!_bounceBack){ 346 | _topY = 0; 347 | _topYV = 0; 348 | } 349 | }else if(_topY < -_contentsHeight + _height){ 350 | _topY += (-_contentsHeight + _height - _topY) * 0.15; 351 | 352 | if(_topYV < 0) fixV = true; 353 | if(!_bounceBack){ 354 | _topY = -_contentsHeight + _height; 355 | _topYV = 0; 356 | } 357 | } 358 | if(fixV){ 359 | //逆らう加速度だったら、加速度減らす。 360 | _topYV += (0 - _topYV) * 0.3; 361 | }else{ 362 | _topYV *= 0.98; 363 | } 364 | } 365 | 366 | //先頭のデータid 367 | var tmpTopId:int = -_topY / _realCellHeight; 368 | //データidの変化 369 | var topIdV:int = tmpTopId - _topId; 370 | _topId = tmpTopId; 371 | //idの変化からセルの並べ替え 372 | optimizeCells(topIdV); 373 | 374 | //高速スクロール時は、ソートのアニメーションをしないよ! 375 | var needAnimation:Boolean = (_topYV<0?-_topYV:_topYV) < _realCellHeight; 376 | 377 | var scY:Number = _cellForSort._parent.y; 378 | _sortInsertId = _topId; 379 | for(var i:int = 0; i < _cellListSize; i ++){ 380 | var id:int = i + _topId; 381 | 382 | if(id < 0 || id >= _dataListSize) { 383 | _cellList[i]._parent.visible = false; 384 | continue; 385 | }else{ 386 | _cellList[i]._parent.visible = true; 387 | } 388 | 389 | _cellList[i]._setData(_dataList[id], false); 390 | _cellList[i]._parent.y = _cellSpace + _topY%_realCellHeight + i * (_realCellHeight); 391 | _cellList[i].cellId = i; 392 | //ソートモードの場合 393 | if(_mode == "sort"){ 394 | if(scY < _cellList[i]._yForSort){ 395 | _cellList[i]._parent.y += _cellSpace; 396 | //下へずらす 397 | _cellList[i]._setPosition("bottom", needAnimation); 398 | }else{ 399 | //上へずらす 400 | _cellList[i]._setPosition("center", needAnimation); 401 | _sortInsertId = _cellList[i].data.id + 1; 402 | } 403 | } 404 | } 405 | 406 | 407 | //スクロールバー移動 408 | _scrollBar.setContentY(_topY); 409 | } 410 | private function get scrollable():Boolean 411 | { 412 | return _contentsHeight > _height; 413 | } 414 | //----------------------------------------------------------// 415 | //選択 416 | //----------------------------------------------------------// 417 | private function messageFromCell(dataId:int, data:Object = null):void 418 | { 419 | var e:ListEvent = new ListEvent(ListEvent.MESSAGE); 420 | e.cellData = _dataList[dataId]; 421 | e.data = data; 422 | e.message = data; 423 | dispatchEvent(e); 424 | } 425 | //----------------------------------------------------------// 426 | //削除 427 | //----------------------------------------------------------// 428 | private function remove(dataId:int, cellId:int):void 429 | { 430 | var e:ListEvent = new ListEvent(ListEvent.REMOVE); 431 | e.cellData = _dataList.splice(dataId, 1)[0]; 432 | _dataListSize = _dataList.length; 433 | updateDataListId(); 434 | var i:int; 435 | 436 | if(_topY - 5 < -_contentsHeight + _height && scrollable){ 437 | //一番下へ行っている 438 | for(i = 0; i < cellId; i ++){ 439 | //対象以降を下へずらす 440 | _cellList[i]._setPosition("top", false); 441 | //上へ戻す 442 | _cellList[i]._setPosition("center", true); 443 | } 444 | }else{ 445 | //一番下へ行っていない 446 | for(i = cellId; i < _cellListSize; i ++){ 447 | //対象以降を下へずらす 448 | _cellList[i]._setPosition("bottom", false); 449 | //上へ戻す 450 | _cellList[i]._setPosition("center", true); 451 | } 452 | } 453 | changeDataSize(); 454 | update(null); 455 | 456 | dispatchEvent(e); 457 | } 458 | 459 | //----------------------------------------------------------// 460 | //スクロール 461 | //----------------------------------------------------------// 462 | private function startScroll():void 463 | { 464 | _mode = "scroll"; 465 | start(); 466 | } 467 | private function stopScroll():void 468 | { 469 | //加速度をframe分の平均をとって計算 470 | _topYVList.reverse(); 471 | _topYV = 0; 472 | var frame:int = 5; 473 | var length:int = _topYVList.length 0){ 541 | for(i = 0; i < idV; i ++){ 542 | cell = _cellList.shift(); 543 | _cellList.push(cell); 544 | if(_mode == "sort"){ 545 | //下へずらす 546 | cell._setPosition("bottom", false); 547 | } 548 | } 549 | }else if(idV < 0){ 550 | idV = -idV; 551 | for(i = 0; i < idV; i ++){ 552 | cell = _cellList.pop(); 553 | _cellList.unshift(cell); 554 | if(_mode == "sort"){ 555 | //下へずらす 556 | cell._setPosition("center", false); 557 | } 558 | } 559 | } 560 | } 561 | //セルのデータidを再適用 562 | private function updateDataListId():void 563 | { 564 | for(var i:int = 0; i < _dataListSize; i ++){ 565 | _dataList[i].id = i; 566 | } 567 | } 568 | //データ数に変化が当たっとき! 569 | private function changeDataSize():void 570 | { 571 | _contentsHeight = _dataListSize * (_realCellHeight) + _cellSpace; 572 | //スクロールバー更新 573 | _scrollBar.setContentHeight(_contentsHeight); 574 | 575 | //アップデートイベントを出す 576 | dispatchEvent(new ListEvent(ListEvent.UPDATE)); 577 | } 578 | 579 | //セルからのアクション 580 | internal function _cell_beginSort(dataId:int, cellId:int):void 581 | { 582 | beginSort(dataId, cellId); 583 | } 584 | internal function _cell_remove(dataId:int, cellId:int):void 585 | { 586 | remove(dataId, cellId); 587 | } 588 | internal function _cell_message(dataId:int, data:Object = null):void 589 | { 590 | messageFromCell(dataId, data); 591 | } 592 | } 593 | } -------------------------------------------------------------------------------- /src/com/takumus/ui/list/ListCell.as: -------------------------------------------------------------------------------- 1 | package com.takumus.ui.list 2 | { 3 | public class ListCell extends _SortableListCell 4 | { 5 | public function ListCell(list:List) 6 | { 7 | super(list); 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /src/com/takumus/ui/list/ScrollBar.as: -------------------------------------------------------------------------------- 1 | package com.takumus.ui.list 2 | { 3 | import flash.display.Sprite; 4 | 5 | public class ScrollBar { 6 | internal var _body:Sprite; 7 | 8 | private var _width:Number; 9 | private var _viewHeight:Number; 10 | private var _contentHeight:Number; 11 | 12 | private var _barHeight:Number; 13 | 14 | private var _barMinHeight:Number; 15 | private var _barMinCompressedHeight:Number; 16 | 17 | private var _prevRenderBarHeight:int; 18 | public function ScrollBar(barWidth:Number, barMinHeight:Number = 100, barMinCompressedHeight:Number = 10) 19 | { 20 | _width = barWidth; 21 | _barMinHeight = barMinHeight; 22 | _barMinCompressedHeight = barMinCompressedHeight; 23 | _body = new Sprite(); 24 | //this.addChild(content); 25 | } 26 | //表示部分の高さを指定 27 | public function setViewHeight(value:Number):void 28 | { 29 | _viewHeight = value; 30 | updateBarHeight(); 31 | } 32 | //中身の高さを指定 33 | public function setContentHeight(value:Number):void 34 | { 35 | _contentHeight = value; 36 | updateBarHeight(); 37 | } 38 | //スクロール位置を指定 39 | public function setContentY(contentY:int):void 40 | { 41 | var ratio:Number = (-contentY) / (_contentHeight - _viewHeight); 42 | var over:Number = 0; 43 | var barHeight:Number = _barHeight; 44 | //overを求める 45 | if(ratio < 0){ 46 | //上にはみ出たら 47 | over = contentY; 48 | }else if(ratio > 1){ 49 | //下にはみ出たら 50 | over = _viewHeight - (_contentHeight + contentY); 51 | } 52 | 53 | //バーの最小の高さをセット 54 | barHeight -= over; 55 | if(barHeight < _barMinCompressedHeight) barHeight = _barMinCompressedHeight; 56 | 57 | //バーを移動 58 | if(ratio < 0){ 59 | //上にはみ出たら 60 | _body.y = 0; 61 | }else if(ratio > 1){ 62 | //下にはみ出たら 63 | _body.y = (_viewHeight - barHeight); 64 | }else{ 65 | _body.y = ratio * (_viewHeight - barHeight); 66 | } 67 | 68 | _render(barHeight); 69 | } 70 | private function updateBarHeight():void 71 | { 72 | _body.visible = _viewHeight <= _contentHeight; 73 | 74 | var height:Number = (_viewHeight / _contentHeight) * _viewHeight; 75 | if(height < _barMinHeight) height = _barMinHeight; 76 | 77 | _barHeight = height; 78 | } 79 | private function _render(height:Number):void 80 | { 81 | //前と同じ大きさだったら再レンダリングしない 82 | if(_prevRenderBarHeight == int(height)) return; 83 | _prevRenderBarHeight = height; 84 | 85 | render(_width, height); 86 | } 87 | protected function render(width:Number, height:Number):void 88 | { 89 | _body.graphics.clear(); 90 | _body.graphics.beginFill(0x000000, 0.3); 91 | _body.graphics.drawRect(0, 0, width, height); 92 | _body.graphics.endFill(); 93 | } 94 | 95 | public function get width():Number 96 | { 97 | return _width; 98 | } 99 | public function get height():Number 100 | { 101 | return _viewHeight; 102 | } 103 | public function get body():Sprite 104 | { 105 | return _body; 106 | } 107 | } 108 | } -------------------------------------------------------------------------------- /src/com/takumus/ui/list/_ClickableListCell.as: -------------------------------------------------------------------------------- 1 | package com.takumus.ui.list 2 | { 3 | import com.takumus.ui.events.ListCellMouseEvent; 4 | 5 | import flash.events.MouseEvent; 6 | 7 | public class _ClickableListCell extends _ListCell 8 | { 9 | private var _pressed:Boolean; 10 | private var _startX:Number; 11 | private var _startY:Number; 12 | public function _ClickableListCell(list:List) 13 | { 14 | super(list); 15 | this.body.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown); 16 | } 17 | private function mouseMove(event:MouseEvent):void 18 | { 19 | if( Math.abs(_startX - body.stage.mouseX) > 10|| 20 | Math.abs(_startY - body.stage.mouseY) > 10){ 21 | _pressed = false; 22 | mouseUp(null); 23 | } 24 | } 25 | private function mouseUp(event:MouseEvent):void 26 | { 27 | body.dispatchEvent(new ListCellMouseEvent(ListCellMouseEvent.MOUSE_UP, event)); 28 | if(_pressed){ 29 | body.dispatchEvent(new ListCellMouseEvent(ListCellMouseEvent.CLICK, event)); 30 | } 31 | body.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUp); 32 | body.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMove); 33 | 34 | var cellList:Vector.<_SortableListCell> = list.getCell(); 35 | //trace(cellId); 36 | for(var i:int = 0; i < cellList.length; i ++){ 37 | if(cellList[i].cellId != cellId) cellList[i]._mouse_up_other(); 38 | //trace(":"+cellList[i].cellId); 39 | } 40 | } 41 | private function mouseDown(event:MouseEvent):void 42 | { 43 | if(scrolling) return; 44 | _pressed = true; 45 | _startX = body.stage.mouseX; 46 | _startY = body.stage.mouseY; 47 | body.dispatchEvent(new ListCellMouseEvent(ListCellMouseEvent.MOUSE_DOWN, event)); 48 | body.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp); 49 | body.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove); 50 | 51 | var cellList:Vector.<_SortableListCell> = list.getCell(); 52 | for(var i:int = 0; i < cellList.length; i ++){ 53 | if(cellList[i].cellId != cellId) cellList[i]._mouse_down_other(); 54 | } 55 | } 56 | override internal function _dispose():void 57 | { 58 | this.body.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDown); 59 | super._dispose(); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /src/com/takumus/ui/list/_Debugger.as: -------------------------------------------------------------------------------- 1 | package com.takumus.ui.list 2 | { 3 | import com.takumus.ui.events.ListEvent; 4 | 5 | import flash.display.Sprite; 6 | import flash.text.TextField; 7 | import flash.text.TextFormat; 8 | 9 | internal class _Debugger extends Sprite 10 | { 11 | private var _log:TextField; 12 | private var _list:List; 13 | public function _Debugger(width:Number, height:Number, list:List) 14 | { 15 | super(); 16 | _list = list; 17 | 18 | _log = new TextField(); 19 | _log.defaultTextFormat = new TextFormat("Consolas"); 20 | _log.border = true; 21 | _log.background = true; 22 | _log.alpha = 0.8; 23 | _log.width = width; 24 | _log.height = height; 25 | this.mouseEnabled = false; 26 | this.addChild(_log); 27 | 28 | initEvents(); 29 | } 30 | private function initEvents():void 31 | { 32 | _list.addEventListener(ListEvent.REMOVE, function(e:ListEvent):void{ 33 | add("remove:{\n" + 34 | " data : " + e.cellData.data + "\n" + 35 | " id : " + e.cellData.id + "\n" + 36 | "}"); 37 | }); 38 | _list.addEventListener(ListEvent.MESSAGE, function(e:ListEvent):void{ 39 | add("message:{\n" + 40 | " data : " + e.cellData.data + "\n" + 41 | " id : " + e.cellData.id + "\n" + 42 | "}"); 43 | }); 44 | _list.addEventListener(ListEvent.UPDATE, function(e:ListEvent):void{ 45 | add("update:{\n" + 46 | " data : " + 47 | _list.getData()+"\n"+ 48 | "}"); 49 | }); 50 | } 51 | public function add(log:String):void 52 | { 53 | if(!List._debug) return; 54 | _log.appendText(log + "\n"); 55 | _log.scrollV = _log.maxScrollV; 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/com/takumus/ui/list/_ListCell.as: -------------------------------------------------------------------------------- 1 | package com.takumus.ui.list 2 | { 3 | import com.takumus.ui.events.ListCellMouseEvent; 4 | 5 | import flash.display.Sprite; 6 | 7 | internal class _ListCell{ 8 | //セルの大きさ 9 | private var _cellHeight:Number, _cellWidth:Number; 10 | 11 | private var _data:CellData; 12 | internal var _parent:Sprite; 13 | protected var body:Sprite; 14 | private var _list:List; 15 | private var _mode:String; 16 | internal var cellId:int; 17 | public function _ListCell(list:List):void 18 | { 19 | this._list = list; 20 | _parent = new Sprite(); 21 | this.body = new Sprite(); 22 | _parent.addChild(body); 23 | } 24 | 25 | public final function get data():CellData 26 | { 27 | return _data; 28 | } 29 | public final function get dataId():int 30 | { 31 | return data.id; 32 | } 33 | 34 | protected function setData(data:CellData):void 35 | { 36 | } 37 | protected function resize(width:Number, height:Number):void 38 | { 39 | } 40 | protected function dispose():void 41 | { 42 | } 43 | protected final function remove():void 44 | { 45 | _list._cell_remove(dataId, cellId); 46 | } 47 | [Deprecated(deprecatedReplacement="message")] 48 | protected final function select(args:Object = null):void 49 | { 50 | _list._cell_message(dataId, args); 51 | } 52 | protected final function message(data:Object):void 53 | { 54 | _list._cell_message(dataId, data); 55 | } 56 | protected final function get cellHeight():Number 57 | { 58 | return _cellHeight; 59 | } 60 | protected final function get cellWidth():Number 61 | { 62 | return _cellWidth; 63 | } 64 | protected final function get scrolling():Boolean 65 | { 66 | return _list.scrolling; 67 | } 68 | protected function get list():List 69 | { 70 | return _list; 71 | } 72 | protected function get mode():String 73 | { 74 | return _mode; 75 | } 76 | protected function setMode(mode:String, def:Boolean):void 77 | { 78 | 79 | } 80 | internal function _mouse_down_other():void 81 | { 82 | body.dispatchEvent(new ListCellMouseEvent(ListCellMouseEvent.MOUSE_DOWN_OTHER, null)); 83 | } 84 | internal function _mouse_up_other():void 85 | { 86 | body.dispatchEvent(new ListCellMouseEvent(ListCellMouseEvent.MOUSE_UP_OTHER, null)); 87 | } 88 | internal function _dispose():void 89 | { 90 | dispose(); 91 | } 92 | internal function _setData(data:CellData, force:Boolean = false):void 93 | { 94 | if(!force){ 95 | if(_data == data){ 96 | return; 97 | } 98 | } 99 | _data = data; 100 | setData(data); 101 | } 102 | internal function _resize(width:Number, height:Number):void 103 | { 104 | _cellWidth = width; 105 | _cellHeight = height; 106 | 107 | resize(width, height); 108 | } 109 | internal function _setMode(mode:String, def:Boolean):void 110 | { 111 | _mode = mode; 112 | this.setMode(mode, def); 113 | } 114 | } 115 | } -------------------------------------------------------------------------------- /src/com/takumus/ui/list/_SortableListCell.as: -------------------------------------------------------------------------------- 1 | package com.takumus.ui.list 2 | { 3 | import flash.events.Event; 4 | 5 | internal class _SortableListCell extends _ClickableListCell{ 6 | //sort用 7 | private var _position:String; 8 | private var _useForSort:Boolean; 9 | private var _targetY:Number; 10 | private var _playing:Boolean; 11 | public function _SortableListCell(list:List):void 12 | { 13 | super(list); 14 | } 15 | protected final function beginSort():void 16 | { 17 | if(_useForSort) return; 18 | list._cell_beginSort(data.id, cellId); 19 | } 20 | public function set useForSort(val:Boolean):void 21 | { 22 | _useForSort = val; 23 | } 24 | internal function _setPosition(position:String, animate:Boolean = false):void 25 | { 26 | if(_position == position) return; 27 | _position = position; 28 | 29 | var y:Number; 30 | if(_position == "bottom"){ 31 | y = cellHeight; 32 | }else if(_position == "center"){ 33 | y = 0; 34 | }else{; 35 | y = -cellHeight; 36 | } 37 | _targetY = y; 38 | if(!animate){ 39 | body.y = y; 40 | return; 41 | } 42 | 43 | stopAnimation(); 44 | startAnimation(); 45 | } 46 | internal function get _yForSort():Number 47 | { 48 | return _parent.y + body.y; 49 | } 50 | 51 | private function animation(event:Event):void 52 | { 53 | body.y += (_targetY - body.y)*0.4; 54 | var diff:Number = body.y - _targetY; 55 | diff *= diff<0?-1:1; 56 | if(diff < 1){ 57 | body.y = _targetY; 58 | stopAnimation(); 59 | } 60 | } 61 | private function startAnimation():void 62 | { 63 | body.addEventListener(Event.ENTER_FRAME, animation); 64 | _playing = true; 65 | } 66 | private function stopAnimation():void 67 | { 68 | if(_playing) body.removeEventListener(Event.ENTER_FRAME, animation); 69 | _playing = false; 70 | } 71 | } 72 | } --------------------------------------------------------------------------------