Skip to content

Commit

Permalink
(split)Fix addTab in TabPanel, also move tabs buttons to bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-miryanov committed Dec 19, 2011
1 parent 5da2901 commit ac23a4d
Showing 1 changed file with 51 additions and 16 deletions.
67 changes: 51 additions & 16 deletions bit101/components/TabPanel.hx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TabPanel extends Component
{
var _tabs:Array<Dynamic>;
var _hbox:HBox;
var TABS : Int;


/**
Expand All @@ -44,8 +45,9 @@ class TabPanel extends Component
* @param xpos The x position to place this component.
* @param ypos The y position to place this component.
*/
public function new(?parent:Dynamic = null, ?xpos:Float = 0, ?ypos:Float = 0)
public function new(?parent:Dynamic = null, ?xpos:Float = 0, ?ypos:Float = 0, ?tabs = 2)
{
TABS = tabs;
super(parent, xpos, ypos);
}

Expand All @@ -64,7 +66,6 @@ class TabPanel extends Component
*/
override function addChildren():Void
{
var TABS:Int = 2;
var tab:PushButton;
var panel:Panel;

Expand All @@ -78,14 +79,17 @@ class TabPanel extends Component
tab = new PushButton(_hbox, 0,0, "Tab " + i, tabSelected);
tab.toggle = true;

panel = new Panel(this, 0, tab.height);
panel = new Panel(this, 0, tab.height - 1);
panel.visible = false;

_tabs.push({tab:tab, panel:panel});
}

cast(_tabs[0].tab, PushButton).selected = true;
cast(_tabs[0].panel, Panel).visible = true;
if (_tabs.length > 0)
{
cast(_tabs[0].tab, PushButton).selected = true;
cast(_tabs[0].panel, Panel).visible = true;
}
}

///////////////////////////////////
Expand All @@ -96,13 +100,14 @@ class TabPanel extends Component
* Adds a new window to the bottom of the accordion.
* @param title The title of the new tab.
*/
public function addTab(title:String):Void
public function addTab(title:String):Int
{
addTabAt(title, _tabs.length);
return addTabAt(title, _tabs.length);
}

public function addTabAt(title:String, index:Int):Void
public function addTabAt(title:String, index:Int):Int
{
var isNew : Bool = _tabs.length == 0;

var pb:PushButton;
var p:Panel;
Expand All @@ -114,26 +119,47 @@ class TabPanel extends Component
pb.toggle = true;
pb.selected = false;

p = new Panel(this, 0, pb.height);
p = new Panel(this, 0, pb.height - 1);
p.visible = false;

_hbox.addChildAt(pb, index);

_tabs.insert(index, {tab:pb, panel:p});

if (isNew)
{
cast(_tabs[0].tab, PushButton).selected = true;
cast(_tabs[0].panel, Panel).visible = true;
}

_resize ();
invalidate();
return index;
}


override public function draw():Void
{

private function _resize () : Void
{
var tabW:Float = Math.round(width / _tabs.length);
var tabH:Float = cast(_tabs[0].tab, PushButton).height;

for (i in 0..._tabs.length)
{
_tabs[i].tab.width = tabW;
_tabs[i].panel.setSize(width, height - tabH);
cast (_tabs[i].tab, PushButton).width = tabW;
cast (_tabs[i].panel, Panel).setSize(width, height - tabH);
}
}


override public function draw():Void
{
_hbox.setY (height - _hbox.height);
for (i in 0..._tabs.length)
{
_tabs[i].panel.setY (0);
}

_resize ();

_hbox.draw();
}

Expand All @@ -150,7 +176,7 @@ class TabPanel extends Component
public function setTabNameAt(name:String, index:Int):Void
{
if (index >= _tabs.length) return;
_tabs[index].tab.label = name;
cast (_tabs[index].tab, PushButton).label = name;
invalidate();
}

Expand Down Expand Up @@ -186,5 +212,14 @@ class TabPanel extends Component
}
}

public function getHeaderHeight () : Float
{
return _hbox.height;
}

public function getPanelHeight () : Float
{
return getHeight () - getHeaderHeight ();
}

}

0 comments on commit ac23a4d

Please sign in to comment.