Skip to content

Commit da0a36d

Browse files
committed
tabbar tweaks (left / right fillers)
1 parent cb54f6b commit da0a36d

File tree

2 files changed

+82
-8
lines changed

2 files changed

+82
-8
lines changed

haxe/ui/_module/styles/default/tabs.css

+24-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
border-bottom-color: $normal-border-color;
1111
border-top-width: 0px;
1212
clip: true;
13+
spacing: 8px;
1314
}
1415

1516
.tabbar > .tabbar-contents {
@@ -82,12 +83,24 @@
8283
icon: $arrow-left;
8384
border-radius: 0;
8485
padding: 5px;
86+
margin-left: 2px;
8587
}
8688

8789
.tabbar-scroll-right {
8890
icon: $arrow-right;
8991
border-radius: 0;
9092
padding: 5px;
93+
margin-left: 3px;
94+
}
95+
96+
.tabbar-filler-left {
97+
width: 1px;
98+
background-color: $normal-border-color;
99+
}
100+
101+
.tabbar-filler-right {
102+
width: 1px;
103+
background-color: $normal-border-color;
91104
}
92105

93106
.tabbar-button-selected .label {
@@ -205,6 +218,16 @@
205218
border-bottom-right-radius: 4px;
206219
}
207220

221+
.rounded-tabs .tabbar .tabbar-scroll-left {
222+
border-top-left-radius: 3px;
223+
border-bottom-left-radius: 3px;
224+
}
225+
226+
.rounded-tabs .tabbar .tabbar-scroll-right {
227+
border-top-right-radius: 3px;
228+
border-bottom-right-radius: 3px;
229+
}
230+
208231
/************************************************************************
209232
** TABVIEW
210233
*************************************************************************/
@@ -253,4 +276,4 @@
253276

254277
.full-width-buttons .tabbar-button, .full-width-buttons .tabbar > .tabbar-contents {
255278
width: 100%;
256-
}
279+
}

haxe/ui/components/TabBar.hx

+58-7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ class TabBarLayout extends DefaultLayout {
6060
filler.left = container.width;
6161
}
6262

63+
var leftFiller:Component = _component.findComponent("tabbar-filler-left", false);
64+
if (leftFiller != null) {
65+
leftFiller.height = _component.height;
66+
}
67+
68+
var rightFiller:Component = _component.findComponent("tabbar-filler-right", false);
69+
if (rightFiller != null) {
70+
rightFiller.left = _component.width - rightFiller.width;
71+
rightFiller.height = _component.height;
72+
}
73+
6374
var max:Float = 0;
6475
for (button in container.childComponents) {
6576
button.validateNow();
@@ -80,12 +91,12 @@ class TabBarLayout extends DefaultLayout {
8091
if (right != null) {
8192
x -= right.width;
8293
}
83-
left.left = x + 1;
94+
left.left = x - left.style.marginLeft;
8495
left.top = (_component.height / 2) - (left.height / 2);
8596
}
8697

8798
if (right != null && hidden(right) == false) {
88-
right.left = _component.width - right.width;
99+
right.left = _component.width - right.width - right.marginLeft;
89100
right.top = (_component.height / 2) - (right.height / 2);
90101
}
91102
}
@@ -206,6 +217,7 @@ private class SelectedIndex extends DataBehaviour {
206217

207218
builder._containerPosition = x;
208219
builder._container.left = x;
220+
builder.checkLeftRightFillers();
209221
}
210222

