Linux phones have no banking apps, and a command line is no answer on a phone. The app does everything the nostro command does and, like it, only talks to nostrod: it holds no key and no token. - Nostro.Ui, a toolkit whose screens are functions that fill a frame, ported from imsd-messages ca5cd72d; Nostro.App, the app's state, forms and screens; Nostro.Ui.Shell, which puts them on a Wayland window with Crafter.Graphics; nostro-app; and Nostro.DebugCommands for the --debug-api build. - Client: every method also in an asynchronous form for an sd-event loop, with DaemonMissing and OutcomeUnknown. - nostrod's Flatpak is net.catcrafts.Nostrod now and the app takes net.catcrafts.Nostro; install.sh moves the state. The app's Flatpak, both Flatpaks cross-built for aarch64, and the licence texts they carry. - nostro-fake-system, a made-up bus and bank with a real nostrod on them, to look at the app against. The README's screenshots are taken on it. - The nostro command: an API key's environment is the key's own to say, so --sandbox is for bunq-oauth alone, and a virtual card is listed as VIRTUAL. The published contract changes in three places, before any release (design rule 10): - Transactions' query takes `stored`: answered from what nostrod has stored, without asking the bank. The app searches with it; before, every search was a call to bunq. - AddBunq's `environment` no longer chooses over what the key says of itself: a key of the other environment is refused. - SetCardStatus refuses to freeze or unfreeze a virtual card. bunq reports one as DEACTIVATED however well it pays, and leaves it as it is when asked, without an error. The app is GPL-3.0-only, the library stays LGPL-3.0-only, and no code moved from one to the other (design rule 13). Transaction's schema is unchanged. Verified: the 17 tests pass with every line, function and region of what they link run, and the five lint runs are clean. Every screen was looked at on the made-up system, at a phone's and a desktop's sizes in the light and the dark look, on Plasma under Wayland. What is said of bunq's cards comes from its sandbox, with throwaway users, and from one real virtual card. Known to have been used against production: connecting, and reading accounts, payments and cards. Not known to have been tried: a payment from the app against bunq, OAuth against bunq, and anything on a phone. Building the app takes --graphics=, a Crafter.Graphics checkout on its branch claude/nostro-app, until that branch is merged and pinned here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
74 lines
3.9 KiB
C++
74 lines
3.9 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
|
|
|
export module Nostro.Ui:Text;
|
|
|
|
import std;
|
|
import :Geometry;
|
|
|
|
// Text as the toolkit handles it: UTF-8 by code point, measured through a font the window supplies, wrapped and cut
|
|
// to a width. The window library shapes one line at a time and knows no line breaks, so the lines are broken here; and
|
|
// since the font's advances come through TextMeasure, the tests pass a constant one and know every offset and width.
|
|
|
|
export namespace Nostro::Ui {
|
|
// Which of the app's fonts a text is set in.
|
|
enum class FontFace : std::uint8_t {
|
|
Regular,
|
|
Medium, // the same family, heavier: titles, amounts, buttons
|
|
Icons // a symbol font: one code point is one icon
|
|
};
|
|
|
|
// The code point at text[i], advancing i past it: 0 at the end, U+FFFD for a malformed sequence (at least one byte
|
|
// consumed, so a loop always ends).
|
|
std::uint32_t DecodeUtf8(std::string_view text, std::size_t& i);
|
|
// The byte offset of the code point before `at`, and of the one after it; `at` at either end stays there.
|
|
std::size_t PreviousCodepoint(std::string_view text, std::size_t at);
|
|
std::size_t NextCodepoint(std::string_view text, std::size_t at);
|
|
std::size_t CountCodepoints(std::string_view text);
|
|
|
|
// A font's sizes at a size in pixels, as the window's fonts give them: how far a code point moves the pen, how far
|
|
// the baseline is below a line's top, and how far apart baselines are.
|
|
struct TextMeasure {
|
|
std::function<float(FontFace face, std::uint32_t codepoint, float px)> advance;
|
|
std::function<float(FontFace face, float px)> ascent;
|
|
std::function<float(FontFace face, float px)> lineHeight;
|
|
};
|
|
|
|
// A line's width as it is drawn: the font's advances as they are, none for a newline, so a caret or a run that
|
|
// follows lands where the glyphs end.
|
|
float TextWidth(const TextMeasure& measure, std::string_view text, FontFace face, float px);
|
|
// The byte offset in a line nearest to `x` pixels from its start, by the same widths: where a tap puts the cursor.
|
|
std::size_t NearestByte(const TextMeasure& measure, std::string_view line, FontFace face, float px, float x);
|
|
// The baseline that puts one line of text in the middle of a box's height.
|
|
float CenteredBaseline(const TextMeasure& measure, Box box, FontFace face, float px);
|
|
// The text that fits in the width, "…" in place of what was cut; a line break cuts too, since this is for one line.
|
|
std::string Ellipsize(const TextMeasure& measure, std::string_view text, FontFace face, float px, float maxWidthPx);
|
|
|
|
struct WrappedLine {
|
|
std::size_t begin = 0; // byte offsets into the text
|
|
std::size_t end = 0; // exclusive; a space or a newline broken at is not part of the line, a hyphen is
|
|
float width = 0;
|
|
friend bool operator==(const WrappedLine&, const WrappedLine&) = default;
|
|
};
|
|
|
|
// Greedy word wrap: a break after a space or a hyphen, a hard break at '\n', a word wider than the line split
|
|
// between code points; the run of spaces where a line wraps goes to neither line. Results are kept per text, font,
|
|
// size and width, since a screen wraps the same texts every frame.
|
|
class WordWrapper {
|
|
public:
|
|
static constexpr std::size_t cacheLimit = 512;
|
|
|
|
explicit WordWrapper(TextMeasure measure);
|
|
|
|
// Valid until the next Wrap: a full cache is emptied.
|
|
const std::vector<WrappedLine>& Wrap(std::string_view text, FontFace face, float px, float maxWidthPx);
|
|
std::size_t CacheSize() const noexcept;
|
|
const TextMeasure& Measure() const noexcept;
|
|
|
|
private:
|
|
std::vector<WrappedLine> Compute(std::string_view text, FontFace face, float px, float maxWidthPx) const;
|
|
|
|
TextMeasure measure;
|
|
std::map<std::string, std::vector<WrappedLine>> cache;
|
|
};
|
|
}
|