morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
views.hpp File Reference

View-schema generation: composes a registered query action's result rows with an optional row-opener action and row/collection action buttons into a list/table or master-detail screen descriptor. More...

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <glaze/glaze.hpp>
#include <span>
#include <stdexcept>
#include <string>
#include <string_view>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
#include "../core/registry.hpp"
#include "forms.hpp"

Go to the source code of this file.

Classes

struct  morph::views::BindEntry
 Maps one target-action wire field to a row wire field, so a row's current value prefills the action's draft before it fires. More...
struct  morph::views::ActionDescriptor
 One action a view screen can fire — the row opener (v-rowAction) or an entry of v-actions. More...
struct  morph::views::ColumnOverride
 Declare-to-override entry for one derived column of a collection view. More...
struct  morph::views::CollectionView
 Tag type: V::kind selects a plain list/table screen. More...
struct  morph::views::MasterDetailView
 Tag type: V::kind selects a list + inline/side editor screen. Introduces no JSON keys beyond CollectionView — purely a rendering choice a conformant renderer may act on. More...
class  morph::views::ViewRegistry
 Process-level registry mapping a view's string type-id to its viewSchemaJson<V>() provider, so a controller can enumerate every registered view by name — parallels ActionExecuteRegistry for actions (docs/spec/core/bridge.md), but a view registers no executor, only a schema provider. More...

Macros

#define BRIDGE_REGISTER_VIEW(V, NAME)
 Registers view descriptor V with the string id NAME.

Enumerations

enum class  morph::views::ActionScope : std::uint8_t { Row , Collection }
 Where a view action button appears: opened per row, or once for the whole collection. More...

Functions

template<typename Action>
consteval ActionDescriptor morph::views::describeAction (std::string_view label={}, ActionScope scope=ActionScope::Row, std::span< const BindEntry > bind={}, bool confirm=false)
 Builds an ActionDescriptor for Action, resolving its wire type id from the real, registered ActionTraits<Action> rather than a hand-typed string.
template<typename V>
const std::string & morph::views::viewSchemaJson ()
 Generates the view-schema JSON document for view descriptor V.

Detailed Description

View-schema generation: composes a registered query action's result rows with an optional row-opener action and row/collection action buttons into a list/table or master-detail screen descriptor.

Where morph::forms::schemaJson<A>() describes one action, this header describes a set of related actions — a query, an edit, a delete — as a single, additional JSON document, morph::views::viewSchemaJson<V>(), emitted alongside (never merged into) the action schemas. See docs/spec/forms/views.md.

Definition in file views.hpp.

Macro Definition Documentation

◆ BRIDGE_REGISTER_VIEW

#define BRIDGE_REGISTER_VIEW ( V,
NAME )
Value:
template <> \
static constexpr std::string_view typeId() noexcept { return NAME; } \
}; \
namespace { \
[[maybe_unused]] const bool bridge_view_reg_##V = morph::views::detail::registerViewOnce<V>(NAME); \
}
Traits specialisation that maps a view descriptor type to its string type-id. Specialise via BRIDGE_R...
Definition views.hpp:569

Registers view descriptor V with the string id NAME.

Specialises morph::views::ViewTraits<V> and registers V's viewSchemaJson<V>() provider with the process-level ViewRegistry at static-init time — parallels BRIDGE_REGISTER_ACTION (registry.hpp), but a view has no dispatch path: it is metadata only, so this macro needs only <morph/core/registry.hpp>, never <morph/core/bridge.hpp>.

Parameters
VConcrete, unqualified view descriptor type in scope at the call site (bring a namespaced type into scope with using ns::V; first — this macro pastes V into an identifier, so it cannot be namespace-qualified).
NAMEString literal used as the view's type-id.

Definition at line 664 of file views.hpp.

Enumeration Type Documentation

◆ ActionScope

enum class morph::views::ActionScope : std::uint8_t
strong

Where a view action button appears: opened per row, or once for the whole collection.

Definition at line 38 of file views.hpp.

Function Documentation

◆ describeAction()

template<typename Action>
ActionDescriptor morph::views::describeAction ( std::string_view label = {},
ActionScope scope = ActionScope::Row,
std::span< const BindEntry > bind = {},
bool confirm = false )
nodiscardconsteval

Builds an ActionDescriptor for Action, resolving its wire type id from the real, registered ActionTraits<Action> rather than a hand-typed string.

Template Parameters
ActionRegistered action type — BRIDGE_REGISTER_ACTION for Action must already have run earlier in this translation unit, or ActionTraits<Action> is incomplete and this fails to compile.
Parameters
labelButton label. Defaults to empty ("use the action type id").
scopeRow button vs. collection-wide button. Defaults to Row.
bindField-name mapping prefilling the action's draft from the activating row. Defaults to empty (no prefill).
confirmWhether a renderer must confirm before firing. Defaults to false.
Returns
The populated descriptor.

Definition at line 87 of file views.hpp.

◆ viewSchemaJson()

template<typename V>
const std::string & morph::views::viewSchemaJson ( )
nodiscard

Generates the view-schema JSON document for view descriptor V.

A new, separate top-level document from morph::forms::schemaJson<A>() — never merged into any action schema. Computed once per type and cached, exactly like schemaJson<A>() — and, like it, returned by reference: the cache is created once per type per process, never mutated afterwards, and lives until the process exits, so the reference stays valid for as long as any caller could hold it. A caller that needs its own mutable copy asks for one (std::string mine = viewSchemaJson<V>();).

Template Parameters
VView descriptor: using kind = CollectionView (or MasterDetailView); using query = <registered query action>; optional static constexpr std::string_view title, rowKey, std::array<ColumnOverride, N> columns, ActionDescriptor rowAction, and std::array<ActionDescriptor, N> actions.
Returns
Reference to the process-lifetime view-schema JSON for V.

Definition at line 560 of file views.hpp.