Ui, main: the new-conversation screen and the long-press sheets

The + opens a screen with a number field (its placeholder "Number", a
parameter of the compose field now) and Start; the number becomes a
conversation key through Number's ConversationKey, as an sms: link's
does (E.164 through the country code, a short code as digits), anything
else is refused in place. A long press on a conversation row offers to
delete the conversation, on a message to copy its text to the clipboard
or delete it; only those two have one: App tells the recogniser before
each press whether what it lands on has a long press (GestureDetector's
longPress), and without one a press held as long — on a button, a field,
a sheet's row — stays a tap at its release, so a slow finger presses the
button all the same. A sheet draws on the overlay layer over a scrim and
pushes its regions last, so they win the hit test, and the wheel scrolls
nothing under it; Escape, the back arrow and a tap outside dismiss it.
Deleting a conversation also closes its notification and drops its
draft; the + keeps the draft of the conversation it leaves, as Back
does, and so does a view that closes because its last message was
deleted. The deletes go through Sync (Erase, EraseConversation: the
commit before, which keeps a deleted text deleted). The number field's
box is drawn by its screen, as the send bar's is by the bar: the shared
field drawing paints no background of its own. Opening a conversation,
from a notification or a link, leaves the new-conversation screen and
any sheet, and the + leaves any sheet. A key whose press changed the
screen acts once: held, its repeats are not the new screen's — Enter,
which started the conversation, would type line breaks into its field,
and Escape would go on back, from a sheet through the conversation and
its draft. A sheet that asks to delete a conversation goes when a text
arrives for it: a yes would delete that text unread. A press on the
conversation's row opens no such sheet either while the row it aimed at
had not shown the text — the regions are a frame's: the press that is
down when the text arrives, and one that comes down before the next
frame is drawn, have no long press; a release before the long-press time
is still the row's tap, while the row stays under the finger.

--new and --bench-sheet put either on screen for the bench
(--bench-sheet conversation or message, each on the screen a long press
opens it over: another value is refused, and one that finds nothing to
press says so in the log), and are window flags as --screenshot is.

Tested: the screens and the sheets by the bench (--new, --bench-sheet)
and the phone step's screenshots; the deletes' logic with the commit
before, in tests/Store and tests/Sync; the press without a long press in
tests/Gesture (the timer gives no long press and a move within the slop
nothing; the release is the tap, however late; a slide off the control
is a drag); a deleted conversation's draft dropped, in tests/Edit. The
press on a row a text arrived for has no bench: none holds a finger on a
row.
This commit is contained in:
Jorijn van der Graaf 2026-11-01 18:11:40 +01:00
commit 20e687452f
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
10 changed files with 358 additions and 38 deletions

View file

