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:
parent
53bc4797bc
commit
20e687452f
10 changed files with 358 additions and 38 deletions
|
|
@ -106,7 +106,8 @@ export namespace ImsdMessages {
|
|||
// What was typed in the conversations that were left, and not sent, by
|
||||
// conversation key, for this run. A draft is its conversation's, not
|
||||
// the view's: leaving the conversation keeps it, opening it again
|
||||
// takes it up, and it goes when it is sent.
|
||||
// takes it up, and it goes when it is sent or the conversation is
|
||||
// deleted.
|
||||
class Drafts {
|
||||
public:
|
||||
// A conversation is left: what its field holds is kept and comes
|
||||
|
|
@ -140,6 +141,11 @@ export namespace ImsdMessages {
|
|||
return field;
|
||||
}
|
||||
|
||||
// The conversation was deleted: its draft goes with it.
|
||||
void Drop(std::string_view key) {
|
||||
if (const auto kept = byKey.find(key); kept != byKey.end()) byKey.erase(kept);
|
||||
}
|
||||
|
||||
// imsd's status: the key of a kept typed address follows it as an
|
||||
// open conversation's does (Number's AfterStatus, with the same
|
||||
// arguments; `nothingStored` says whether a key has no texts) — a
|
||||
|
|
|
|||
|
|
@ -41,12 +41,14 @@ export namespace ImsdMessages {
|
|||
// the long-press time is a tap; a press held past that time without
|
||||
// moving is a long press (the host runs the timer and calls Timeout);
|
||||
// movement past the slop starts a drag whose release is a fling when it
|
||||
// was fast enough.
|
||||
// was fast enough. Where the host says that what the press lands on has
|
||||
// no long press, a press held as long is still a tap at its release.
|
||||
class GestureDetector {
|
||||
public:
|
||||
float slopPx = 8;
|
||||
std::int64_t longPressMs = 500;
|
||||
float flingMinPxPerS = 60;
|
||||
bool longPress = true; // whether the press that follows can be a long press: the host's word, before each Down
|
||||
|
||||
GestureEvent Feed(PointerPhase phase, Point p, std::int64_t tMs) {
|
||||
GestureEvent e;
|
||||
|
|
@ -100,7 +102,7 @@ export namespace ImsdMessages {
|
|||
e.kind = GestureEvent::Kind::Release;
|
||||
}
|
||||
e.at = p;
|
||||
} else if (!longPressed && tMs - downAt < longPressMs) {
|
||||
} else if (!longPressed && (!longPress || tMs - downAt < longPressMs)) {
|
||||
e.kind = GestureEvent::Kind::Tap;
|
||||
e.at = down;
|
||||
} else {
|
||||
|
|
@ -122,7 +124,7 @@ export namespace ImsdMessages {
|
|||
// The host's timer at Down + longPressMs.
|
||||
GestureEvent Timeout(std::int64_t tMs) {
|
||||
GestureEvent e;
|
||||
if (!pressed || dragging || longPressed || tMs - downAt < longPressMs) return e;
|
||||
if (!longPress || !pressed || dragging || longPressed || tMs - downAt < longPressMs) return e;
|
||||
longPressed = true;
|
||||
e.kind = GestureEvent::Kind::LongPress;
|
||||
e.at = down;
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ export namespace ImsdMessages::Bus {
|
|||
g_dbus_connection_call(conn, notifyName, notifyPath, notifyName, "Notify", g_variant_new("(susssasa{sv}i)", "imsd-messages", replaces, std::string(appId).c_str(), summary.c_str(), body.c_str(), &actions, &hints, -1), G_VARIANT_TYPE("(u)"), G_DBUS_CALL_FLAGS_NONE, -1, nullptr, OnNotified, new std::pair<Notifier*, std::string>(this, m.conversation));
|
||||
}
|
||||
|
||||
// The conversation was opened: its notification goes.
|
||||
// The conversation was opened or deleted: its notification goes.
|
||||
void Close(const std::string& conversation) {
|
||||
if (!conn) return;
|
||||
waiting.erase(conversation);
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ export namespace ImsdMessages::Ui {
|
|||
hits.clear();
|
||||
hitKeys.clear();
|
||||
hitMessages.clear();
|
||||
textSinceFrame.clear();
|
||||
}
|
||||
|
||||
static gboolean OnHideIdle(gpointer data) {
|
||||
|
|
@ -102,6 +103,7 @@ export namespace ImsdMessages::Ui {
|
|||
bool closeQuits = false; // no session bus: a close ends the process, since nothing could show the window again
|
||||
std::function<void()> onQuit; // the screenshot's run is over, or the window closed with no bus to come back on
|
||||
std::function<void(const std::string&)> onConversationOpened; // the notification goes
|
||||
std::function<void(const std::string&)> onConversationDeleted; // so does the notification
|
||||
std::function<void(std::string_view)> onLog;
|
||||
std::function<void()> onDisplayLost; // the compositor's connection broke
|
||||
std::int32_t exitCode = 0; // what main returns when nothing else decided: 1 for a screenshot not written
|
||||
|
|
@ -165,6 +167,7 @@ export namespace ImsdMessages::Ui {
|
|||
if (gestures.Pressed()) Pointer(PointerPhase::Move);
|
||||
});
|
||||
scrollSub.emplace(&w.onMouseScroll, [this](std::uint32_t raw) {
|
||||
if (sheet || fresh) return; // a sheet takes the wheel as it takes the taps; the new-conversation screen scrolls nothing
|
||||
const std::int32_t detents = static_cast<std::int32_t>(raw);
|
||||
ActiveScroll().ScrollBy(static_cast<float>(detents) * canvas->Dp(48));
|
||||
if (view) view->stickToBottom = false;
|
||||
|
|
@ -178,15 +181,24 @@ export namespace ImsdMessages::Ui {
|
|||
}
|
||||
});
|
||||
textSub.emplace(&w.onTextInput, [this](const std::string_view text) {
|
||||
if (!view) return;
|
||||
ComposeInsert(view->compose, text);
|
||||
ShowCaret();
|
||||
if (sheet) return;
|
||||
if (fresh) {
|
||||
// One line: a pasted number's line breaks are dropped, the rest kept.
|
||||
std::string oneLine(text);
|
||||
std::erase_if(oneLine, [](char c) { return c == '\n' || c == '\r'; });
|
||||
ComposeInsert(fresh->field, oneLine);
|
||||
fresh->error.clear();
|
||||
ShowCaret();
|
||||
} else if (view) {
|
||||
ComposeInsert(view->compose, text);
|
||||
ShowCaret();
|
||||
}
|
||||
});
|
||||
resizeSub.emplace(&w.onResize, [this] { Dirty(); });
|
||||
closeSub.emplace(&w.onClose, [this] { Close(); });
|
||||
Reload();
|
||||
Opened();
|
||||
if (view && view->compose.focused) ShowCaret(); // the blink a hide stopped
|
||||
if (fresh || (view && view->compose.focused)) ShowCaret(); // the blink a hide stopped
|
||||
w.Render();
|
||||
frames->RequestRedraw();
|
||||
}
|
||||
|
|
@ -236,6 +248,8 @@ export namespace ImsdMessages::Ui {
|
|||
StopFling();
|
||||
CancelGesture();
|
||||
KeepWindow();
|
||||
fresh.reset();
|
||||
sheet.reset();
|
||||
if (!view || view->key != key) {
|
||||
KeepDraft();
|
||||
view.emplace();
|
||||
|
|
@ -261,6 +275,21 @@ export namespace ImsdMessages::Ui {
|
|||
}
|
||||
|
||||
void Back() {
|
||||
// Every exit is a screen change: a press held across it (Escape
|
||||
// on a keyboard while a finger or a button is down) is cancelled,
|
||||
// not resolved against what the next frame draws there.
|
||||
if (sheet) {
|
||||
CancelGesture();
|
||||
sheet.reset();
|
||||
Dirty();
|
||||
return;
|
||||
}
|
||||
if (fresh) {
|
||||
CancelGesture();
|
||||
fresh.reset();
|
||||
Dirty();
|
||||
return;
|
||||
}
|
||||
if (!view) return;
|
||||
StopFling();
|
||||
CancelGesture();
|
||||
|
|
@ -274,10 +303,48 @@ export namespace ImsdMessages::Ui {
|
|||
Dirty();
|
||||
}
|
||||
|
||||
// Puts text into the open conversation's field (the bench's typing).
|
||||
// The screen behind the +.
|
||||
void NewConversation() {
|
||||
StopFling();
|
||||
CancelGesture();
|
||||
KeepDraft();
|
||||
view.reset();
|
||||
sheet.reset();
|
||||
fresh.emplace();
|
||||
Show();
|
||||
if (sync) sync->SetOpenConversation(std::nullopt);
|
||||
ShowCaret();
|
||||
}
|
||||
|
||||
// Start, from the new-conversation screen: a number becomes a key.
|
||||
void Start() {
|
||||
if (!fresh) return;
|
||||
const std::string key = ConversationKey(fresh->field.value, sync ? sync->CountryCode() : "");
|
||||
if (key.empty()) {
|
||||
fresh->error = "Enter a phone number";
|
||||
Dirty();
|
||||
return;
|
||||
}
|
||||
const std::string dialled = DialledNumber(fresh->field.value);
|
||||
fresh.reset();
|
||||
Open(key, dialled);
|
||||
}
|
||||
|
||||
// The bench's hands: types into the field of the open screen, and
|
||||
// opens a sheet as a long press would.
|
||||
void Prefill(std::string_view text) {
|
||||
if (!view) return;
|
||||
ComposeInsert(view->compose, text);
|
||||
if (fresh) ComposeInsert(fresh->field, text);
|
||||
else if (view) ComposeInsert(view->compose, text);
|
||||
Dirty();
|
||||
}
|
||||
|
||||
void BenchSheet(std::string_view which) {
|
||||
// As a long press opens them: a conversation's sheet over the
|
||||
// list, a message's over its conversation — and a line when the
|
||||
// screen has nothing of the kind to press.
|
||||
if (which == "conversation" && !view && !fresh && !convs.empty()) sheet = Sheet{ Sheet::Kind::DeleteConversation, convs.front().key, 0, "" };
|
||||
else if (which == "message" && view && !view->messages.empty()) sheet = Sheet{ Sheet::Kind::MessageActions, view->key, view->messages.front().id, view->messages.front().text };
|
||||
else Log(std::format("--bench-sheet {}: nothing on this screen to press", which));
|
||||
Dirty();
|
||||
}
|
||||
|
||||
|
|
@ -342,6 +409,24 @@ export namespace ImsdMessages::Ui {
|
|||
|
||||
void Changed() { Reload(); }
|
||||
|
||||
// A text arrived. A sheet that asks to delete its conversation goes:
|
||||
// the question was about the texts the list showed, and a yes to it
|
||||
// would delete this one unread. A press on its 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 now, and one
|
||||
// that comes down before the next frame is drawn (Pointer), have no
|
||||
// long press. A release before the long-press time is still the
|
||||
// row's tap, while the row stays under the finger.
|
||||
void Imported(const Message& m) {
|
||||
if (sheet && sheet->kind == Sheet::Kind::DeleteConversation && sheet->key == m.conversation) {
|
||||
CancelGesture();
|
||||
sheet.reset();
|
||||
}
|
||||
textSinceFrame.insert(m.conversation);
|
||||
if (gestures.Pressed() && pressedOn && pressedOn->id == Hit::rowBase && pressedOn->key == m.conversation) pressGotText = true;
|
||||
Reload();
|
||||
}
|
||||
|
||||
private:
|
||||
void Log(std::string_view line) {
|
||||
if (onLog) onLog(line);
|
||||
|
|
@ -419,7 +504,11 @@ export namespace ImsdMessages::Ui {
|
|||
if (frames->Animating()) {
|
||||
if (!ActiveScroll().Tick(std::min(dt, 0.05f))) frames->SetAnimating(false);
|
||||
}
|
||||
if (view) {
|
||||
if (fresh) {
|
||||
Box area = DrawHeader(c, "New message", true, hits);
|
||||
area = DrawBanner(c, area, status);
|
||||
fresh->Draw(c, area, hits);
|
||||
} else if (view) {
|
||||
Box area = DrawHeader(c, DisplayNumber(view->key), true, hits);
|
||||
area = DrawBanner(c, area, status);
|
||||
area = view->DrawComposeBar(c, area, CanSend(status) && !Destination().empty(), hits);
|
||||
|
|
@ -429,12 +518,14 @@ export namespace ImsdMessages::Ui {
|
|||
area = DrawBanner(c, area, status);
|
||||
list.Draw(c, area, convs, now, zone, hits);
|
||||
}
|
||||
if (sheet) DrawSheet(c, *sheet, hits);
|
||||
// What the regions name, as drawn: a reload before the next frame
|
||||
// re-sorts the vectors, so a gesture resolves against these.
|
||||
hitKeys.clear();
|
||||
for (const auto& conv : convs) hitKeys.push_back(conv.key);
|
||||
hitMessages.clear();
|
||||
if (view) for (const Message& m : view->messages) hitMessages.push_back(m.id);
|
||||
textSinceFrame.clear(); // this frame's regions are of the texts as they are now
|
||||
if (c.Overflowed() && !overflowLogged) {
|
||||
overflowLogged = true;
|
||||
Log("a layer ran out of items this frame; the buffers are too small for this screen");
|
||||
|
|
@ -449,11 +540,19 @@ export namespace ImsdMessages::Ui {
|
|||
gestures.slopPx = canvas->Dp(8);
|
||||
gestures.flingMinPxPerS = canvas->Dp(60);
|
||||
if (phase == PointerPhase::Down) ActiveScroll().velocity = 0; // a finger down stops the fling under it
|
||||
if (phase == PointerPhase::Down) pressedOn = Target(p);
|
||||
if (phase == PointerPhase::Down) {
|
||||
pressedOn = Target(p);
|
||||
pressGotText = pressedOn && pressedOn->id == Hit::rowBase && textSinceFrame.contains(pressedOn->key);
|
||||
// Only a row and a message have a long press. A press on
|
||||
// anything else — a button, a field, a sheet's row — stays
|
||||
// that control's tap at its release, however long it was
|
||||
// held: a slow finger presses the button all the same.
|
||||
gestures.longPress = pressedOn && pressedOn->id >= Hit::rowBase;
|
||||
}
|
||||
Handle(gestures.Feed(phase, p, NowMs()));
|
||||
if (phase == PointerPhase::Down) {
|
||||
if (longPressTimer) g_source_remove(longPressTimer);
|
||||
longPressTimer = g_timeout_add(static_cast<guint>(gestures.longPressMs), OnLongPress, this);
|
||||
longPressTimer = gestures.longPress ? g_timeout_add(static_cast<guint>(gestures.longPressMs), OnLongPress, this) : 0;
|
||||
} else if (phase != PointerPhase::Move && longPressTimer) {
|
||||
g_source_remove(longPressTimer);
|
||||
longPressTimer = 0;
|
||||
|
|
@ -468,23 +567,27 @@ export namespace ImsdMessages::Ui {
|
|||
}
|
||||
|
||||
void Handle(const GestureEvent& e) {
|
||||
if (sheet && e.kind != GestureEvent::Kind::Tap) return;
|
||||
// A tap or a long press acts on what the press went down on: a
|
||||
// frame drawn meanwhile (a new text snapped the conversation, the
|
||||
// list re-sorted) that moved another bubble or row under the
|
||||
// finger names something else, and the release acts on nothing.
|
||||
if ((e.kind == GestureEvent::Kind::Tap || e.kind == GestureEvent::Kind::LongPress) && Target(e.at) != pressedOn) return;
|
||||
if (e.kind == GestureEvent::Kind::LongPress && pressGotText) return; // the pressed row had not shown a text of its conversation (Imported)
|
||||
switch (e.kind) {
|
||||
case GestureEvent::Kind::None: return;
|
||||
case GestureEvent::Kind::Tap: Tap(e.at); return;
|
||||
case GestureEvent::Kind::LongPress: Log("long press (actions come in a later step)"); return;
|
||||
case GestureEvent::Kind::LongPress: LongPress(e.at); return;
|
||||
case GestureEvent::Kind::DragStart:
|
||||
case GestureEvent::Kind::Drag:
|
||||
if (fresh) return; // the new-conversation screen scrolls nothing
|
||||
frames->SetAnimating(false);
|
||||
ActiveScroll().ScrollBy(-e.delta.y);
|
||||
if (view) view->stickToBottom = false;
|
||||
Dirty();
|
||||
return;
|
||||
case GestureEvent::Kind::Fling:
|
||||
if (fresh) return;
|
||||
ActiveScroll().Fling(-e.velocity.y);
|
||||
frames->SetAnimating(true);
|
||||
return;
|
||||
|
|
@ -505,13 +608,34 @@ export namespace ImsdMessages::Ui {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// A key: Escape goes back; Ctrl+Enter sends; the rest edits the field.
|
||||
// A key: Escape goes back; Enter on the number screen starts the
|
||||
// conversation; Ctrl+Enter sends; the rest edits the field.
|
||||
void Key(Crafter::KeyCode code) {
|
||||
using Crafter::CrafterKeys;
|
||||
// A key whose press changed the screen acts once: held, the
|
||||
// library sends it again (its repeat is that key's while it
|
||||
// runs), and those are the old screen's — Enter's, which
|
||||
// started the conversation, would type line breaks into its
|
||||
// field, and Escape's would go on back, from a sheet through
|
||||
// the conversation and its draft. A new press acts again.
|
||||
if (spentKey == code) {
|
||||
if (Crafter::Device::keyRepeat.active && Crafter::Device::keyRepeat.key == code) return;
|
||||
spentKey.reset();
|
||||
}
|
||||
if (code == Crafter::Key(CrafterKeys::Escape)) {
|
||||
spentKey = code;
|
||||
Back();
|
||||
return;
|
||||
}
|
||||
if (sheet) return;
|
||||
if (fresh) {
|
||||
if (code == Crafter::Key(CrafterKeys::Enter) || code == Crafter::Key(CrafterKeys::keypad_enter)) {
|
||||
Start();
|
||||
if (!fresh) spentKey = code; // started: the conversation's screen is up
|
||||
} else if (ComposeKey(fresh->field, code)) ShowCaret();
|
||||
if (!repeatTimer) repeatTimer = g_timeout_add(30, OnRepeat, this);
|
||||
return;
|
||||
}
|
||||
if (!view) return;
|
||||
const std::unordered_set<Crafter::KeyCode>& held = canvas->Window().heldKeys;
|
||||
const bool ctrl = held.contains(Crafter::Key(CrafterKeys::LeftCtrl)) || held.contains(Crafter::Key(CrafterKeys::RightCtrl));
|
||||
|
|
@ -539,8 +663,9 @@ export namespace ImsdMessages::Ui {
|
|||
// the window is up (without one nothing draws it; Show starts the
|
||||
// blink again).
|
||||
void ShowCaret() {
|
||||
if (!view) return;
|
||||
view->caretVisible = true;
|
||||
if (!view && !fresh) return;
|
||||
if (view) view->caretVisible = true;
|
||||
if (fresh) fresh->caretVisible = true;
|
||||
if (blinkTimer) g_source_remove(blinkTimer);
|
||||
blinkTimer = canvas ? g_timeout_add(500, OnBlink, this) : 0;
|
||||
Dirty();
|
||||
|
|
@ -548,20 +673,82 @@ export namespace ImsdMessages::Ui {
|
|||
|
||||
static gboolean OnBlink(gpointer data) {
|
||||
App& self = *static_cast<App*>(data);
|
||||
if (!self.view) {
|
||||
if (!self.view && !self.fresh) {
|
||||
self.blinkTimer = 0;
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
self.view->caretVisible = !self.view->caretVisible;
|
||||
if (self.view) self.view->caretVisible = !self.view->caretVisible;
|
||||
if (self.fresh) self.fresh->caretVisible = !self.fresh->caretVisible;
|
||||
self.Dirty();
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
void LongPress(Point at) {
|
||||
const std::optional<std::uint32_t> id = HitTest(hits, at);
|
||||
if (!id) return;
|
||||
if (*id >= Hit::messageBase && view) {
|
||||
if (const Message* m = HitMessage(*id - Hit::messageBase)) sheet = Sheet{ Sheet::Kind::MessageActions, view->key, m->id, m->text };
|
||||
} else if (*id >= Hit::rowBase && !view && !fresh) {
|
||||
const std::size_t i = *id - Hit::rowBase;
|
||||
if (i < hitKeys.size()) sheet = Sheet{ Sheet::Kind::DeleteConversation, hitKeys[i], 0, "" };
|
||||
}
|
||||
Dirty();
|
||||
}
|
||||
|
||||
// A conversation that no longer exists: its notification goes, and
|
||||
// the view on it closes, its field's text kept as at any leave (a
|
||||
// view closes when its last message is deleted; a conversation
|
||||
// deleted whole takes its draft with it, SheetAction).
|
||||
void ConversationGone(const std::string& key) {
|
||||
if (onConversationDeleted) onConversationDeleted(key);
|
||||
if (view && view->key == key) {
|
||||
StopFling();
|
||||
CancelGesture();
|
||||
KeepDraft();
|
||||
view.reset();
|
||||
if (sync) sync->SetOpenConversation(std::nullopt);
|
||||
}
|
||||
}
|
||||
|
||||
void SheetAction(std::uint32_t id) {
|
||||
if (!sheet) return;
|
||||
const Sheet s = *sheet;
|
||||
sheet.reset();
|
||||
if (id == Hit::sheetDelete) {
|
||||
if (s.kind == Sheet::Kind::DeleteConversation) {
|
||||
if (sync) sync->EraseConversation(s.key);
|
||||
else store.EraseConversation(s.key);
|
||||
} else {
|
||||
if (sync) sync->Erase(s.messageId);
|
||||
else store.Erase(s.messageId);
|
||||
}
|
||||
// Gone once no message is left (the list groups messages) —
|
||||
// not on a delete the store refused: the rows stay, their
|
||||
// notification with them, and the banner says why.
|
||||
if (store.Conversation(s.key).empty()) {
|
||||
ConversationGone(s.key);
|
||||
if (s.kind == Sheet::Kind::DeleteConversation) drafts.Drop(s.key);
|
||||
}
|
||||
Reload();
|
||||
} else if (id == Hit::sheetCopy) {
|
||||
if (!Crafter::Clipboard::SetText(s.text)) Log("the clipboard did not take the text");
|
||||
}
|
||||
Dirty();
|
||||
}
|
||||
|
||||
void Tap(Point at) {
|
||||
const std::optional<std::uint32_t> id = HitTest(hits, at);
|
||||
if (!id) return;
|
||||
if (*id == Hit::back) {
|
||||
if (*id == Hit::sheetScrim || *id == Hit::sheetCancel || *id == Hit::sheetDelete || *id == Hit::sheetCopy) {
|
||||
SheetAction(*id);
|
||||
} else if (*id == Hit::back) {
|
||||
Back();
|
||||
} else if (*id == Hit::start) {
|
||||
Start();
|
||||
} else if (*id == Hit::newField) {
|
||||
if (!fresh) return;
|
||||
fresh->field.cursor = ComposeHit(*canvas, fresh->field, fresh->fieldLayout, at);
|
||||
ShowCaret();
|
||||
} else if (*id == Hit::compose) {
|
||||
if (!view) return;
|
||||
view->compose.focused = true;
|
||||
|
|
@ -570,7 +757,7 @@ export namespace ImsdMessages::Ui {
|
|||
} else if (*id == Hit::send) {
|
||||
SendDraft();
|
||||
} else if (*id == Hit::fab) {
|
||||
Log("new conversation (comes in a later step)");
|
||||
NewConversation();
|
||||
} else if (*id >= Hit::messageBase) {
|
||||
if (!view || !sync) return;
|
||||
const Message* m = HitMessage(*id - Hit::messageBase);
|
||||
|
|
@ -590,16 +777,21 @@ export namespace ImsdMessages::Ui {
|
|||
std::vector<std::string> hitKeys; // the conversation each row region named, as drawn
|
||||
std::vector<std::uint64_t> hitMessages; // the message each bubble region named, as drawn
|
||||
std::optional<HitTarget> pressedOn; // what the press went down on, as drawn then
|
||||
bool pressGotText = false; // the pressed row had not shown a text of its conversation: no long press (Imported)
|
||||
std::unordered_set<std::string> textSinceFrame; // the conversations a text arrived for since the regions were recorded
|
||||
std::optional<WaylandSource> source;
|
||||
std::optional<FrameDriver> frames;
|
||||
std::optional<DayWatch> day; // while the window is up
|
||||
ListScreen list;
|
||||
std::optional<ViewScreen> view;
|
||||
Drafts drafts; // what was typed in the conversations left and not sent
|
||||
std::optional<NewScreen> fresh; // the new-conversation screen
|
||||
std::optional<Sheet> sheet;
|
||||
GestureDetector gestures;
|
||||
std::vector<HitRegion> hits;
|
||||
guint longPressTimer = 0;
|
||||
guint repeatTimer = 0;
|
||||
std::optional<Crafter::KeyCode> spentKey; // the key whose press changed the screen (Key)
|
||||
guint blinkTimer = 0;
|
||||
guint hideIdle = 0; // a close's Hide, deferred to the loop
|
||||
std::chrono::steady_clock::time_point lastFrame{};
|
||||
|
|
|
|||
|
|
@ -51,9 +51,10 @@ export namespace ImsdMessages::Ui {
|
|||
return std::max<std::size_t>(1, static_cast<std::size_t>(std::lround(layout.text.h / layout.lineHeight)));
|
||||
}
|
||||
|
||||
// The field: rounded, one to five lines tall, a placeholder when empty,
|
||||
// the caret at the cursor. Returns the layout the app needs for taps.
|
||||
ComposeLayout DrawCompose(Canvas& c, const ComposeState& s, Box field, bool caretVisible) {
|
||||
// The field's text: one to five lines tall, a placeholder when empty, the
|
||||
// caret at the cursor; the box itself is the caller's, whose screen
|
||||
// decides its fill and outline. Returns the layout the app needs for taps.
|
||||
ComposeLayout DrawCompose(Canvas& c, const ComposeState& s, Box field, bool caretVisible, std::string_view placeholder = "Message") {
|
||||
const float px = c.Dp(16);
|
||||
const float padX = c.Dp(12);
|
||||
const float padY = c.Dp(8);
|
||||
|
|
@ -61,9 +62,8 @@ export namespace ImsdMessages::Ui {
|
|||
layout.px = px;
|
||||
layout.lineHeight = c.LineHeight(px);
|
||||
layout.text = { field.x + padX, field.y + padY, field.w - 2 * padX, field.h - 2 * padY };
|
||||
c.chrome.Quad(field, c.theme.bg, c.Dp(18));
|
||||
if (s.value.empty()) {
|
||||
c.chrome.Text("Message", layout.text.x, layout.text.y + c.Ascent(px), c.Font(), px, c.theme.muted);
|
||||
c.chrome.Text(placeholder, layout.text.x, layout.text.y + c.Ascent(px), c.Font(), px, c.theme.muted);
|
||||
layout.lines = { { 0, 0, 0 } };
|
||||
} else {
|
||||
layout.lines = c.Wrapper().Wrap(s.value, px, layout.text.w);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ ImsdMessages.Ui — the window: Crafter.Graphics driven from the GLib main
|
|||
loop. Loop makes the Wayland display a GSource and owns the frame callback,
|
||||
Canvas holds the window, the font and the four compositing layers, Compose
|
||||
lays a field out and draws it over the core's editing (ImsdMessages:Edit),
|
||||
turning keys into its edits, Screens draw the conversation list and a
|
||||
conversation, App wires them to the store and to Sync.
|
||||
turning keys into its edits, Screens draw the conversation list, a
|
||||
conversation, the new-conversation screen and the sheets, App wires them to
|
||||
the store and to Sync.
|
||||
*/
|
||||
export module ImsdMessages.Ui;
|
||||
export import :Loop;
|
||||
|
|
|
|||
Loading…
Reference in a new issue