Update documentation.

This commit is contained in:
ArthurSonzogni 2025-06-05 11:34:25 +02:00
parent b751e50851
commit b1e63d0221
No known key found for this signature in database
GPG Key ID: 41D98248C074CD6C
19 changed files with 177 additions and 27 deletions

View File

@ -8,11 +8,21 @@
#include <functional> // for function #include <functional> // for function
namespace ftxui::animation { namespace ftxui::animation {
// Components who haven't completed their animation can call this function to /// @brief RequestAnimationFrame is a function that requests a new frame to be
// request a new frame to be drawn later. /// drawn in the next animation cycle.
// ///
// When there is no new events and no animations to complete, no new frame is /// @note This function is typically called by components that need to
// drawn. /// update their state or appearance over time, such as animations or
/// transitions. This is useful when the change doesn't depend depend on the
/// events seen by the terminal, but rather on the passage of time.
///
/// Components who haven't completed their animation can call this function to
/// request a new frame to be drawn later.
///
/// When there is no new events and no animations to complete, no new frame is
/// drawn.
///
/// @ingroup component
void RequestAnimationFrame(); void RequestAnimationFrame();
using Clock = std::chrono::steady_clock; using Clock = std::chrono::steady_clock;

View File

@ -7,6 +7,7 @@
#include <memory> #include <memory>
namespace ftxui { namespace ftxui {
class CapturedMouseInterface { class CapturedMouseInterface {
public: public:
CapturedMouseInterface() = default; CapturedMouseInterface() = default;

View File

@ -27,6 +27,8 @@ struct EntryState {
int index; ///< Index of the entry when applicable or -1. int index; ///< Index of the entry when applicable or -1.
}; };
/// @brief Option for the underline effect.
/// @ingroup component
struct UnderlineOption { struct UnderlineOption {
bool enabled = false; bool enabled = false;
@ -230,7 +232,8 @@ struct SliderOption {
std::function<void()> on_change; ///> Called when `value` is updated. std::function<void()> on_change; ///> Called when `value` is updated.
}; };
// Parameter pack used by `WindowOptions::render`. /// @brief State passed to the `Window` component's render function.
/// @ingroup component
struct WindowRenderState { struct WindowRenderState {
Element inner; ///< The element wrapped inside this window. Element inner; ///< The element wrapped inside this window.
const std::string& title; ///< The title of the window. const std::string& title; ///< The title of the window.

View File

@ -24,6 +24,8 @@ class ComponentBase;
/// ///
/// Useful documentation about xterm specification: /// Useful documentation about xterm specification:
/// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html /// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
///
/// @ingroup component
struct Event { struct Event {
// --- Constructor section --------------------------------------------------- // --- Constructor section ---------------------------------------------------
static Event Character(std::string); static Event Character(std::string);

View File

@ -14,6 +14,45 @@ class ComponentBase;
using Component = std::shared_ptr<ComponentBase>; using Component = std::shared_ptr<ComponentBase>;
class ScreenInteractive; class ScreenInteractive;
/// @brief Loop is a class that manages the event loop for a component.
///
/// It is responsible for running the component, handling events, and
/// updating the screen.
///
/// The Loop class is designed to be used with a ScreenInteractive object,
/// which represents the terminal screen.
///
/// **Example**
/// ```cpp
/// #include <ftxui/component/component.hpp>
/// #include <ftxui/component/screen_interactive.hpp>
/// #include <ftxui/component/loop.hpp>
///
/// int main() {
/// auto screen = ftxui::ScreenInteractive::TerminalOutput();
/// auto component = ftxui::Button("Click me", [] { ... });
///
/// ftxui::Loop loop(screen.get(), component);
///
/// // Either
/// loop.Run(); // Blocking until the component quits.
///
/// // Or
/// loop.RunOnce(); // Non-blocking, returns immediately.
///
/// // Or
/// loop.RunOnceBlocking(); // Blocking until handling one event.
///
/// // Or in a loop:
/// while (!loop.HasQuitted()) {
/// loop.RunOnce();
///
/// // Do something else like running a different library loop function.
/// }
/// }
/// ```
///
/// @ingroup component
class Loop { class Loop {
public: public:
Loop(ScreenInteractive* screen, Component component); Loop(ScreenInteractive* screen, Component component);

View File

@ -27,6 +27,10 @@ struct Event;
using Component = std::shared_ptr<ComponentBase>; using Component = std::shared_ptr<ComponentBase>;
class ScreenInteractivePrivate; class ScreenInteractivePrivate;
/// @brief ScreenInteractive is a `Screen` that can handle events, run a main
/// loop, and manage components.
///
/// @ingroup component
class ScreenInteractive : public Screen { class ScreenInteractive : public Screen {
public: public:
// Constructors: // Constructors:

View File

@ -20,6 +20,21 @@
namespace ftxui { namespace ftxui {
/// @brief Canvas is a drawable buffer associated with drawing operations.
///
/// Canvas is a drawable area that can be used to create complex graphics. It
/// supports drawing points, lines, circles, ellipses, text, and images using
/// braille, block, or normal characters.
///
/// Note: A terminal contains cells. A cells is a unit of:
/// - 2x4 braille characters (1x1 pixel)
/// - 2x2 block characters (2x2 pixels)
/// - 2x4 normal characters (2x4 pixels)
///
/// You need to multiply the x coordinate by 2 and the y coordinate by 4 to
/// get the correct position in the terminal.
///
/// @ingroup dom
struct Canvas { struct Canvas {
public: public:
Canvas() = default; Canvas() = default;

View File

@ -5,6 +5,11 @@
#define FTXUI_DOM_DIRECTION_HPP #define FTXUI_DOM_DIRECTION_HPP
namespace ftxui { namespace ftxui {
/// @brief Direction is an enumeration that represents the four cardinal
/// directions.
///
/// @ingroup dom
enum class Direction { enum class Direction {
Up = 0, Up = 0,
Down = 1, Down = 1,

View File

@ -24,6 +24,14 @@ using Elements = std::vector<Element>;
using Decorator = std::function<Element(Element)>; using Decorator = std::function<Element(Element)>;
using GraphFunction = std::function<std::vector<int>(int, int)>; using GraphFunction = std::function<std::vector<int>(int, int)>;
/// @brief BorderStyle is an enumeration that represents the different styles
/// of borders that can be applied to elements in the terminal UI.
///
/// BorderStyle is an enumeration that represents the different styles of
/// borders that can be applied to elements in the terminal UI.
/// It is used to define the visual appearance of borders around elements,
/// such as windows, frames, or separators.
/// @ingroup dom
enum BorderStyle { enum BorderStyle {
LIGHT, LIGHT,
DASHED, DASHED,

View File

@ -12,6 +12,19 @@
namespace ftxui { namespace ftxui {
/// @brief FlexboxConfig is a configuration structure that defines the layout
/// properties for a flexbox container.
//
/// It allows you to specify the direction of the flex items, whether they
/// should wrap, how they should be justified along the main axis, and how
/// they should be aligned along the cross axis.
/// It also includes properties for gaps between flex items in both the
/// main and cross axes.
/// This structure is used to configure the layout behavior of flexbox
/// containers in a terminal user interface.
///
/// @ingroup dom
struct FlexboxConfig { struct FlexboxConfig {
/// This establishes the main-axis, thus defining the direction flex items are /// This establishes the main-axis, thus defining the direction flex items are
/// placed in the flex container. Flexbox is (aside wrapping) single-direction /// placed in the flex container. Flexbox is (aside wrapping) single-direction

View File

@ -27,8 +27,15 @@ namespace ftxui {
/// LinearGradient(Color::Red, Color::Blue); /// LinearGradient(Color::Red, Color::Blue);
/// LinearGradient(45, Color::Red, Color::Blue); /// LinearGradient(45, Color::Red, Color::Blue);
/// ``` /// ```
///
/// @ingroup dom
struct LinearGradient { struct LinearGradient {
float angle = 0.f; float angle = 0.f;
/// A stop is a color at a specific position in the gradient.
/// The position is a value between 0.0 and 1.0,
/// where 0.0 is the start of the gradient
/// and 1.0 is the end of the gradient.
struct Stop { struct Stop {
Color color = Color::Default; Color color = Color::Default;
std::optional<float> position; std::optional<float> position;

View File

@ -20,6 +20,20 @@ class Screen;
using Element = std::shared_ptr<Node>; using Element = std::shared_ptr<Node>;
using Elements = std::vector<Element>; using Elements = std::vector<Element>;
/// @brief Node is the base class for all elements in the DOM tree.
///
/// It represents a single node in the document object model (DOM) and provides
/// the basic structure for layout and rendering.
/// It contains methods for computing layout requirements, setting the box
/// dimensions, selecting content, rendering to the screen, and checking the
/// layout status.
/// It typically contains child elements, which are also instances of Node.
///
/// Users are expected to derive from this class to create custom elements.
///
/// A list of builtin elements can be found in the `elements.hpp` file.
///
/// @ingroup dom
class Node { class Node {
public: public:
Node(); Node();

View File

@ -10,6 +10,11 @@
namespace ftxui { namespace ftxui {
class Node; class Node;
/// @brief Requirement is a structure that defines the layout requirements for a
/// Node in the terminal user interface.
///
/// It specifies the minimum size required to fully draw the element,
/// @ingroup dom
struct Requirement { struct Requirement {
// The required size to fully draw the element. // The required size to fully draw the element.
int min_x = 0; int min_x = 0;

View File

@ -13,7 +13,12 @@
namespace ftxui { namespace ftxui {
/// @brief Represent a selection in the terminal. /// @brief Represents a selection in a terminal user interface.
///
/// Selection is a class that represents the two endpoints of a selection in a
/// terminal user interface.
///
/// @ingroup dom
class Selection { class Selection {
public: public:
Selection(); // Empty selection. Selection(); // Empty selection.

View File

@ -11,28 +11,28 @@
namespace ftxui { namespace ftxui {
// Usage:
//
// Initialization:
// ---------------
//
// auto table = Table({
// {"X", "Y"},
// {"-1", "1"},
// {"+0", "0"},
// {"+1", "1"},
// });
//
// table.SelectAll().Border(LIGHT);
//
// table.SelectRow(1).Border(DOUBLE);
// table.SelectRow(1).SeparatorInternal(Light);
//
// std::move(table).Element();
class Table; class Table;
class TableSelection; class TableSelection;
/// @brief Table is a utility to draw tables.
///
/// **example**
/// ```cpp
/// auto table = Table({
/// {"X", "Y"},
/// {"-1", "1"},
/// {"+0", "0"},
/// {"+1", "1"},
/// });
///
/// table.SelectAll().Border(LIGHT);
/// table.SelectRow(1).Border(DOUBLE);
/// table.SelectRow(1).SeparatorInternal(LIGHT);
///
/// std::move(table).Render();
/// ```
///
/// @ingroup dom
class Table { class Table {
public: public:
Table(); Table();

View File

@ -6,6 +6,13 @@
namespace ftxui { namespace ftxui {
/// @brief Box is a structure that represents a rectangular area in a 2D space.
///
/// It is defined by its minimum and maximum coordinates along the x and y axes.
/// Note that the coordinates are inclusive, meaning that the box includes both
/// the minimum and maximum values.
///
/// @ingroup screen
struct Box { struct Box {
int x_min = 0; int x_min = 0;
int x_max = 0; int x_max = 0;

View File

@ -15,7 +15,9 @@
namespace ftxui { namespace ftxui {
/// @brief A class representing terminal colors. /// @brief Color is a class that represents a color in the terminal user
/// interface.
///
/// @ingroup screen /// @ingroup screen
class Color { class Color {
public: public:

View File

@ -9,6 +9,10 @@
namespace ftxui { namespace ftxui {
/// @brief ColorInfo is a structure that contains information about the terminal
/// color palette.
///
/// @ingroup screen
struct ColorInfo { struct ColorInfo {
const char* name; const char* name;
uint8_t index_256; uint8_t index_256;

View File

@ -5,6 +5,9 @@
#define FTXUI_SCREEN_TERMINAL_HPP #define FTXUI_SCREEN_TERMINAL_HPP
namespace ftxui { namespace ftxui {
/// @brief Dimensions is a structure that represents the size of the terminal
/// @ingroup screen
struct Dimensions { struct Dimensions {
int dimx; int dimx;
int dimy; int dimy;
@ -14,6 +17,9 @@ namespace Terminal {
Dimensions Size(); Dimensions Size();
void SetFallbackSize(const Dimensions& fallbackSize); void SetFallbackSize(const Dimensions& fallbackSize);
/// @brief Color is an enumeration that represents the color support of the
/// terminal.
/// @ingroup screen
enum Color { enum Color {
Palette1, Palette1,
Palette16, Palette16,