5#include <portals/text_format.hpp>
7#include <portals/virtual_table.hpp>
47template <
class T,
class Projection>
49 std::is_object_v<Projection> && std::copy_constructible<Projection> && std::invocable<Projection &, const T &>;
57template <
class T,
class Projection,
class Formatter>
60 requires(Projection &projection, Formatter &formatter,
const T &row) {
61 { std::invoke(formatter, std::invoke(projection, row)) } -> std::same_as<GraphemeText>;
82template <
class T,
class Projection,
class Formatter>
86 [projection = std::move(projection), formatter = std::move(formatter)](
const T &row)
mutable ->
GraphemeText {
87 return std::invoke(formatter, std::invoke(projection, row));
100template <
class T,
class Member,
class Formatter>
101 requires ColumnFormatter<T, Member T::*, Formatter>
119 return std::unexpected(
text.error());
138template <
class T,
class Member,
class Formatter>
141 Formatter formatter, std::int32_t width = 1,
146 return std::unexpected(options.error());
162template <
class T,
class Projection,
class Formatter>
165 std::int32_t width = 1) {
166 return {std::string(header), width,
167 [projection = std::move(projection), formatter = std::move(formatter)](
const T &row)
mutable ->
GraphemeText {
168 return std::invoke(formatter, std::invoke(projection, row));
182template <
class T,
class Member,
class Formatter>
183 requires ColumnFormatter<T, Member T::*, Formatter>
185 std::int32_t width = 1) {
195template <
class T,
class Projection>
196 requires ColumnProjection<T, Projection> &&
197 std::formattable<std::remove_cvref_t<std::invoke_result_t<Projection &, const T &>>,
char>
199 using Field = std::remove_cvref_t<std::invoke_result_t<Projection &, const T &>>;
200 return {std::string(header),
204 return [projection, formatter =
cellFormat<Field>(
"{}", policy)](
const T &row)
mutable {
205 return formatter(std::invoke(projection, row));
214template <
class T,
class Member>
215 requires ColumnProjection<T, Member T::*> &&
216 std::formattable<std::remove_cvref_t<std::invoke_result_t<Member T::*&, const T &>>,
char>
222template <
class T, std::size_t N, std::size_t... I>
223std::expected<std::array<TableColumn<T>, N>, TextError>
224assembleColumns(WidthPolicy policy, std::array<TableColumnSpec<T>, N> specs, std::index_sequence<I...>) {
225 constexpr std::uint64_t INITIAL_COLUMN_GENERATION = 1;
227 auto built = std::array{[&](std::size_t index) -> std::expected<TableColumn<T>, TextError> {
231 return std::unexpected(header.error());
234 auto format = specs[index].prepareFormat ? specs[index].prepareFormat(policy) : std::move(specs[index].format);
235 return TableColumn<T>{
236 {index + 1, INITIAL_COLUMN_GENERATION}, std::move(*header), specs[index].width, std::move(format)};
239 for (
const auto &column : built) {
241 return std::unexpected(column.error());
245 return std::array<TableColumn<T>, N>{std::move(*built[I])...};
262template <
class T,
class... Rest>
266 constexpr std::size_t COLUMN_COUNT = 1 +
sizeof...(Rest);
268 return detail::assembleColumns(
269 policy, std::array<
TableColumnSpec<T>, COLUMN_COUNT>{std::move(first), std::forward<Rest>(rest)...},
270 std::make_index_sequence<COLUMN_COUNT>{});
281template <
class T,
class... Rest>
282 requires(std::same_as<std::remove_cvref_t<Rest>, TableColumnSpec<T>> && ...)
Owning validated UTF-8 and immutable extended grapheme measurements.
Definition text.hpp:145
static std::expected< GraphemeText, TextError > from(std::string_view bytes, WidthPolicy policy={}, TextLimits limits={})
Validate, segment and measure a single logical UTF-8 buffer.
GraphemeText(const GraphemeText &other)=default
Copy bytes and metadata into independent storage; may allocate.
An owning copyable callable that projects a borrowed immutable row.
Definition table_column.hpp:48
consteval auto id(StyleState state=StyleState::ANY, bool readOnly=false)
Definition style_static.hpp:865
Public Portals API.
Definition action.hpp:8
ui::ValueText text(std::format_string< const ui::detail::TextArgumentValue< Args > &... > pattern, Args &&...args)
Declare live formatted text over explicit scalar roots, fields or value properties.
Definition ui_value_text.hpp:567
CellFormat< T > cellFormat(std::format_string< const T & > pattern, WidthPolicy policy={})
Build a reusable column formatter without a formatting lambda.
Definition text_format.hpp:76
std::expected< TableColumnOptions, TextError > columnOptions(ColumnId id, std::string_view header, std::int32_t width=1, WidthPolicy policy={})
Construct typed metadata from UTF-8 without unchecked header extraction.
Definition table_column.hpp:114
std::expected< std::array< TableColumn< T >, 1+sizeof...(Rest)>, TextError > tableColumns(WidthPolicy policy, TableColumnSpec< T > first, Rest &&...rest)
Assemble a fixed schema and allocate deterministic table-local identities.
Definition table_column.hpp:265
TableColumn< T > tableColumn(TableColumnOptions options, Projection projection, Formatter formatter)
Compose an owning typed column from explicit projection and text formatting.
Definition table_column.hpp:84
Owning fixed-schema caption and sizing, without identity bookkeeping.
Definition table_column.hpp:37
std::int32_t width
Positive width in terminal cells, validated by table preparation.
Definition table_column.hpp:39
std::string header
UTF-8 copied into the schema; captions may change with locale.
Definition table_column.hpp:38
Provider-assigned column identity; typed row accessors define column values.
Definition model.hpp:24
Owning metadata for a typed column; validation remains part of table preparation.
Definition table_column.hpp:17
ColumnId id
Nonzero unique value/generation pair within the table configuration.
Definition table_column.hpp:18
std::int32_t width
Positive width in terminal cells; columns remain in configured order.
Definition table_column.hpp:20
GraphemeText header
Owning header text using the table's width policy.
Definition table_column.hpp:19
Owning column recipe whose identity is assigned by tableColumns.
Definition table_column.hpp:28
std::string header
Owning UTF-8 caption, validated when the schema is assembled.
Definition table_column.hpp:29
std::int32_t width
Width in terminal cells, validated by table preparation.
Definition table_column.hpp:30
std::function< std::function< GraphemeText(const T &)>(WidthPolicy)> prepareFormat
Optional cold default formatter factory; each assembly owns its independent width policy.
Definition table_column.hpp:32
std::function< GraphemeText(const T &)> format
Owning callback; reference captures remain borrowed.
Definition table_column.hpp:31
A typed owning column definition; identity is independent of visual order.
Definition virtual_table.hpp:25
Owning error value, independent of the failed input's lifetime.
Definition text.hpp:87
Owning deterministic width policy; no font or terminal matching promise.
Definition text.hpp:42