Allow dismissing notifications by touching/clicking them.

Fixes #18040

Might do something more elegant in the future.
This commit is contained in:
Henrik Rydgård 2023-09-04 10:01:07 +02:00
parent 980b2158ba
commit cd78097e74
5 changed files with 37 additions and 0 deletions

View file

@ -39,6 +39,13 @@ float OnScreenDisplay::SidebarAlpha() const {
return saturatef(1.0f - ((float)timeSinceNudge - 0.1f) * 4.0f);
}
void OnScreenDisplay::DismissEntry(size_t index, double now) {
std::lock_guard<std::mutex> guard(mutex_);
if (index < entries_.size() && entries_[index].type != OSDType::ACHIEVEMENT_CHALLENGE_INDICATOR) {
entries_[index].endTime = std::min(now + FadeoutTime(), entries_[index].endTime);
}
}
void OnScreenDisplay::Show(OSDType type, const std::string &text, const std::string &text2, const std::string &icon, float duration_s, const char *id) {
// Automatic duration based on type.
if (duration_s <= 0.0f) {

View file

@ -87,6 +87,9 @@ public:
std::vector<Entry> Entries();
// TODO: Use something more stable than the index.
void DismissEntry(size_t index, double now);
static float FadeinTime() { return 0.1f; }
static float FadeoutTime() { return 0.25f; }

View file

@ -48,6 +48,9 @@ void ScreenManager::update() {
switchToNext();
}
if (overlayScreen_) {
overlayScreen_->update();
}
if (stack_.size()) {
stack_.back().screen->update();
}
@ -90,6 +93,10 @@ void ScreenManager::touch(const TouchInput &touch) {
layer.screen->UnsyncTouch(screen->transformTouch(touch));
}
} else if (!stack_.empty()) {
// Let the overlay know about touch-downs, to be able to dismiss popups.
if (overlayScreen_ && (touch.flags & TOUCH_DOWN)) {
overlayScreen_->UnsyncTouch(overlayScreen_->transformTouch(touch));
}
Screen *screen = stack_.back().screen;
stack_.back().screen->UnsyncTouch(screen->transformTouch(touch));
}

View file

@ -448,9 +448,19 @@ void OnScreenMessagesView::Draw(UIContext &dc) {
}
}
// Quick hack for dismissing messages by touch.
for (auto &touch : touches_) {
if (b.Contains(touch.x, touch.y)) {
INFO_LOG(G3D, "Dismissing entry %d (%0.1f %0.1f vs %0.1f %0.1f %0.1f %0.f)", j, touch.x, touch.y, bounds_.x, bounds_.y, bounds_.w, bounds_.h);
g_OSD.DismissEntry(j, now);
}
}
y += (measuredEntry.h + 4.0f) * measuredEntry.alpha;
}
}
touches_.clear();
}
std::string OnScreenMessagesView::DescribeText() const {
@ -465,6 +475,13 @@ std::string OnScreenMessagesView::DescribeText() const {
return ss.str();
}
bool OnScreenMessagesView::Touch(const TouchInput &input) {
if (input.flags & TOUCH_DOWN) {
touches_.push_back(input);
}
return true;
}
void OSDOverlayScreen::CreateViews() {
root_ = new UI::AnchorLayout();
root_->SetTag("OSDOverlayScreen");

View file

@ -21,7 +21,10 @@ class OnScreenMessagesView : public UI::InertView {
public:
OnScreenMessagesView(UI::LayoutParams *layoutParams = nullptr) : UI::InertView(layoutParams) {}
void Draw(UIContext &dc) override;
bool Touch(const TouchInput &input) override;
std::string DescribeText() const override;
private:
std::vector<TouchInput> touches_;
};
class OSDOverlayScreen : public UIScreen {