Added simple tab selector to edit peer color box.

This commit is contained in:
23rd
2025-10-25 13:28:26 +03:00
parent 1bb2efc346
commit 4b3b9ad140
2 changed files with 120 additions and 1 deletions
+2
View File
@@ -976,6 +976,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_settings_font_family" = "Font family";
"lng_settings_color_title" = "Color preview";
"lng_settings_color_tab_profile" = "Profile";
"lng_settings_color_tab_name" = "Name";
"lng_settings_color_reply" = "Reply to your message";
"lng_settings_color_reply_channel" = "Reply to your channel message";
"lng_settings_color_text" = "Your name and replies to your messages will be shown in the selected color.";
@@ -1876,6 +1876,113 @@ void EditPeerColorSection(
}, button->lifetime());
}
not_null<Ui::RpWidget*> CreateTabsWidget(
not_null<Ui::VerticalLayout*> container,
const std::vector<QString> &tabs,
const std::vector<Fn<void()>> &callbacks) {
struct State {
int activeTab = 0;
Ui::Animations::Simple animation;
float64 animatedPosition = 0.;
};
const auto tabsContainer = container->add(
object_ptr<Ui::RpWidget>(container),
st::boxRowPadding,
style::al_top);
const auto state = tabsContainer->lifetime().make_state<State>();
const auto height = st::semiboldFont->height * 1.5;
auto totalWidth = 0;
auto tabWidths = std::vector<int>();
tabWidths.reserve(tabs.size());
for (const auto &text : tabs) {
const auto width = st::semiboldFont->width(text) + height * 2;
tabWidths.push_back(width);
totalWidth += width;
}
tabsContainer->resize(totalWidth, height);
tabsContainer->setMaximumWidth(tabsContainer->width());
auto left = 0;
for (auto i = 0; i < tabs.size(); ++i) {
const auto tabButton = Ui::CreateChild<Ui::AbstractButton>(
tabsContainer);
tabButton->setGeometry(left, 0, tabWidths[i], height);
tabButton->setClickedCallback([=] {
if (state->activeTab != i) {
auto targetPosition = 0.;
for (auto j = 0; j < i; ++j) {
targetPosition += tabWidths[j];
}
state->animation.stop();
state->animation.start(
[=](float64 v) {
state->animatedPosition = v;
tabsContainer->update();
},
state->animatedPosition,
targetPosition,
400,
anim::easeOutQuint);
state->activeTab = i;
}
if (i < callbacks.size() && callbacks[i]) {
callbacks[i]();
}
});
left += tabWidths[i];
}
const auto penWidth = st::lineWidth * 2;
tabsContainer->paintRequest() | rpl::start_with_next([=] {
auto p = QPainter(tabsContainer);
auto hq = PainterHighQualityEnabler(p);
const auto r = tabsContainer->rect();
auto pen = QPen(st::giftBoxTabBgActive);
pen.setWidthF(penWidth);
p.setPen(pen);
const auto halfPen = penWidth / 2;
p.drawRoundedRect(
QRectF(
halfPen,
halfPen,
r.width() - penWidth,
r.height() - penWidth),
height / 2,
height / 2);
p.setFont(st::semiboldFont);
const auto animatedLeft = state->animatedPosition;
const auto activeWidth = tabWidths[state->activeTab];
p.setBrush(st::giftBoxTabBgActive);
p.setPen(Qt::NoPen);
p.drawRoundedRect(
QRect(animatedLeft, 0, activeWidth, height),
height / 2,
height / 2);
auto left = 0;
for (auto i = 0; i < tabs.size(); ++i) {
auto textPen = QPen(state->activeTab == i
? st::giftBoxTabFgActive
: st::giftBoxTabFg);
textPen.setWidthF(penWidth);
p.setPen(textPen);
p.drawText(
QRect(left, 0, tabWidths[i], height),
tabs[i],
style::al_center);
left += tabWidths[i];
}
}, tabsContainer->lifetime());
state->animatedPosition = 0.;
return tabsContainer;
}
void EditPeerColorBox(
not_null<Ui::GenericBox*> box,
std::shared_ptr<ChatHelpers::Show> show,
@@ -1891,10 +1998,20 @@ void EditPeerColorBox(
box->closeBox();
});
const auto button = box->addButton(tr::lng_settings_color_apply(), [] {});
const auto content = box->verticalLayout();
CreateTabsWidget(
content,
{
tr::lng_settings_color_tab_profile(tr::now),
tr::lng_settings_color_tab_name(tr::now),
},
{ [] {}, [] {} });
Ui::AddSkip(content);
EditPeerColorSection(
box,
box->verticalLayout(),
content,
button,
show,
peer,