| 3681 | } |
| 3682 | |
| 3683 | void PricesBox( |
| 3684 | not_null<Ui::GenericBox*> box, |
| 3685 | const std::vector<UpgradePrice> &list, |
| 3686 | rpl::producer<int> cost) { |
| 3687 | const auto top = box->setPinnedToTopContent( |
| 3688 | object_ptr<Ui::VerticalLayout>(box)); |
| 3689 | box->setWidth(st::boxWideWidth); |
| 3690 | box->setStyle(st::boostBox); |
| 3691 | |
| 3692 | struct State { |
| 3693 | rpl::variable<int> cost; |
| 3694 | }; |
| 3695 | const auto state = box->lifetime().make_state<State>(); |
| 3696 | state->cost = std::move(cost); |
| 3697 | const auto min = list.back().stars; |
| 3698 | const auto max = std::max(min + 2, list.front().stars); |
| 3699 | const auto from = 0; |
| 3700 | const auto till = max - min; |
| 3701 | |
| 3702 | const auto addSkip = [&](int skip) { |
| 3703 | top->add(object_ptr<Ui::FixedHeightWidget>(top, skip)); |
| 3704 | }; |
| 3705 | |
| 3706 | const auto ratio = [=](int current) { |
| 3707 | current = std::clamp(current, from, till); |
| 3708 | const auto count = (till - from); |
| 3709 | const auto index = (current - from); |
| 3710 | if (count <= 2) { |
| 3711 | return 0.5; |
| 3712 | } |
| 3713 | const auto available = st::boxWideWidth |
| 3714 | - st::boxPadding.left() |
| 3715 | - st::boxPadding.right(); |
| 3716 | const auto average = available / float64(count); |
| 3717 | const auto levelWidth = [&](int stars) { |
| 3718 | return st::normalFont->width(Lang::FormatCountDecimal(stars)); |
| 3719 | }; |
| 3720 | const auto paddings = 2 * st::premiumLineTextSkip; |
| 3721 | const auto labelLeftWidth = paddings + levelWidth(min); |
| 3722 | const auto labelRightWidth = paddings + levelWidth(max); |
| 3723 | const auto first = std::max(average, labelLeftWidth * 1.); |
| 3724 | const auto last = std::max(average, labelRightWidth * 1.); |
| 3725 | const auto other = (available - first - last) / (count - 2); |
| 3726 | return (first + (index - 1) * other) / available; |
| 3727 | }; |
| 3728 | |
| 3729 | auto bubbleRowState = state->cost.value( |
| 3730 | ) | rpl::map([=](int value) { |
| 3731 | return Premium::BubbleRowState{ |
| 3732 | .counter = max - value, |
| 3733 | .ratio = ratio(max - value), |
| 3734 | .dynamic = true, |
| 3735 | }; |
| 3736 | }); |
| 3737 | Premium::AddBubbleRow( |
| 3738 | top, |
| 3739 | st::starRatingBubble, |
| 3740 | box->showFinishes(), |
nothing calls this directly
no test coverage detected