Loading [MathJax]/extensions/tex2jax.js
ttx 0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
selection.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/container/algorithm/minmax.h"
4#include "di/reflect/prelude.h"
5#include "di/types/integers.h"
6
7namespace ttx::terminal {
13 u64 row { 0 };
14 u32 col { 0 };
15
16 auto operator==(SelectionPoint const&) const -> bool = default;
17 auto operator<=>(SelectionPoint const&) const = default;
18
19 constexpr friend auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<SelectionPoint>) {
20 return di::make_fields<"SelectionPoint">(di::field<"row", &SelectionPoint::row>,
21 di::field<"col", &SelectionPoint::col>);
22 }
23};
24
26struct Selection {
29
31 constexpr auto normalize() const -> Selection {
32 auto [s, e] = di::minmax({ start, end });
33 return { s, e };
34 }
35
36 constexpr auto operator==(Selection const& other) const -> bool {
37 auto a = this->normalize();
38 auto b = other.normalize();
39 return a.start == b.start && a.end == other.end;
40 }
41
42 constexpr friend auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<Selection>) {
43 return di::make_fields<"Selection">(di::field<"start", &Selection::start>, di::field<"end", &Selection::end>);
44 }
45};
46}
Definition capability.h:8
Represents a coordinate of a visual selection.
Definition selection.h:12
u32 col
The column referenced by the selection.
Definition selection.h:14
u64 row
The absolute row referenced by the selection.
Definition selection.h:13
auto operator<=>(SelectionPoint const &) const =default
constexpr friend auto tag_invoke(di::Tag< di::reflect >, di::InPlaceType< SelectionPoint >)
Definition selection.h:19
auto operator==(SelectionPoint const &) const -> bool=default
Represents the visual selection of a terminal.
Definition selection.h:26
constexpr auto normalize() const -> Selection
Normalize the selection so that start <= end.
Definition selection.h:31
SelectionPoint end
The end of the selection (inclusive)
Definition selection.h:28
constexpr friend auto tag_invoke(di::Tag< di::reflect >, di::InPlaceType< Selection >)
Definition selection.h:42
SelectionPoint start
The start of the selection.
Definition selection.h:27
constexpr auto operator==(Selection const &other) const -> bool
Definition selection.h:36