FTXUI
6.1.9
C++ functional terminal UI.
Toggle main menu visibility
Loading...
Searching...
No Matches
focus.cpp
Go to the documentation of this file.
1
// Copyright 2020 Arthur Sonzogni. All rights reserved.
2
// Use of this source code is governed by the MIT license that can be found in
3
// the LICENSE file.
4
#include <memory>
// for make_shared
5
#include <utility>
// for move
6
7
#include "
ftxui/dom/elements.hpp
"
// for Decorator, Element, focusPosition, focusPositionRelative
8
#include "
ftxui/dom/node_decorator.hpp
"
// for NodeDecorator
9
#include "
ftxui/dom/requirement.hpp
"
// for Requirement, Requirement::NORMAL, Requirement::Selection
10
#include "
ftxui/screen/box.hpp
"
// for Box
11
12
namespace
ftxui
{
13
14
/// @brief Used inside a `frame`, this force the view to be scrolled toward a
15
/// a given position. The position is expressed in proportion of the requested
16
/// size.
17
///
18
/// For instance:
19
/// - (0, 0) means that the view is scrolled toward the upper left.
20
/// - (1, 0) means that the view is scrolled toward the upper right.
21
/// - (0, 1) means that the view is scrolled toward the bottom left.
22
/// @ingroup dom
23
///
24
/// ### Example
25
///
26
/// ```cpp
27
/// Element document = huge_document()
28
/// | focusPositionRelative(0.f, 1.f)
29
/// | frame;
30
/// ```
31
Decorator
focusPositionRelative
(
float
x,
float
y) {
32
class
Impl :
public
NodeDecorator
{
33
public
:
34
Impl(
Element
child,
float
x,
float
y)
35
:
NodeDecorator
(std::move(child)), x_(x), y_(y) {}
36
37
void
ComputeRequirement()
override
{
38
NodeDecorator::ComputeRequirement
();
39
requirement_.focused.enabled =
true
;
40
requirement_.focused.node =
this
;
41
requirement_.focused.box.x_min = int(
float
(requirement_.min_x) * x_);
42
requirement_.focused.box.y_min = int(
float
(requirement_.min_y) * y_);
43
requirement_.focused.box.x_max = int(
float
(requirement_.min_x) * x_);
44
requirement_.focused.box.y_max = int(
float
(requirement_.min_y) * y_);
45
}
46
47
private
:
48
const
float
x_;
49
const
float
y_;
50
};
51
52
return
[x, y](
Element
child) {
53
return
std::make_shared<Impl>(std::move(child), x, y);
54
};
55
}
56
57
/// @brief Used inside a `frame`, this force the view to be scrolled toward a
58
/// a given position. The position is expressed in the numbers of cells.
59
///
60
/// @ingroup dom
61
///
62
/// ### Example
63
///
64
/// ```cpp
65
/// Element document = huge_document()
66
/// | focusPosition(10, 10)
67
/// | frame;
68
/// ```
69
Decorator
focusPosition
(
int
x,
int
y) {
70
class
Impl :
public
NodeDecorator
{
71
public
:
72
Impl(
Element
child,
int
x,
int
y)
73
:
NodeDecorator
(std::move(child)), x_(x), y_(y) {}
74
75
void
ComputeRequirement()
override
{
76
NodeDecorator::ComputeRequirement
();
77
requirement_.focused.enabled =
false
;
78
79
Box
& box = requirement_.focused.box;
80
box.
x_min
= x_;
81
box.
y_min
= y_;
82
box.
x_max
= x_;
83
box.
y_max
= y_;
84
}
85
86
private
:
87
const
int
x_;
88
const
int
y_;
89
};
90
91
return
[x, y](
Element
child) {
92
return
std::make_shared<Impl>(std::move(child), x, y);
93
};
94
}
95
96
}
// namespace ftxui
box.hpp
ftxui::NodeDecorator
Definition
node_decorator.hpp:16
ftxui::NodeDecorator::ComputeRequirement
void ComputeRequirement() override
Compute how much space an elements needs.
Definition
node_decorator.cpp:12
elements.hpp
ftxui
Definition
animation.hpp:10
ftxui::focusPositionRelative
Decorator focusPositionRelative(float x, float y)
Used inside a frame, this force the view to be scrolled toward a a given position....
Definition
focus.cpp:31
ftxui::Decorator
std::function< Element(Element)> Decorator
Definition
elements.hpp:24
ftxui::Element
std::shared_ptr< Node > Element
Definition
elements.hpp:22
ftxui::focusPosition
Decorator focusPosition(int x, int y)
Used inside a frame, this force the view to be scrolled toward a a given position....
Definition
focus.cpp:69
node_decorator.hpp
requirement.hpp
ftxui::Box
Definition
box.hpp:9
ftxui::Box::x_max
int x_max
Definition
box.hpp:11
ftxui::Box::y_min
int y_min
Definition
box.hpp:12
ftxui::Box::y_max
int y_max
Definition
box.hpp:13
ftxui::Box::x_min
int x_min
Definition
box.hpp:10