Focus start button on launch.

This commit is contained in:
John Preston
2025-10-24 10:55:45 +04:00
parent b5f4e40c3e
commit 65891508e0
7 changed files with 55 additions and 18 deletions

View File

@@ -38,5 +38,18 @@ rpl::producer<QString> StartWidget::nextButtonText() const {
return tr::lng_start_msgs();
}
rpl::producer<> StartWidget::nextButtonFocusRequests() const {
return _nextButtonFocusRequests.events();
}
void StartWidget::activate() {
Step::activate();
setInnerFocus();
}
void StartWidget::setInnerFocus() {
_nextButtonFocusRequests.fire({});
}
} // namespace details
} // namespace Intro

View File

@@ -27,6 +27,12 @@ public:
void submit() override;
rpl::producer<QString> nextButtonText() const override;
rpl::producer<> nextButtonFocusRequests() const override;
void activate() override;
void setInnerFocus() override;
private:
rpl::event_stream<> _nextButtonFocusRequests;
};

View File

@@ -133,6 +133,10 @@ rpl::producer<const style::RoundButton*> Step::nextButtonStyle() const {
return rpl::single((const style::RoundButton*)(nullptr));
}
rpl::producer<> Step::nextButtonFocusRequests() const {
return rpl::never();
}
void Step::goBack() {
if (_goCallback) {
_goCallback(nullptr, StackAction::Back, Animate::Back);

View File

@@ -94,6 +94,7 @@ public:
[[nodiscard]] virtual rpl::producer<QString> nextButtonText() const;
[[nodiscard]] virtual auto nextButtonStyle() const
-> rpl::producer<const style::RoundButton*>;
[[nodiscard]] virtual rpl::producer<> nextButtonFocusRequests() const;
[[nodiscard]] int contentLeft() const;
[[nodiscard]] int contentTop() const;

View File

@@ -116,6 +116,7 @@ Widget::Widget(
default: Unexpected("Enter point in Intro::Widget::Widget.");
}
setupStep();
fixOrder();
if (_account->mtp().isTestMode()) {
@@ -342,6 +343,32 @@ void Widget::setInnerFocus() {
}
}
void Widget::setupStep() {
getStep()->nextButtonStyle(
) | rpl::start_with_next([=](const style::RoundButton *st) {
const auto nextStyle = st ? st : &st::introNextButton;
if (_nextStyle != nextStyle) {
_nextStyle = nextStyle;
const auto wasShown = _next->toggled();
_next.destroy();
_next.create(
this,
object_ptr<Ui::RoundButton>(this, nullptr, *nextStyle));
showControls();
updateControlsGeometry();
_next->toggle(wasShown, anim::type::instant);
}
}, getStep()->lifetime());
getStep()->nextButtonFocusRequests() | rpl::start_with_next([=] {
if (_next && !_next->isHidden()) {
_next->entity()->setFocus(Qt::OtherFocusReason);
}
}, getStep()->lifetime());
getStep()->finishInit();
}
void Widget::historyMove(StackAction action, Animate animate) {
Expects(_stepHistory.size() > 1);
@@ -363,25 +390,8 @@ void Widget::historyMove(StackAction action, Animate animate) {
if (_terms) {
hideAndDestroy(std::exchange(_terms, { nullptr }));
}
{
getStep()->nextButtonStyle(
) | rpl::start_with_next([=](const style::RoundButton *st) {
const auto nextStyle = st ? st : &st::introNextButton;
if (_nextStyle != nextStyle) {
_nextStyle = nextStyle;
const auto wasShown = _next->toggled();
_next.destroy();
_next.create(
this,
object_ptr<Ui::RoundButton>(this, nullptr, *nextStyle));
showControls();
updateControlsGeometry();
_next->toggle(wasShown, anim::type::instant);
}
}, _next->lifetime());
}
setupStep();
getStep()->finishInit();
getStep()->prepareShowAnimated(wasStep);
if (wasStep->hasCover() != getStep()->hasCover()) {
_nextTopFrom = wasStep->contentTop() + st::introNextTop;

View File

@@ -120,6 +120,7 @@ protected:
void keyPressEvent(QKeyEvent *e) override;
private:
void setupStep();
void refreshLang();
void showFinished();
void createLanguageLink();