@ -2,10 +2,10 @@
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
/*
ImsdMessages.Ui:Screens — the two screens of the baseline, drawn into the
canvas's layers: the conversation list and one conversation. A screen
lays out and draws in the same pass, records the regions a tap can hit,
and keeps its scroll state; the app decides what a hit means.
ImsdMessages.Ui:Screens — the screens, drawn into the canvas's layers: the
conversation list, one conversation, the new-conversation screen and the
long-press sheets. A screen lays out and draws in the same pass and
records the regions a tap can hit; the app decides what a hit means.
*/
module;
#include "vulkan/vulkan.h"
@ -26,6 +26,13 @@ export namespace ImsdMessages::Ui {
constexpr std::uint32_t back = 2;
constexpr std::uint32_t compose = 4;
constexpr std::uint32_t send = 5;
constexpr std::uint32_t start = 6;
constexpr std::uint32_t newField = 7;
constexpr std::uint32_t sheetScrim = 10;
constexpr std::uint32_t sheetCancel = 11;
constexpr std::uint32_t sheetDelete = 12;
constexpr std::uint32_t sheetCopy = 13;
constexpr std::uint32_t sheetPanel = 14; // the panel beside and between its buttons: inert
constexpr std::uint32_t rowBase = 1000;
constexpr std::uint32_t messageBase = 100000;
}
@ -160,6 +167,7 @@ export namespace ImsdMessages::Ui {
c.chrome.Quad(bar, c.theme.surface);
c.chrome.Quad({ bar.x, bar.y, bar.w, c.Dp(1) }, c.theme.divider);
const Box field{ bar.x + c.Dp(12), bar.y + c.Dp(10), fieldW, fieldH };
c.chrome.Quad(field, c.theme.bg, c.Dp(18)); // the field's box on the surface bar
composeLayout = DrawCompose(c, compose, field, caretVisible);
hits.push_back({ field, Hit::compose });
const bool enabled = canSend && !compose.value.empty();
@ -247,4 +255,71 @@ export namespace ImsdMessages::Ui {
}
}
};
// The screen behind the +: a number, and Start.
class NewScreen {
public:
ComposeState field;
ComposeLayout fieldLayout;
bool caretVisible = true;
std::string error;
void Draw(Canvas& c, Box area, std::vector<HitRegion>& hits) {
const float x = area.x + c.Dp(16);
const float w = area.w - c.Dp(32);
float y = area.y + c.Dp(20);
c.chrome.Text("To", x, y + c.Ascent(c.Dp(13)), c.Font(), c.Dp(13), c.theme.muted);
y += c.LineHeight(c.Dp(13)) + c.Dp(6);
const Box box{ x, y, w, c.LineHeight(c.Dp(16)) + 2 * c.Dp(8) };
c.chrome.Quad(box, c.theme.surface, c.Dp(18), c.Dp(1), c.theme.divider);
fieldLayout = DrawCompose(c, field, box, caretVisible, "Number");
hits.push_back({ box, Hit::newField });
y = box.Bottom() + c.Dp(8);
const std::string hint = error.empty() ? "Like +31 6 1234 5678 or 06 1234 5678" : error;
c.chrome.Text(c.Wrapper().Ellipsize(hint, c.Dp(13), w), x, y + c.Ascent(c.Dp(13)), c.Font(), c.Dp(13), error.empty() ? c.theme.muted : c.theme.danger);
y += c.LineHeight(c.Dp(13)) + c.Dp(20);
const bool enabled = !field.value.empty();
const Box button{ x, y, w, c.Dp(44) };
c.chrome.Quad(button, enabled ? c.theme.accent : c.theme.divider, c.Dp(22));
c.chrome.Text("Start", button.x + button.w / 2, c.CenteredBaseline(button, c.Dp(16)), c.Font(), c.Dp(16), enabled ? c.theme.onAccent : c.theme.muted, Crafter::TextAlign::Center);
if (enabled) hits.push_back({ button, Hit::start });
}
};
// A bottom sheet over everything: a title, two or three actions, a scrim
// that dismisses. Drawn in the overlay layer; its regions are pushed last,
// so they win the hit test.
struct Sheet {
enum class Kind : std::uint8_t { DeleteConversation, MessageActions };
Kind kind = Kind::DeleteConversation;
std::string key; // the conversation
std::uint64_t messageId = 0;
std::string text; // the message (for Copy)
};
void DrawSheet(Canvas& c, const Sheet& sheet, std::vector<HitRegion>& hits) {
const Box all{ 0, 0, c.Width(), c.Height() };
c.overlay.Quad(all, c.theme.scrim);
hits.push_back({ all, Hit::sheetScrim });
const bool conversation = sheet.kind == Sheet::Kind::DeleteConversation;
const std::size_t buttons = conversation ? 2 : 3;
const float buttonH = c.Dp(48);
const float panelH = c.Dp(16) + c.LineHeight(c.Dp(16)) + c.Dp(12) + buttonH * static_cast<float>(buttons) + c.Dp(8) * static_cast<float>(buttons - 1) + c.Dp(20);
const Box panel{ 0, c.Height() - panelH, c.Width(), panelH + c.Dp(24) };
c.overlay.Quad(panel, c.theme.surface, c.Dp(20));
hits.push_back({ panel, Hit::sheetPanel }); // over the scrim: a tap on the panel itself dismisses nothing
const std::string title = conversation ? std::format("Delete the conversation with {}?", DisplayNumber(sheet.key)) : "Message";
c.overlay.Text(c.Wrapper().Ellipsize(title, c.Dp(16), panel.w - c.Dp(32)), c.Dp(16), panel.y + c.Dp(16) + c.Ascent(c.Dp(16)), c.Font(), c.Dp(16), c.theme.text);
float y = panel.y + c.Dp(16) + c.LineHeight(c.Dp(16)) + c.Dp(12);
auto button = [&](std::string_view label, Color bg, Color fg, std::uint32_t id) {
const Box b{ c.Dp(16), y, panel.w - c.Dp(32), buttonH };
c.overlay.Quad(b, bg, c.Dp(24));
c.overlay.Text(label, b.x + b.w / 2, c.CenteredBaseline(b, c.Dp(16)), c.Font(), c.Dp(16), fg, Crafter::TextAlign::Center);
hits.push_back({ b, id });
y += buttonH + c.Dp(8);
};
if (!conversation) button("Copy text", c.theme.bg, c.theme.text, Hit::sheetCopy);
button(conversation ? "Delete conversation" : "Delete message", c.theme.danger, c.theme.onAccent, Hit::sheetDelete);
button("Cancel", c.theme.bg, c.theme.text, Hit::sheetCancel);
}
}