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

morph::ui::Mounted: builds a view tree's widgets through a backend once, and keeps them current through reactive bindings. More...

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <exception>
#include <functional>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <optional>
#include <ranges>
#include <stdexcept>
#include <string>
#include <string_view>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <variant>
#include <vector>
#include "../attributes.hpp"
#include "../reactive/runtime.hpp"
#include "../reactive/scope.hpp"
#include "../reactive/signal.hpp"
#include "../ui/backend.hpp"
#include "view.hpp"

Go to the source code of this file.

Classes

struct  morph::ui::detail::KeyedRow
 One mounted row of a ForEach or Table. More...
struct  morph::ui::detail::VisibleRange
 What the backend's own scroll position asks a virtualized table to realize next. More...
struct  morph::ui::detail::KeyedRows
 The mounted rows of one ForEach or Table, in their container's order. More...
struct  morph::ui::detail::Pages
 Where one Tabs keeps its pages: a slot per tab, made the first time the tab is selected and kept, hidden, after. More...
class  morph::ui::detail::Mounter
 Builds widgets for nodes and wires their props and callbacks. More...
class  morph::ui::Mounted
 A view tree mounted on a backend: its widgets, built once, and the bindings that keep them current. More...

Namespaces

namespace  morph::ui::detail::site
 The site names a misuse in this layer is reported under, through the runtime's owner probe.

Typedefs

using morph::ui::detail::RowHook = std::function<void(reactive::Scope&, Node const&, Widget&, Key const&)>
 Called for each newly mounted row with its widget and key; a Table tells its widget the row's key.

Enumerations

enum class  morph::ui::detail::RowWidgetState : std::uint8_t { Realized , Dewindowed , NullView }
 Whether a row's widget is realized, and if not, why – so the windowing pass of reconcile never confuses a row that has no widget by design (its view was a null node) with one whose widget is simply not realized right now, which it should realize the next time the row enters the visible range. More...

Functions

std::vector< bool > morph::ui::detail::stableTargets (std::vector< std::size_t > const &sequence)
 Which entries of a permutation lie on one longest increasing run.
void morph::ui::detail::reorderChildren (ContainerWidget &container, std::vector< Widget * > &current, std::vector< Widget * > const &target)
 Brings a container's children from their current order into the target order with moveChild, moving only the children outside a longest run already in order.

Variables

constexpr char const * morph::ui::detail::site::kCallbackThrew = "morph::ui: an exception escaped a widget callback"
 An exception escaped a widget callback; the mount caught it, so it never reaches the backend.
constexpr char const * morph::ui::detail::site::kDuplicateKey = "morph::ui: duplicate ForEach key"
 A ForEach or Table snapshot repeated a key; the later row is refused and the first one kept.

Detailed Description

morph::ui::Mounted: builds a view tree's widgets through a backend once, and keeps them current through reactive bindings.

Specified in docs/spec/ui/view_tree.md, "Mount".

Definition in file mount.hpp.

Typedef Documentation

◆ RowHook

using morph::ui::detail::RowHook = std::function<void(reactive::Scope&, Node const&, Widget&, Key const&)>

Called for each newly mounted row with its widget and key; a Table tells its widget the row's key.

Definition at line 51 of file mount.hpp.

Enumeration Type Documentation

◆ RowWidgetState

enum class morph::ui::detail::RowWidgetState : std::uint8_t
strong

Whether a row's widget is realized, and if not, why – so the windowing pass of reconcile never confuses a row that has no widget by design (its view was a null node) with one whose widget is simply not realized right now, which it should realize the next time the row enters the visible range.

Enumerator
Realized 

widgetScope/widget are set.

Dewindowed 

The row's view is not null, but its widget is not realized: out of the visible range.

NullView 

The row's view is a null node; it never had a widget and never will while that stays true.

Definition at line 56 of file mount.hpp.

Function Documentation

◆ stableTargets()

std::vector< bool > morph::ui::detail::stableTargets ( std::vector< std::size_t > const & sequence)
inlinenodiscard

Which entries of a permutation lie on one longest increasing run.

sequence holds, in current order, each widget's target position; the widgets on the run are already in order relative to each other and stay where they are, and every other one is moved once.

Parameters
sequenceA permutation of 0 .. n-1.
Returns
Indexed by target position: whether that widget stays.

Definition at line 129 of file mount.hpp.

◆ reorderChildren()

void morph::ui::detail::reorderChildren ( ContainerWidget & container,
std::vector< Widget * > & current,
std::vector< Widget * > const & target )
inline

Brings a container's children from their current order into the target order with moveChild, moving only the children outside a longest run already in order.

Parameters
containerThe container.
currentIts children, in their current order. Kept equal to the container's order after every move, so it is still that order when a move throws.
targetThe same children, in the order wanted.

Definition at line 159 of file mount.hpp.