mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 23:27:09 +02:00
Fixed state losing in filter buttons on resize of statistics layer.
This commit is contained in:
parent
3b5a007db5
commit
4a10d86a29
3 changed files with 41 additions and 31 deletions
|
@ -178,32 +178,41 @@ ChartLinesFilterWidget::ChartLinesFilterWidget(
|
|||
: Ui::RpWidget(parent) {
|
||||
}
|
||||
|
||||
void ChartLinesFilterWidget::resizeToWidth(int outerWidth) {
|
||||
auto maxRight = 0;
|
||||
for (auto i = 0; i < _buttons.size(); i++) {
|
||||
const auto raw = _buttons[i].get();
|
||||
if (!i) {
|
||||
raw->move(0, 0);
|
||||
} else {
|
||||
const auto prevRaw = _buttons[i - 1].get();
|
||||
const auto prevLeft = rect::right(prevRaw);
|
||||
const auto isOut = (prevLeft + raw->width() > outerWidth);
|
||||
const auto left = isOut ? 0 : prevLeft;
|
||||
const auto top = isOut ? rect::bottom(prevRaw) : prevRaw->y();
|
||||
raw->move(left, top);
|
||||
}
|
||||
maxRight = std::max(maxRight, rect::right(raw));
|
||||
}
|
||||
if (!_buttons.empty()) {
|
||||
resize(maxRight, rect::bottom(_buttons.back().get()));
|
||||
}
|
||||
}
|
||||
|
||||
void ChartLinesFilterWidget::fillButtons(
|
||||
const std::vector<QString> &texts,
|
||||
const std::vector<QColor> &colors,
|
||||
const std::vector<int> &ids,
|
||||
int outerWidth) {
|
||||
const std::vector<int> &ids) {
|
||||
Expects(texts.size() == colors.size());
|
||||
_buttons.clear();
|
||||
|
||||
_buttons.reserve(texts.size());
|
||||
auto maxRight = 0;
|
||||
for (auto i = 0; i < texts.size(); i++) {
|
||||
auto button = base::make_unique_q<FlatCheckbox>(
|
||||
this,
|
||||
texts[i],
|
||||
colors[i]);
|
||||
button->show();
|
||||
if (!i) {
|
||||
button->move(0, 0);
|
||||
} else {
|
||||
const auto lastRaw = _buttons.back().get();
|
||||
const auto lastLeft = rect::right(lastRaw);
|
||||
const auto isOut = (lastLeft + button->width() > outerWidth);
|
||||
const auto left = isOut ? 0 : lastLeft;
|
||||
const auto top = isOut ? rect::bottom(lastRaw) : lastRaw->y();
|
||||
button->move(left, top);
|
||||
}
|
||||
const auto id = ids[i];
|
||||
button->setClickedCallback([=, raw = button.get()] {
|
||||
const auto checked = !raw->checked();
|
||||
|
@ -227,12 +236,9 @@ void ChartLinesFilterWidget::fillButtons(
|
|||
raw->setChecked(checked, true);
|
||||
_buttonEnabledChanges.fire({ .id = id, .enabled = checked });
|
||||
});
|
||||
maxRight = std::max(maxRight, rect::right(button.get()));
|
||||
|
||||
_buttons.push_back(std::move(button));
|
||||
}
|
||||
|
||||
resize(maxRight, rect::bottom(_buttons.back().get()));
|
||||
}
|
||||
|
||||
auto ChartLinesFilterWidget::buttonEnabledChanges() const
|
||||
|
|
|
@ -18,8 +18,9 @@ public:
|
|||
void fillButtons(
|
||||
const std::vector<QString> &texts,
|
||||
const std::vector<QColor> &colors,
|
||||
const std::vector<int> &ids,
|
||||
int outerWidth);
|
||||
const std::vector<int> &ids);
|
||||
|
||||
void resizeToWidth(int outerWidth);
|
||||
|
||||
struct Entry final {
|
||||
int id = 0;
|
||||
|
|
|
@ -843,19 +843,7 @@ ChartWidget::ChartWidget(not_null<Ui::RpWidget*> parent)
|
|||
|
||||
int ChartWidget::resizeGetHeight(int newWidth) {
|
||||
if (_filterButtons) {
|
||||
auto texts = std::vector<QString>();
|
||||
auto colors = std::vector<QColor>();
|
||||
auto ids = std::vector<int>();
|
||||
texts.reserve(_chartData.lines.size());
|
||||
colors.reserve(_chartData.lines.size());
|
||||
ids.reserve(_chartData.lines.size());
|
||||
for (const auto &line : _chartData.lines) {
|
||||
texts.push_back(line.name);
|
||||
colors.push_back(line.color);
|
||||
ids.push_back(line.id);
|
||||
}
|
||||
|
||||
_filterButtons->fillButtons(texts, colors, ids, newWidth);
|
||||
_filterButtons->resizeToWidth(newWidth);
|
||||
}
|
||||
const auto filtersTopSkip = st::statisticsFilterButtonsPadding.top();
|
||||
const auto filtersHeight = _filterButtons
|
||||
|
@ -1401,6 +1389,21 @@ void ChartWidget::setupFilterButtons() {
|
|||
}
|
||||
_filterButtons = base::make_unique_q<ChartLinesFilterWidget>(this);
|
||||
_filterButtons->show();
|
||||
{
|
||||
auto texts = std::vector<QString>();
|
||||
auto colors = std::vector<QColor>();
|
||||
auto ids = std::vector<int>();
|
||||
texts.reserve(_chartData.lines.size());
|
||||
colors.reserve(_chartData.lines.size());
|
||||
ids.reserve(_chartData.lines.size());
|
||||
for (const auto &line : _chartData.lines) {
|
||||
texts.push_back(line.name);
|
||||
colors.push_back(line.color);
|
||||
ids.push_back(line.id);
|
||||
}
|
||||
|
||||
_filterButtons->fillButtons(texts, colors, ids);
|
||||
}
|
||||
|
||||
_filterButtons->buttonEnabledChanges(
|
||||
) | rpl::start_with_next([=](const ChartLinesFilterWidget::Entry &e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue