From 4b3b9ad140ef86cecb34226a8eba198b98bae3cd Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 25 Oct 2025 13:28:26 +0300 Subject: [PATCH] Added simple tab selector to edit peer color box. --- Telegram/Resources/langs/lang.strings | 2 + .../boxes/peers/edit_peer_color_box.cpp | 119 +++++++++++++++++- 2 files changed, 120 insertions(+), 1 deletion(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index c217c95383..281ae4d846 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -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."; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp index f08ca78ec1..53f071259c 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp @@ -1876,6 +1876,113 @@ void EditPeerColorSection( }, button->lifetime()); } +not_null CreateTabsWidget( + not_null container, + const std::vector &tabs, + const std::vector> &callbacks) { + struct State { + int activeTab = 0; + Ui::Animations::Simple animation; + float64 animatedPosition = 0.; + }; + const auto tabsContainer = container->add( + object_ptr(container), + st::boxRowPadding, + style::al_top); + const auto state = tabsContainer->lifetime().make_state(); + const auto height = st::semiboldFont->height * 1.5; + + auto totalWidth = 0; + auto tabWidths = std::vector(); + 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( + 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 box, std::shared_ptr 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,