Skip to content

Commit

Permalink
Add documentations to every public functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurSonzogni committed Aug 19, 2023
1 parent 5724f84 commit 49a4882
Show file tree
Hide file tree
Showing 32 changed files with 396 additions and 48 deletions.
66 changes: 58 additions & 8 deletions src/ftxui/component/component_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,65 @@

namespace ftxui {

void AnimatedColorOption::Set(Color a_inactive,
Color a_active,
animation::Duration a_duration,
animation::easing::Function a_function) {
/// @brief A color option that can be animated.
/// @params _inactive The color when the component is inactive.
/// @params _active The color when the component is active.
/// @params _duration The duration of the animation.
/// @params _function The easing function of the animation.
/// @ingroup component
void AnimatedColorOption::Set(Color _inactive,
Color _active,
animation::Duration _duration,
animation::easing::Function _function) {
enabled = true;
inactive = a_inactive;
active = a_active;
duration = a_duration;
function = std::move(a_function);
inactive = _inactive;
active = _active;
duration = _duration;
function = std::move(_function);
}

/// @brief Set how the underline should animate.
/// @param d The duration of the animation.
/// @param f The easing function of the animation.
/// @ingroup component
void UnderlineOption::SetAnimation(animation::Duration d,
animation::easing::Function f) {
SetAnimationDuration(d);
SetAnimationFunction(std::move(f));
}

/// @brief Set how the underline should animate.
/// @param d The duration of the animation.
/// @ingroup component
void UnderlineOption::SetAnimationDuration(animation::Duration d) {
leader_duration = d;
follower_duration = d;
}

/// @brief Set how the underline should animate.
/// @param f The easing function of the animation.
/// @ingroup component
void UnderlineOption::SetAnimationFunction(animation::easing::Function f) {
leader_function = f;
follower_function = std::move(f);
}

/// @brief Set how the underline should animate.
/// This is useful to desynchronize the animation of the leader and the
/// follower.
/// @param f_leader The duration of the animation for the leader.
/// @param f_follower The duration of the animation for the follower.
/// @ingroup component
void UnderlineOption::SetAnimationFunction(
animation::easing::Function f_leader,
animation::easing::Function f_follower) {
leader_function = std::move(f_leader);
follower_function = std::move(f_follower);
}

/// @brief Standard options for an horizontal menu.
/// This can be useful to implement a tab bar.
/// @ingroup component
// static
MenuOption MenuOption::Horizontal() {
MenuOption option;
Expand All @@ -69,13 +94,19 @@ MenuOption MenuOption::Horizontal() {
return option;
}

/// @brief Standard options for an animated horizontal menu.
/// This can be useful to implement a tab bar.
/// @ingroup component
// static
MenuOption MenuOption::HorizontalAnimated() {
auto option = Horizontal();
option.underline.enabled = true;
return option;
}

/// @brief Standard options for a vertical menu.
/// This can be useful to implement a list of selectable items.
/// @ingroup component
// static
MenuOption MenuOption::Vertical() {
MenuOption option;
Expand All @@ -95,6 +126,9 @@ MenuOption MenuOption::Vertical() {
return option;
}

/// @brief Standard options for an animated vertical menu.
/// This can be useful to implement a list of selectable items.
/// @ingroup component
// static
MenuOption MenuOption::VerticalAnimated() {
auto option = MenuOption::Vertical();
Expand All @@ -115,6 +149,9 @@ MenuOption MenuOption::VerticalAnimated() {
return option;
}

/// @brief Standard options for a horitontal menu with some separator.
/// This can be useful to implement a tab bar.
/// @ingroup component
// static
MenuOption MenuOption::Toggle() {
auto option = MenuOption::Horizontal();
Expand All @@ -123,6 +160,7 @@ MenuOption MenuOption::Toggle() {
}

/// @brief Create a ButtonOption, highlighted using [] characters.
/// @ingroup component
// static
ButtonOption ButtonOption::Ascii() {
ButtonOption option;
Expand All @@ -135,6 +173,7 @@ ButtonOption ButtonOption::Ascii() {
}

/// @brief Create a ButtonOption, inverted when focused.
/// @ingroup component
// static
ButtonOption ButtonOption::Simple() {
ButtonOption option;
Expand All @@ -150,6 +189,7 @@ ButtonOption ButtonOption::Simple() {

/// @brief Create a ButtonOption. The button is shown using a border, inverted
/// when focused. This is the current default.
/// @ingroup component
ButtonOption ButtonOption::Border() {
ButtonOption option;
option.transform = [](const EntryState& s) {
Expand All @@ -166,13 +206,15 @@ ButtonOption ButtonOption::Border() {
}

/// @brief Create a ButtonOption, using animated colors.
/// @ingroup component
// static
ButtonOption ButtonOption::Animated() {
return Animated(Color::Black, Color::GrayLight, //
Color::GrayDark, Color::White);
}

/// @brief Create a ButtonOption, using animated colors.
/// @ingroup component
// static
ButtonOption ButtonOption::Animated(Color color) {
return ButtonOption::Animated(
Expand All @@ -183,6 +225,7 @@ ButtonOption ButtonOption::Animated(Color color) {
}

/// @brief Create a ButtonOption, using animated colors.
/// @ingroup component
// static
ButtonOption ButtonOption::Animated(Color background, Color foreground) {
// NOLINTBEGIN
Expand All @@ -195,6 +238,7 @@ ButtonOption ButtonOption::Animated(Color background, Color foreground) {
}

/// @brief Create a ButtonOption, using animated colors.
/// @ingroup component
// static
ButtonOption ButtonOption::Animated(Color background,
Color foreground,
Expand All @@ -214,6 +258,7 @@ ButtonOption ButtonOption::Animated(Color background,
}

/// @brief Option for standard Checkbox.
/// @ingroup component
// static
CheckboxOption CheckboxOption::Simple() {
auto option = CheckboxOption();
Expand All @@ -238,6 +283,7 @@ CheckboxOption CheckboxOption::Simple() {
}

/// @brief Option for standard Radiobox
/// @ingroup component
// static
RadioboxOption RadioboxOption::Simple() {
auto option = RadioboxOption();
Expand All @@ -261,6 +307,8 @@ RadioboxOption RadioboxOption::Simple() {
return option;
}

/// @brief Standard options for the input component.
/// @ingroup component
// static
InputOption InputOption::Default() {
InputOption option;
Expand All @@ -282,6 +330,8 @@ InputOption InputOption::Default() {
return option;
}

/// @brief Standard options for a more beautiful input component.
/// @ingroup component
// static
InputOption InputOption::Spacious() {
InputOption option;
Expand Down
4 changes: 4 additions & 0 deletions src/ftxui/component/dropdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

namespace ftxui {

/// @brief A dropdown menu.
/// @ingroup component
/// @param entries The list of entries to display.
/// @param selected The index of the selected entry.
Component Dropdown(ConstStringListRef entries, int* selected) {
class Impl : public ComponentBase {
public:
Expand Down
17 changes: 17 additions & 0 deletions src/ftxui/component/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace ftxui {

/// @brief An event corresponding to a given typed character.
/// @param input The character typed by the user.
/// @ingroup component
// static
Event Event::Character(std::string input) {
Event event;
Expand All @@ -17,16 +20,26 @@ Event Event::Character(std::string input) {
return event;
}

/// @brief An event corresponding to a given typed character.
/// @param c The character typed by the user.
/// @ingroup component
// static
Event Event::Character(char c) {
return Event::Character(std::string{c});
}

/// @brief An event corresponding to a given typed character.
/// @param c The character typed by the user.
/// @ingroup component
// static
Event Event::Character(wchar_t c) {
return Event::Character(to_string(std::wstring{c}));
}

/// @brief An event corresponding to a given typed character.
/// @param input The sequence of character send by the terminal.
/// @param mouse The mouse state.
/// @ingroup component
// static
Event Event::Mouse(std::string input, struct Mouse mouse) {
Event event;
Expand All @@ -36,13 +49,17 @@ Event Event::Mouse(std::string input, struct Mouse mouse) {
return event;
}

/// @brief An custom event whose meaning is defined by the user of the library.
/// @param input An arbitrary sequence of character defined by the developer.
/// @ingroup component.
// static
Event Event::Special(std::string input) {
Event event;
event.input_ = std::move(input);
return event;
}

/// @internal
// static
Event Event::CursorReporting(std::string input, int x, int y) {
Event event;
Expand Down
10 changes: 10 additions & 0 deletions src/ftxui/component/loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@

namespace ftxui {

/// @brief A Loop is a wrapper around a Component and a ScreenInteractive.
/// It is used to run a Component in a terminal.
/// @ingroup component
/// @see Component, ScreenInteractive.
/// @see ScreenInteractive::Loop().
/// @see ScreenInteractive::ExitLoop().
/// @param screen The screen to use.
/// @param component The component to run.
// NOLINTNEXTLINE
Loop::Loop(ScreenInteractive* screen, Component component)
: screen_(screen), component_(std::move(component)) {
Expand All @@ -19,6 +27,8 @@ Loop::~Loop() {
screen_->PostMain();
}

/// @brief Whether the loop has quitted.
/// @ingroup component
bool Loop::HasQuitted() {
return screen_->HasQuitted();
}
Expand Down
7 changes: 6 additions & 1 deletion src/ftxui/component/maybe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

namespace ftxui {

/// @brief Decorate a component |child|. It is shown only when |show| returns
/// true.
/// @param child the compoenent to decorate.
/// @param show a function returning whether |child| should shown.
/// @ingroup component
Component Maybe(Component child, std::function<bool()> show) {
class Impl : public ComponentBase {
public:
Expand All @@ -40,7 +45,7 @@ Component Maybe(Component child, std::function<bool()> show) {

/// @brief Decorate a component. It is shown only when the |show| function
/// returns true.
/// @param show a function returning whether the decoratorated component should
/// @param show a function returning whether the decorated component should
/// be shown.
/// @ingroup component
///
Expand Down
Loading

0 comments on commit 49a4882

Please sign in to comment.