# FTXUI: loop.hpp Source File

Loading...
Searching...
No Matches
loop.hpp
Go to the documentation of this file.
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#ifndef FTXUI_COMPONENT_LOOP_HPP
#define FTXUI_COMPONENT_LOOP_HPP
#include <memory> // for shared_ptr
#include "ftxui/component/component_base.hpp" // for ComponentBase
namespace ftxui {
class ComponentBase;
using Component = std::shared_ptr<ComponentBase>;
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 {
public:
Loop(ScreenInteractive* screen, Component component);
~Loop();
bool HasQuitted();
void RunOnce();
void RunOnceBlocking();
void Run();
// This class is non copyable/movable.
Loop(const Loop&) = default;
Loop(Loop&&) = delete;
Loop& operator=(Loop&&) = delete;
Loop(const ScreenInteractive&) = delete;
Loop& operator=(const Loop&) = delete;
private:
ScreenInteractive* screen_;
Component component_;
};
} // namespace ftxui
#endif // FTXUI_COMPONENT_LOOP_HPP
component_base.hpp
ftxui::Loop::HasQuitted
bool HasQuitted()
Whether the loop has quitted.
Definition loop.cpp:30
ftxui::Loop::Loop
Loop(const ScreenInteractive &)=delete
ftxui::Loop::~Loop
~Loop()
Definition loop.cpp:25
ftxui::Loop::Run
void Run()
Definition loop.cpp:49
ftxui::Loop::Loop
Loop(ScreenInteractive *screen, Component component)
A Loop is a wrapper around a Component and a ScreenInteractive. It is used to run a Component in a te...
Definition loop.cpp:20
ftxui::Loop::operator=
Loop & operator=(const Loop &)=delete
ftxui::Loop::RunOnce
void RunOnce()
Execute the loop. Make the component to process every pending tasks/events. A new frame might be draw...
Definition loop.cpp:37
ftxui::Loop::Loop
Loop(const Loop &)=default
ftxui::Loop::operator=
Loop & operator=(Loop &&)=delete
ftxui::Loop::Loop
Loop(Loop &&)=delete
ftxui::Loop::RunOnceBlocking
void RunOnceBlocking()
Wait for at least one event to be handled and execute Loop::RunOnce().
Definition loop.cpp:43
ftxui::Loop
Loop is a class that manages the event loop for a component.
Definition loop.hpp:56
ftxui::ScreenInteractive
ScreenInteractive is a Screen that can handle events, run a main loop, and manage components.
Definition screen_interactive.hpp:35
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
ftxui::Component
std::shared_ptr< ComponentBase > Component
Definition component_base.hpp:24