211223
_component.invalidateComponentLayout();
@@ -409,6 +421,8 @@ private class Builder extends CompositeBuilder {
409421
_filler = new Box();
410422
_filler.id = "tabbar-filler";
411423
_filler.addClass("tabbar-filler");
424+
_filler.scriptAccess = false;
425+
_filler.includeInLayout = false;
412426
_tabbar.addComponent(_filler);
413427
}
414428
if (_container == null) {
@@ -492,21 +506,21 @@ private class Builder extends CompositeBuilder {
492506
}
493507

494508
public override function addComponent(child:Component):Component {
495-
if (child != _container && child != _scrollLeft && child != _scrollRight && child != _filler) {
509+
if (child != _container && child != _scrollLeft && child != _scrollRight && child != _filler && child.id != "tabbar-filler-left" && child.id != "tabbar-filler-right") {
496510
return addTab(child);
497511
}
498512
return null;
499513
}
500514

501515
public override function addComponentAt(child:Component, index:Int):Component {
502-
if (child != _container && child != _scrollLeft && child != _scrollRight && child != _filler) {
516+
if (child != _container && child != _scrollLeft && child != _scrollRight && child != _filler && child.id != "tabbar-filler-left" && child.id != "tabbar-filler-right") {
503517
return addTabAt(child, index);
504518
}
505519
return null;
506520
}
507521

508522
public override function removeComponent(child:Component, dispose:Bool = true, invalidate:Bool = true):Component {
509-
if (child != _container && child != _scrollLeft && child != _scrollRight && child != _filler) {
523+
if (child != _container && child != _scrollLeft && child != _scrollRight && child != _filler && child.id != "tabbar-filler-left" && child.id != "tabbar-filler-right") {
510524
var index = _container.getComponentIndex(child);
511525
if (index != -1) {
512526
_tabbar.removeTab(index);
@@ -525,14 +539,14 @@ private class Builder extends CompositeBuilder {
525539
}
526540

527541
public override function getComponentIndex(child:Component):Int {
528-
if (child != _container && child != _scrollLeft && child != _scrollRight && child != _filler) {
542+
if (child != _container && child != _scrollLeft && child != _scrollRight && child != _filler && child.id != "tabbar-filler-left" && child.id != "tabbar-filler-right") {
529543
return _container.getComponentIndex(child);
530544
}
531545
return -1;
532546
}
533547

534548
public override function setComponentIndex(child:Component, index:Int):Component {
535-
if (child != _container && child != _scrollLeft && child != _scrollRight && child != _filler) {
549+
if (child != _container && child != _scrollLeft && child != _scrollRight && child != _filler && child.id != "tabbar-filler-left" && child.id != "tabbar-filler-right") {
536550
return _container.setComponentIndex(child, index);
537551
}
538552
return null;
@@ -559,6 +573,8 @@ private class Builder extends CompositeBuilder {
559573
_containerPosition = null;
560574
}
561575

576+
checkLeftRightFillers();
577+
562578
return true;
563579
}
564580

@@ -607,6 +623,40 @@ private class Builder extends CompositeBuilder {
607623
}
608624
_containerPosition = x;
609625
_container.left = x;
626+
checkLeftRightFillers();
627+
}
628+
629+
private function checkLeftRightFillers() {
630+
var leftFiller = _tabbar.findComponent("tabbar-filler-left", false);
631+
if (_containerPosition < 0) {
632+
if (leftFiller == null) {
633+
leftFiller = new Box();
634+
leftFiller.id = "tabbar-filler-left";
635+
leftFiller.addClass("tabbar-filler-left");
636+
leftFiller.scriptAccess = false;
637+
leftFiller.includeInLayout = false;
638+
_tabbar.addComponent(leftFiller);
639+
}
640+
leftFiller.show();
641+
} else if (leftFiller != null) {
642+
leftFiller.hide();
643+
}
644+
645+
var rightFiller = _tabbar.findComponent("tabbar-filler-right", false);
646+
var max = -(_container.width - _tabbar.width);
647+
if (_containerPosition > max) {
648+
if (rightFiller == null) {
649+
rightFiller = new Box();
650+
rightFiller.id = "tabbar-filler-right";
651+
rightFiller.addClass("tabbar-filler-right");
652+
rightFiller.scriptAccess = false;
653+
rightFiller.includeInLayout = false;
654+
_tabbar.addComponent(rightFiller);
655+
}
656+
rightFiller.show();
657+
} else if (rightFiller != null) {
658+
rightFiller.hide();
659+
}
610660
}
611661

612662
private function scrollRight() {
@@ -632,6 +682,7 @@ private class Builder extends CompositeBuilder {
632682
}
633683
_containerPosition = x;
634684
_container.left = x;
685+
checkLeftRightFillers();
635686
}
636687

637688
private function hideScrollButtons() {

0 commit comments

Comments
 (0)