1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
|
/**
* @file lllayoutstack.cpp
* @brief LLLayout class - dynamic stacking of UI elements
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
// Opaque view with a background and a border. Can contain LLUICtrls.
#include "linden_common.h"
#include "lllayoutstack.h"
#include "lllocalcliprect.h"
#include "llpanel.h"
#include "llcriticaldamp.h"
#include "lliconctrl.h"
#include "boost/foreach.hpp"
static const F32 MIN_FRACTIONAL_SIZE = 0.00001f;
static const F32 MAX_FRACTIONAL_SIZE = 1.f;
static LLDefaultChildRegistry::Register<LLLayoutStack> register_layout_stack("layout_stack");
static LLLayoutStack::LayoutStackRegistry::Register<LLLayoutPanel> register_layout_panel("layout_panel");
//
// LLLayoutPanel
//
LLLayoutPanel::Params::Params()
: expanded_min_dim("expanded_min_dim", 0),
min_dim("min_dim", -1),
user_resize("user_resize", false),
auto_resize("auto_resize", true)
{
addSynonym(min_dim, "min_width");
addSynonym(min_dim, "min_height");
}
LLLayoutPanel::LLLayoutPanel(const Params& p)
: LLPanel(p),
mExpandedMinDim(p.expanded_min_dim.isProvided() ? p.expanded_min_dim : p.min_dim),
mMinDim(p.min_dim),
mAutoResize(p.auto_resize),
mUserResize(p.user_resize),
mCollapsed(false),
mCollapseAmt(0.f),
mVisibleAmt(1.f), // default to fully visible
mResizeBar(NULL),
mFractionalSize(0.f),
mTargetDim(0),
mIgnoreReshape(false),
mOrientation(LLLayoutStack::HORIZONTAL)
{
// panels initialized as hidden should not start out partially visible
if (!getVisible())
{
mVisibleAmt = 0.f;
}
}
void LLLayoutPanel::initFromParams(const Params& p)
{
LLPanel::initFromParams(p);
setFollowsNone();
}
LLLayoutPanel::~LLLayoutPanel()
{
// probably not necessary, but...
delete mResizeBar;
mResizeBar = NULL;
gFocusMgr.removeKeyboardFocusWithoutCallback(this);
}
F32 LLLayoutPanel::getAutoResizeFactor() const
{
return mVisibleAmt * (1.f - mCollapseAmt);
}
F32 LLLayoutPanel::getVisibleAmount() const
{
return mVisibleAmt;
}
S32 LLLayoutPanel::getLayoutDim() const
{
return ll_round((F32)((mOrientation == LLLayoutStack::HORIZONTAL)
? getRect().getWidth()
: getRect().getHeight()));
}
S32 LLLayoutPanel::getTargetDim() const
{
return mTargetDim;
}
void LLLayoutPanel::setTargetDim(S32 value)
{
LLRect new_rect(getRect());
if (mOrientation == LLLayoutStack::HORIZONTAL)
{
new_rect.mRight = new_rect.mLeft + value;
}
else
{
new_rect.mTop = new_rect.mBottom + value;
}
setShape(new_rect, true);
}
S32 LLLayoutPanel::getVisibleDim() const
{
F32 min_dim = getRelevantMinDim();
return ll_round(mVisibleAmt
* (min_dim
+ (((F32)mTargetDim - min_dim) * (1.f - mCollapseAmt))));
}
void LLLayoutPanel::setOrientation( LLView::EOrientation orientation )
{
mOrientation = orientation;
S32 layout_dim = ll_round((F32)((mOrientation == LLLayoutStack::HORIZONTAL)
? getRect().getWidth()
: getRect().getHeight()));
if (mAutoResize == false
&& mUserResize == true
&& mMinDim == -1 )
{
setMinDim(layout_dim);
}
mTargetDim = llmax(layout_dim, getMinDim());
}
void LLLayoutPanel::setVisible( bool visible )
{
if (visible != getVisible())
{
LLLayoutStack* stackp = dynamic_cast<LLLayoutStack*>(getParent());
if (stackp)
{
stackp->mNeedsLayout = true;
}
}
LLPanel::setVisible(visible);
}
void LLLayoutPanel::reshape( S32 width, S32 height, bool called_from_parent /*= true*/ )
{
if (width == getRect().getWidth() && height == getRect().getHeight() && !LLView::sForceReshape) return;
if (!mIgnoreReshape && mAutoResize == false)
{
mTargetDim = (mOrientation == LLLayoutStack::HORIZONTAL) ? width : height;
LLLayoutStack* stackp = dynamic_cast<LLLayoutStack*>(getParent());
if (stackp)
{
stackp->mNeedsLayout = true;
}
}
LLPanel::reshape(width, height, called_from_parent);
}
void LLLayoutPanel::handleReshape(const LLRect& new_rect, bool by_user)
{
LLLayoutStack* stackp = dynamic_cast<LLLayoutStack*>(getParent());
if (stackp)
{
if (by_user)
{ // tell layout stack to account for new shape
// make sure that panels have already been auto resized
stackp->updateLayout();
// now apply requested size to panel
stackp->updatePanelRect(this, new_rect);
}
stackp->mNeedsLayout = true;
}
LLPanel::handleReshape(new_rect, by_user);
}
//
// LLLayoutStack
//
LLLayoutStack::Params::Params()
: orientation("orientation"),
animate("animate", true),
clip("clip", true),
open_time_constant("open_time_constant", 0.02f),
close_time_constant("close_time_constant", 0.03f),
resize_bar_overlap("resize_bar_overlap", 1),
border_size("border_size", LLCachedControl<S32>(*LLUI::getInstance()->mSettingGroups["config"], "UIResizeBarHeight", 0)),
show_drag_handle("show_drag_handle", false),
drag_handle_first_indent("drag_handle_first_indent", 0),
drag_handle_second_indent("drag_handle_second_indent", 0),
drag_handle_thickness("drag_handle_thickness", 5),
drag_handle_shift("drag_handle_shift", 2),
drag_handle_color("drag_handle_color", LLUIColorTable::instance().getColor("ResizebarBody"))
{
addSynonym(border_size, "drag_handle_gap");
}
LLLayoutStack::LLLayoutStack(const LLLayoutStack::Params& p)
: LLView(p),
mPanelSpacing(p.border_size),
mOrientation(p.orientation),
mAnimate(p.animate),
mAnimatedThisFrame(false),
mNeedsLayout(true),
mClip(p.clip),
mOpenTimeConstant(p.open_time_constant),
mCloseTimeConstant(p.close_time_constant),
mResizeBarOverlap(p.resize_bar_overlap),
mShowDragHandle(p.show_drag_handle),
mDragHandleFirstIndent(p.drag_handle_first_indent),
mDragHandleSecondIndent(p.drag_handle_second_indent),
mDragHandleThickness(p.drag_handle_thickness),
mDragHandleShift(p.drag_handle_shift),
mDragHandleColor(p.drag_handle_color())
{
}
LLLayoutStack::~LLLayoutStack()
{
e_panel_list_t panels = mPanels; // copy list of panel pointers
mPanels.clear(); // clear so that removeChild() calls don't cause trouble
std::for_each(panels.begin(), panels.end(), DeletePointer());
}
void LLLayoutStack::draw()
{
updateLayout();
// always clip to stack itself
LLLocalClipRect clip(getLocalRect());
for (LLLayoutPanel* panelp : mPanels)
{
if ((!panelp->getVisible() || panelp->mCollapsed)
&& (panelp->mVisibleAmt < 0.001f || !mAnimate))
{
// essentially invisible
continue;
}
// clip to layout rectangle, not bounding rectangle
LLRect clip_rect = panelp->getRect();
// scale clipping rectangle by visible amount
if (mOrientation == HORIZONTAL)
{
clip_rect.mRight = clip_rect.mLeft + panelp->getVisibleDim();
}
else
{
clip_rect.mBottom = clip_rect.mTop - panelp->getVisibleDim();
}
{LLLocalClipRect clip(clip_rect, mClip);
// only force drawing invisible children if visible amount is non-zero
drawChild(panelp, 0, 0, !clip_rect.isEmpty());
}
if (panelp->getResizeBar()->getVisible())
{
drawChild(panelp->getResizeBar());
}
}
}
void LLLayoutStack::deleteAllChildren()
{
mPanels.clear();
LLView::deleteAllChildren();
// Not really needed since nothing is left to
// display, but for the sake of consistency
updateFractionalSizes();
mNeedsLayout = true;
}
void LLLayoutStack::removeChild(LLView* view)
{
LLLayoutPanel* embedded_panelp = findEmbeddedPanel(dynamic_cast<LLPanel*>(view));
if (embedded_panelp)
{
mPanels.erase(std::find(mPanels.begin(), mPanels.end(), embedded_panelp));
LLView::removeChild(view);
updateFractionalSizes();
mNeedsLayout = true;
}
else
{
LLView::removeChild(view);
}
}
bool LLLayoutStack::postBuild()
{
updateLayout();
return true;
}
bool LLLayoutStack::addChild(LLView* child, S32 tab_group)
{
LLLayoutPanel* panelp = dynamic_cast<LLLayoutPanel*>(child);
if (panelp)
{
panelp->setOrientation(mOrientation);
mPanels.push_back(panelp);
createResizeBar(panelp);
mNeedsLayout = true;
}
bool result = LLView::addChild(child, tab_group);
updateFractionalSizes();
return result;
}
void LLLayoutStack::addPanel(LLLayoutPanel* panel, EAnimate animate)
{
addChild(panel);
// panel starts off invisible (collapsed)
if (animate == ANIMATE)
{
panel->mVisibleAmt = 0.f;
panel->setVisible(true);
}
}
void LLLayoutStack::collapsePanel(LLPanel* panel, bool collapsed)
{
LLLayoutPanel* panel_container = findEmbeddedPanel(panel);
if (!panel_container) return;
panel_container->mCollapsed = collapsed;
mNeedsLayout = true;
}
class LLImagePanel : public LLPanel
{
public:
struct Params : public LLInitParam::Block<Params, LLPanel::Params>
{
Optional<bool> horizontal;
Params() : horizontal("horizontal", false) {}
};
LLImagePanel(const Params& p) : LLPanel(p), mHorizontal(p.horizontal) {}
virtual ~LLImagePanel() {}
void draw()
{
const LLRect& parent_rect = getParent()->getRect();
const LLRect& rect = getRect();
LLRect clip_rect( -rect.mLeft, parent_rect.getHeight() - rect.mBottom - 2
, parent_rect.getWidth() - rect.mLeft - (mHorizontal ? 2 : 0), -rect.mBottom);
LLLocalClipRect clip(clip_rect);
LLPanel::draw();
}
private:
bool mHorizontal;
};
void LLLayoutStack::updateLayout()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_UI;
if (!mNeedsLayout) return;
bool continue_animating = animatePanels();
F32 total_visible_fraction = 0.f;
S32 space_to_distribute = (mOrientation == HORIZONTAL)
? getRect().getWidth()
: getRect().getHeight();
// first, assign minimum dimensions
for (LLLayoutPanel* panelp : mPanels)
{
if (panelp->mAutoResize)
{
panelp->mTargetDim = panelp->getRelevantMinDim();
}
space_to_distribute -= panelp->getVisibleDim() + ll_round((F32)mPanelSpacing * panelp->getVisibleAmount());
total_visible_fraction += panelp->mFractionalSize * panelp->getAutoResizeFactor();
}
llassert(total_visible_fraction < 1.05f);
// don't need spacing after last panel
if (!mPanels.empty())
{
space_to_distribute += ll_round(F32(mPanelSpacing) * mPanels.back()->getVisibleAmount());
}
S32 remaining_space = space_to_distribute;
if (space_to_distribute > 0 && total_visible_fraction > 0.f)
{ // give space proportionally to visible auto resize panels
for (LLLayoutPanel* panelp : mPanels)
{
if (panelp->mAutoResize)
{
F32 fraction_to_distribute = (panelp->mFractionalSize * panelp->getAutoResizeFactor()) / (total_visible_fraction);
S32 delta = ll_round((F32)space_to_distribute * fraction_to_distribute);
panelp->mTargetDim += delta;
remaining_space -= delta;
}
}
}
// distribute any left over pixels to non-collapsed, visible panels
for (LLLayoutPanel* panelp : mPanels)
{
if (remaining_space == 0) break;
if (panelp->mAutoResize
&& !panelp->mCollapsed
&& panelp->getVisible())
{
S32 space_for_panel = remaining_space > 0 ? 1 : -1;
panelp->mTargetDim += space_for_panel;
remaining_space -= space_for_panel;
}
}
F32 cur_pos = (mOrientation == HORIZONTAL) ? 0.f : (F32)getRect().getHeight();
for (LLLayoutPanel* panelp : mPanels)
{
F32 panel_dim = llmax(panelp->getExpandedMinDim(), panelp->mTargetDim);
LLRect panel_rect;
if (mOrientation == HORIZONTAL)
{
panel_rect.setLeftTopAndSize(ll_round(cur_pos),
getRect().getHeight(),
ll_round(panel_dim),
getRect().getHeight());
}
else
{
panel_rect.setLeftTopAndSize(0,
ll_round(cur_pos),
getRect().getWidth(),
ll_round(panel_dim));
}
LLRect resize_bar_rect(panel_rect);
F32 panel_spacing = (F32)mPanelSpacing * panelp->getVisibleAmount();
F32 panel_visible_dim = panelp->getVisibleDim();
S32 panel_spacing_round = (S32)(ll_round(panel_spacing));
if (mOrientation == HORIZONTAL)
{
cur_pos += panel_visible_dim + panel_spacing;
if (mShowDragHandle && panel_spacing_round > mDragHandleThickness)
{
resize_bar_rect.mLeft = panel_rect.mRight + mDragHandleShift;
resize_bar_rect.mRight = resize_bar_rect.mLeft + mDragHandleThickness;
}
else
{
resize_bar_rect.mLeft = panel_rect.mRight - mResizeBarOverlap;
resize_bar_rect.mRight = panel_rect.mRight + panel_spacing_round + mResizeBarOverlap;
}
if (mShowDragHandle)
{
resize_bar_rect.mBottom += mDragHandleSecondIndent;
resize_bar_rect.mTop -= mDragHandleFirstIndent;
}
}
else //VERTICAL
{
cur_pos -= panel_visible_dim + panel_spacing;
if (mShowDragHandle && panel_spacing_round > mDragHandleThickness)
{
resize_bar_rect.mTop = panel_rect.mBottom - mDragHandleShift;
resize_bar_rect.mBottom = resize_bar_rect.mTop - mDragHandleThickness;
}
else
{
resize_bar_rect.mTop = panel_rect.mBottom + mResizeBarOverlap;
resize_bar_rect.mBottom = panel_rect.mBottom - panel_spacing_round - mResizeBarOverlap;
}
if (mShowDragHandle)
{
resize_bar_rect.mLeft += mDragHandleFirstIndent;
resize_bar_rect.mRight -= mDragHandleSecondIndent;
}
}
panelp->setIgnoreReshape(true);
panelp->setShape(panel_rect);
panelp->setIgnoreReshape(false);
panelp->mResizeBar->setShape(resize_bar_rect);
}
updateResizeBarLimits();
// clear animation flag at end, since panel resizes will set it
// and leave it set if there is any animation in progress
mNeedsLayout = continue_animating;
} // end LLLayoutStack::updateLayout
void LLLayoutStack::setPanelSpacing(S32 val)
{
if (mPanelSpacing != val)
{
mPanelSpacing = val;
mNeedsLayout = true;
}
}
LLLayoutPanel* LLLayoutStack::findEmbeddedPanel(LLPanel* panelp) const
{
if (!panelp) return NULL;
for (LLLayoutPanel* p : mPanels)
{
if (p == panelp)
{
return p;
}
}
return NULL;
}
LLLayoutPanel* LLLayoutStack::findEmbeddedPanelByName(const std::string& name) const
{
LLLayoutPanel* result = NULL;
for (LLLayoutPanel* p : mPanels)
{
if (p->getName() == name)
{
result = p;
break;
}
}
return result;
}
void LLLayoutStack::createResizeBar(LLLayoutPanel* panelp)
{
for (LLLayoutPanel* lp : mPanels)
{
if (lp->mResizeBar == NULL)
{
LLResizeBar::Params resize_params;
resize_params.name("resize");
resize_params.resizing_view(lp);
resize_params.min_size(lp->getRelevantMinDim());
resize_params.side((mOrientation == HORIZONTAL) ? LLResizeBar::RIGHT : LLResizeBar::BOTTOM);
resize_params.snapping_enabled(false);
LLResizeBar* resize_bar = LLUICtrlFactory::create<LLResizeBar>(resize_params);
lp->mResizeBar = resize_bar;
if (mShowDragHandle)
{
LLPanel::Params resize_bar_bg_panel_p;
resize_bar_bg_panel_p.name = "resize_handle_bg_panel";
resize_bar_bg_panel_p.rect = lp->mResizeBar->getLocalRect();
resize_bar_bg_panel_p.follows.flags = FOLLOWS_ALL;
resize_bar_bg_panel_p.tab_stop = false;
resize_bar_bg_panel_p.background_visible = true;
resize_bar_bg_panel_p.bg_alpha_color = mDragHandleColor;
resize_bar_bg_panel_p.has_border = true;
resize_bar_bg_panel_p.border.border_thickness = 1;
resize_bar_bg_panel_p.border.highlight_light_color = LLUIColorTable::instance().getColor("ResizebarBorderLight");
resize_bar_bg_panel_p.border.shadow_dark_color = LLUIColorTable::instance().getColor("ResizebarBorderDark");
LLPanel* resize_bar_bg_panel = LLUICtrlFactory::create<LLPanel>(resize_bar_bg_panel_p);
LLIconCtrl::Params icon_p;
icon_p.name = "resize_handle_image";
icon_p.rect = lp->mResizeBar->getLocalRect();
icon_p.follows.flags = FOLLOWS_ALL;
icon_p.image = LLUI::getUIImage(mOrientation == HORIZONTAL ? "Vertical Drag Handle" : "Horizontal Drag Handle");
resize_bar_bg_panel->addChild(LLUICtrlFactory::create<LLIconCtrl>(icon_p));
lp->mResizeBar->addChild(resize_bar_bg_panel);
}
/*if (mShowDragHandle)
{
LLViewBorder::Params border_params;
border_params.border_thickness = 1;
border_params.highlight_light_color = LLUIColorTable::instance().getColor("ResizebarBorderLight");
border_params.shadow_dark_color = LLUIColorTable::instance().getColor("ResizebarBorderDark");
addBorder(border_params);
setBorderVisible(true);
LLImagePanel::Params image_panel;
mDragHandleImage = LLUI::getUIImage(LLResizeBar::RIGHT == mSide ? "Vertical Drag Handle" : "Horizontal Drag Handle");
image_panel.bg_alpha_image = mDragHandleImage;
image_panel.background_visible = true;
image_panel.horizontal = (LLResizeBar::BOTTOM == mSide);
mImagePanel = LLUICtrlFactory::create<LLImagePanel>(image_panel);
setImagePanel(mImagePanel);
}*/
//if (mShowDragHandle)
//{
// setBackgroundVisible(true);
// setTransparentColor(LLUIColorTable::instance().getColor("ResizebarBody"));
//}
/*if (mShowDragHandle)
{
S32 image_width = mDragHandleImage->getTextureWidth();
S32 image_height = mDragHandleImage->getTextureHeight();
const LLRect& panel_rect = getRect();
S32 image_left = (panel_rect.getWidth() - image_width) / 2 - 1;
S32 image_bottom = (panel_rect.getHeight() - image_height) / 2;
mImagePanel->setRect(LLRect(image_left, image_bottom + image_height, image_left + image_width, image_bottom));
}*/
LLView::addChild(resize_bar, 0);
}
}
// bring all resize bars to the front so that they are clickable even over the panels
// with a bit of overlap
for (e_panel_list_t::iterator panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
{
LLResizeBar* resize_barp = (*panel_it)->mResizeBar;
sendChildToFront(resize_barp);
}
}
// update layout stack animations, etc. once per frame
// NOTE: we use this to size world view based on animating UI, *before* we draw the UI
// we might still need to call updateLayout during UI draw phase, in case UI elements
// are resizing themselves dynamically
//static
void LLLayoutStack::updateClass()
{
for (auto& layout : instance_snapshot())
{
layout.updateLayout();
layout.mAnimatedThisFrame = false;
}
}
void LLLayoutStack::updateFractionalSizes()
{
F32 total_resizable_dim = 0.f;
for (LLLayoutPanel* panelp : mPanels)
{
if (panelp->mAutoResize)
{
total_resizable_dim += llmax(MIN_FRACTIONAL_SIZE, (F32)(panelp->getLayoutDim() - panelp->getRelevantMinDim()));
}
}
for (LLLayoutPanel* panelp : mPanels)
{
if (panelp->mAutoResize)
{
F32 panel_resizable_dim = llmax(MIN_FRACTIONAL_SIZE, (F32)(panelp->getLayoutDim() - panelp->getRelevantMinDim()));
panelp->mFractionalSize = panel_resizable_dim > 0.f
? llclamp(panel_resizable_dim / total_resizable_dim, MIN_FRACTIONAL_SIZE, MAX_FRACTIONAL_SIZE)
: MIN_FRACTIONAL_SIZE;
llassert(!llisnan(panelp->mFractionalSize));
}
}
normalizeFractionalSizes();
}
void LLLayoutStack::normalizeFractionalSizes()
{
S32 num_auto_resize_panels = 0;
F32 total_fractional_size = 0.f;
for (LLLayoutPanel* panelp : mPanels)
{
if (panelp->mAutoResize)
{
total_fractional_size += panelp->mFractionalSize;
num_auto_resize_panels++;
}
}
if (total_fractional_size == 0.f)
{ // equal distribution
for (LLLayoutPanel* panelp : mPanels)
{
if (panelp->mAutoResize)
{
panelp->mFractionalSize = MAX_FRACTIONAL_SIZE / (F32)num_auto_resize_panels;
}
}
}
else
{ // renormalize
for (LLLayoutPanel* panelp : mPanels)
{
if (panelp->mAutoResize)
{
panelp->mFractionalSize /= total_fractional_size;
}
}
}
}
bool LLLayoutStack::animatePanels()
{
bool continue_animating = false;
//
// animate visibility
//
for (LLLayoutPanel* panelp : mPanels)
{
if (panelp->getVisible())
{
if (mAnimate && panelp->mVisibleAmt < 1.f)
{
if (!mAnimatedThisFrame)
{
panelp->mVisibleAmt = lerp(panelp->mVisibleAmt, 1.f, LLSmoothInterpolation::getInterpolant(mOpenTimeConstant));
if (panelp->mVisibleAmt > 0.99f)
{
panelp->mVisibleAmt = 1.f;
}
}
mAnimatedThisFrame = true;
continue_animating = true;
}
else
{
if (panelp->mVisibleAmt != 1.f)
{
panelp->mVisibleAmt = 1.f;
mAnimatedThisFrame = true;
}
}
}
else // not visible
{
if (mAnimate && panelp->mVisibleAmt > 0.f)
{
if (!mAnimatedThisFrame)
{
panelp->mVisibleAmt = lerp(panelp->mVisibleAmt, 0.f, LLSmoothInterpolation::getInterpolant(mCloseTimeConstant));
if (panelp->mVisibleAmt < 0.001f)
{
panelp->mVisibleAmt = 0.f;
}
}
continue_animating = true;
mAnimatedThisFrame = true;
}
else
{
if (panelp->mVisibleAmt != 0.f)
{
panelp->mVisibleAmt = 0.f;
mAnimatedThisFrame = true;
}
}
}
F32 collapse_state = panelp->mCollapsed ? 1.f : 0.f;
if (panelp->mCollapseAmt != collapse_state)
{
if (mAnimate)
{
if (!mAnimatedThisFrame)
{
panelp->mCollapseAmt = lerp(panelp->mCollapseAmt, collapse_state, LLSmoothInterpolation::getInterpolant(mCloseTimeConstant));
}
if (llabs(panelp->mCollapseAmt - collapse_state) < 0.001f)
{
panelp->mCollapseAmt = collapse_state;
}
mAnimatedThisFrame = true;
continue_animating = true;
}
else
{
panelp->mCollapseAmt = collapse_state;
mAnimatedThisFrame = true;
}
}
}
if (mAnimatedThisFrame) mNeedsLayout = true;
return continue_animating;
}
void LLLayoutStack::updatePanelRect( LLLayoutPanel* resized_panel, const LLRect& new_rect )
{
S32 new_dim = (mOrientation == HORIZONTAL)
? new_rect.getWidth()
: new_rect.getHeight();
S32 delta_panel_dim = new_dim - resized_panel->getVisibleDim();
if (delta_panel_dim == 0) return;
F32 total_visible_fraction = 0.f;
F32 delta_auto_resize_headroom = 0.f;
F32 old_auto_resize_headroom = 0.f;
LLLayoutPanel* other_resize_panel = NULL;
LLLayoutPanel* following_panel = NULL;
BOOST_REVERSE_FOREACH(LLLayoutPanel* panelp, mPanels) // Should replace this when C++20 reverse view adaptor becomes available...
{
if (panelp->mAutoResize)
{
old_auto_resize_headroom += (F32)(panelp->mTargetDim - panelp->getRelevantMinDim());
if (panelp->getVisible() && !panelp->mCollapsed)
{
total_visible_fraction += panelp->mFractionalSize;
}
}
if (panelp == resized_panel)
{
other_resize_panel = following_panel;
}
if (panelp->getVisible() && !panelp->mCollapsed)
{
following_panel = panelp;
}
}
if (resized_panel->mAutoResize)
{
if (!other_resize_panel || !other_resize_panel->mAutoResize)
{
delta_auto_resize_headroom += delta_panel_dim;
}
}
else
{
if (!other_resize_panel || other_resize_panel->mAutoResize)
{
delta_auto_resize_headroom -= delta_panel_dim;
}
}
F32 fraction_given_up = 0.f;
F32 fraction_remaining = 1.f;
F32 new_auto_resize_headroom = old_auto_resize_headroom + delta_auto_resize_headroom;
enum
{
BEFORE_RESIZED_PANEL,
RESIZED_PANEL,
NEXT_PANEL,
AFTER_RESIZED_PANEL
} which_panel = BEFORE_RESIZED_PANEL;
for (LLLayoutPanel* panelp : mPanels)
{
if (!panelp->getVisible() || panelp->mCollapsed)
{
if (panelp->mAutoResize)
{
fraction_remaining -= panelp->mFractionalSize;
}
continue;
}
if (panelp == resized_panel)
{
which_panel = RESIZED_PANEL;
}
switch(which_panel)
{
case BEFORE_RESIZED_PANEL:
if (panelp->mAutoResize)
{ // freeze current size as fraction of overall auto_resize space
F32 fractional_adjustment_factor = new_auto_resize_headroom == 0.f
? 1.f
: old_auto_resize_headroom / new_auto_resize_headroom;
F32 new_fractional_size = llclamp(panelp->mFractionalSize * fractional_adjustment_factor,
MIN_FRACTIONAL_SIZE,
MAX_FRACTIONAL_SIZE);
fraction_given_up -= new_fractional_size - panelp->mFractionalSize;
fraction_remaining -= panelp->mFractionalSize;
panelp->mFractionalSize = new_fractional_size;
llassert(!llisnan(panelp->mFractionalSize));
}
else
{
// leave non auto-resize panels alone
}
break;
case RESIZED_PANEL:
if (panelp->mAutoResize)
{ // freeze new size as fraction
F32 new_fractional_size = (new_auto_resize_headroom == 0.f)
? MAX_FRACTIONAL_SIZE
: llclamp(total_visible_fraction * (F32)(new_dim - panelp->getRelevantMinDim()) / new_auto_resize_headroom, MIN_FRACTIONAL_SIZE, MAX_FRACTIONAL_SIZE);
fraction_given_up -= new_fractional_size - panelp->mFractionalSize;
fraction_remaining -= panelp->mFractionalSize;
panelp->mFractionalSize = new_fractional_size;
llassert(!llisnan(panelp->mFractionalSize));
}
else
{ // freeze new size as original size
panelp->mTargetDim = new_dim;
}
which_panel = NEXT_PANEL;
break;
case NEXT_PANEL:
if (panelp->mAutoResize)
{
fraction_remaining -= panelp->mFractionalSize;
if (resized_panel->mAutoResize)
{
panelp->mFractionalSize = llclamp(panelp->mFractionalSize + fraction_given_up, MIN_FRACTIONAL_SIZE, MAX_FRACTIONAL_SIZE);
fraction_given_up = 0.f;
}
else
{
if (new_auto_resize_headroom < 1.f)
{
new_auto_resize_headroom = 1.f;
}
F32 new_fractional_size = llclamp(total_visible_fraction * (F32)(panelp->mTargetDim - panelp->getRelevantMinDim() + delta_auto_resize_headroom)
/ new_auto_resize_headroom,
MIN_FRACTIONAL_SIZE,
MAX_FRACTIONAL_SIZE);
fraction_given_up -= new_fractional_size - panelp->mFractionalSize;
panelp->mFractionalSize = new_fractional_size;
}
}
else
{
panelp->mTargetDim -= delta_panel_dim;
}
which_panel = AFTER_RESIZED_PANEL;
break;
case AFTER_RESIZED_PANEL:
if (panelp->mAutoResize && fraction_given_up != 0.f)
{
panelp->mFractionalSize = llclamp(panelp->mFractionalSize + (panelp->mFractionalSize / fraction_remaining) * fraction_given_up,
MIN_FRACTIONAL_SIZE,
MAX_FRACTIONAL_SIZE);
}
break;
default:
break;
}
}
updateLayout();
//normalizeFractionalSizes();
}
void LLLayoutStack::reshape(S32 width, S32 height, bool called_from_parent)
{
mNeedsLayout = true;
LLView::reshape(width, height, called_from_parent);
}
void LLLayoutStack::updateResizeBarLimits()
{
LLLayoutPanel* previous_visible_panelp{ nullptr };
BOOST_REVERSE_FOREACH(LLLayoutPanel* visible_panelp, mPanels) // Should replace this when C++20 reverse view adaptor becomes available...
{
if (!visible_panelp->getVisible() || visible_panelp->mCollapsed)
{
visible_panelp->mResizeBar->setVisible(false);
continue;
}
// toggle resize bars based on panel visibility, resizability, etc
if (previous_visible_panelp
&& (visible_panelp->mUserResize || previous_visible_panelp->mUserResize) // one of the pair is user resizable
&& (visible_panelp->mAutoResize || visible_panelp->mUserResize) // current panel is resizable
&& (previous_visible_panelp->mAutoResize || previous_visible_panelp->mUserResize)) // previous panel is resizable
{
visible_panelp->mResizeBar->setVisible(true);
S32 previous_panel_headroom = previous_visible_panelp->getVisibleDim() - previous_visible_panelp->getRelevantMinDim();
visible_panelp->mResizeBar->setResizeLimits(visible_panelp->getRelevantMinDim(),
visible_panelp->getVisibleDim() + previous_panel_headroom);
}
else
{
visible_panelp->mResizeBar->setVisible(false);
}
previous_visible_panelp = visible_panelp;
}
}
|