MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / FillBoostLimit

Function FillBoostLimit

Telegram/SourceFiles/ui/boxes/boost_box.cpp:841–940  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

839}
840
841void FillBoostLimit(
842 rpl::producer<> showFinished,
843 not_null<VerticalLayout*> container,
844 rpl::producer<BoostCounters> data,
845 style::margins limitLinePadding) {
846 const auto addSkip = [&](int skip) {
847 container->add(object_ptr<Ui::FixedHeightWidget>(container, skip));
848 };
849
850 const auto ratio = [=](BoostCounters counters) {
851 const auto min = counters.thisLevelBoosts;
852 const auto max = counters.nextLevelBoosts;
853
854 Assert(counters.boosts >= min && counters.boosts <= max);
855 const auto count = (max - min);
856 const auto index = (counters.boosts - min);
857 if (!index) {
858 return 0.;
859 } else if (index == count) {
860 return 1.;
861 } else if (count == 2) {
862 return 0.5;
863 }
864 const auto available = st::boxWideWidth
865 - st::boxPadding.left()
866 - st::boxPadding.right();
867 const auto average = available / float64(count);
868 const auto levelWidth = [&](int add) {
869 return st::normalFont->width(
870 tr::lng_boost_level(
871 tr::now,
872 lt_count,
873 counters.level + add));
874 };
875 const auto paddings = 2 * st::premiumLineTextSkip;
876 const auto labelLeftWidth = paddings + levelWidth(0);
877 const auto labelRightWidth = paddings + levelWidth(1);
878 const auto first = std::max(average, labelLeftWidth * 1.);
879 const auto last = std::max(average, labelRightWidth * 1.);
880 const auto other = (available - first - last) / (count - 2);
881 return (first + (index - 1) * other) / available;
882 };
883
884 auto adjustedData = rpl::duplicate(data) | rpl::map(AdjustByReached);
885
886 auto bubbleRowState = rpl::duplicate(
887 adjustedData
888 ) | rpl::combine_previous(
889 BoostCounters()
890 ) | rpl::map([=](BoostCounters previous, BoostCounters counters) {
891 return Premium::BubbleRowState{
892 .counter = counters.boosts,
893 .ratio = ratio(counters),
894 .animateFromZero = (counters.level != previous.level),
895 .dynamic = true,
896 };
897 });
898 Premium::AddBubbleRow(

Callers 3

BoostBoxFunction · 0.85
AskBoostBoxFunction · 0.85
fillMethod · 0.85

Calls 5

AddBubbleRowFunction · 0.85
AddLimitRowFunction · 0.85
BoostCountersClass · 0.70
addMethod · 0.45
widthMethod · 0.45

Tested by

no test coverage detected