mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 02:01:40 -05:00
Support variable width tabs slider.
This commit is contained in:
parent
0255d0c59e
commit
fc66550a32
2 changed files with 52 additions and 4 deletions
|
@ -103,6 +103,15 @@ void DiscreteSlider::enumerateSections(Lambda callback) {
|
|||
}
|
||||
}
|
||||
|
||||
template <typename Lambda>
|
||||
void DiscreteSlider::enumerateSections(Lambda callback) const {
|
||||
for (auto §ion : _sections) {
|
||||
if (!callback(section)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DiscreteSlider::mousePressEvent(QMouseEvent *e) {
|
||||
auto index = getIndexFromPosition(e->pos());
|
||||
if (_selectOnPress) {
|
||||
|
@ -183,20 +192,55 @@ void SettingsSlider::resizeSections(int newWidth) {
|
|||
auto count = getSectionsCount();
|
||||
if (!count) return;
|
||||
|
||||
auto sectionsWidth = newWidth - (count - 1) * _st.barSkip;
|
||||
auto sectionWidth = sectionsWidth / float64(count);
|
||||
auto sectionWidths = countSectionsWidths(newWidth);
|
||||
|
||||
auto skip = 0;
|
||||
auto x = 0.;
|
||||
enumerateSections([this, &x, &skip, sectionWidth](Section §ion) {
|
||||
auto sectionWidth = sectionWidths.begin();
|
||||
enumerateSections([&](Section §ion) {
|
||||
Expects(sectionWidth != sectionWidths.end());
|
||||
|
||||
section.left = qFloor(x) + skip;
|
||||
x += sectionWidth;
|
||||
x += *sectionWidth;
|
||||
section.width = qRound(x) - (section.left - skip);
|
||||
skip += _st.barSkip;
|
||||
++sectionWidth;
|
||||
return true;
|
||||
});
|
||||
stopAnimation();
|
||||
}
|
||||
|
||||
std::vector<float64> SettingsSlider::countSectionsWidths(
|
||||
int newWidth) const {
|
||||
auto count = getSectionsCount();
|
||||
auto sectionsWidth = newWidth - (count - 1) * _st.barSkip;
|
||||
auto sectionWidth = sectionsWidth / float64(count);
|
||||
|
||||
auto result = std::vector<float64>(count, sectionWidth);
|
||||
auto labelsWidth = 0;
|
||||
auto commonWidth = true;
|
||||
enumerateSections([&](const Section §ion) {
|
||||
labelsWidth += section.labelWidth;
|
||||
if (section.labelWidth >= sectionWidth) {
|
||||
commonWidth = false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
// If labelsWidth > sectionsWidth we're screwed anyway.
|
||||
if (!commonWidth && labelsWidth <= sectionsWidth) {
|
||||
auto padding = (sectionsWidth - labelsWidth) / (2. * count);
|
||||
auto currentWidth = result.begin();
|
||||
enumerateSections([&](const Section §ion) {
|
||||
Expects(currentWidth != result.end());
|
||||
|
||||
*currentWidth = padding + section.labelWidth + padding;
|
||||
++currentWidth;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int SettingsSlider::resizeGetHeight(int newWidth) {
|
||||
resizeSections(newWidth);
|
||||
return _st.height;
|
||||
|
|
|
@ -71,6 +71,9 @@ protected:
|
|||
template <typename Lambda>
|
||||
void enumerateSections(Lambda callback);
|
||||
|
||||
template <typename Lambda>
|
||||
void enumerateSections(Lambda callback) const;
|
||||
|
||||
virtual void startRipple(int sectionIndex) {
|
||||
}
|
||||
|
||||
|
@ -122,6 +125,7 @@ private:
|
|||
QImage prepareRippleMask(int sectionIndex, const Section §ion);
|
||||
|
||||
void resizeSections(int newWidth);
|
||||
std::vector<float64> countSectionsWidths(int newWidth) const;
|
||||
|
||||
const style::SettingsSlider &_st;
|
||||
int _rippleTopRoundRadius = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue