diff --git a/examples/component/canvas_animated.cpp b/examples/component/canvas_animated.cpp index 19fc33d..3b8f3b2 100644 --- a/examples/component/canvas_animated.cpp +++ b/examples/component/canvas_animated.cpp @@ -167,7 +167,7 @@ int main(int argc, const char* argv[]) { for (int x = 0; x < size; x++) { float dx = x - mx; float dy = y - my; - ys[y][x] = (int)(-1.5 + 3.0 * std::exp(-0.2f * (dx * dx + dy * dy))); + ys[y][x] = -1.5 + 3.0 * std::exp(-0.2f * (dx * dx + dy * dy)); } } for (int y = 0; y < size; y++) { diff --git a/include/ftxui/component/screen_interactive.hpp b/include/ftxui/component/screen_interactive.hpp index 333393b..ab34207 100644 --- a/include/ftxui/component/screen_interactive.hpp +++ b/include/ftxui/component/screen_interactive.hpp @@ -79,7 +79,7 @@ class ScreenInteractive : public Screen { std::atomic quit_ = false; std::thread event_listener_; std::thread animation_listener_; - bool animation_requested_ = true; + bool animation_requested_ = false; animation::TimePoint previous_animation_time; int cursor_x_ = 1; diff --git a/src/ftxui/component/menu.cpp b/src/ftxui/component/menu.cpp index cf9539d..d30191e 100644 --- a/src/ftxui/component/menu.cpp +++ b/src/ftxui/component/menu.cpp @@ -512,9 +512,9 @@ Component MenuEntry(ConstStringRef label, Ref option) { EntryState state = { *label_, + false, hovered_, focused, - false, }; Element element = diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index 37ce6a3..db9680c 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -485,63 +485,64 @@ void ScreenInteractive::Main(Component component) { Clear(); }; - draw(); - + bool attempt_draw = true; while (!quit_) { - if (!task_receiver_->HasPending()) + if (attempt_draw && !task_receiver_->HasPending()) { draw(); - - bool continue_event_loop = true; - while (continue_event_loop) { - continue_event_loop = false; - Task task; - if (!task_receiver_->Receive(&task)) - break; - - std::visit( - [&](auto&& arg) { - using T = std::decay_t; - - // Handle Event. - if constexpr (std::is_same_v) { - if (arg.is_cursor_reporting()) { - cursor_x_ = arg.cursor_x(); - cursor_y_ = arg.cursor_y(); - return; - } - - if (arg.is_mouse()) { - arg.mouse().x -= cursor_x_; - arg.mouse().y -= cursor_y_; - } - - arg.screen_ = this; - component->OnEvent(arg); - } - - // Handle callback - if constexpr (std::is_same_v) { - arg(); - return; - } - - // Handle Animation - if constexpr (std::is_same_v) { - if (!animation_requested_) { - continue_event_loop = true; - return; - } - animation_requested_ = false; - animation::TimePoint now = animation::Clock::now(); - animation::Duration delta = now - previous_animation_time; - previous_animation_time = now; - - animation::Params params(delta); - component->OnAnimation(params); - } - }, - task); + attempt_draw = false; } + + Task task; + if (!task_receiver_->Receive(&task)) + break; + + // clang-format off + std::visit([&](auto&& arg) { + using T = std::decay_t; + + // Handle Event. + if constexpr (std::is_same_v) { + if (arg.is_cursor_reporting()) { + cursor_x_ = arg.cursor_x(); + cursor_y_ = arg.cursor_y(); + return; + } + + if (arg.is_mouse()) { + arg.mouse().x -= cursor_x_; + arg.mouse().y -= cursor_y_; + } + + arg.screen_ = this; + component->OnEvent(arg); + attempt_draw = true; + return; + } + + // Handle callback + if constexpr (std::is_same_v) { + arg(); + return; + } + + // Handle Animation + if constexpr (std::is_same_v) { + if (!animation_requested_) + return; + + animation_requested_ = false; + animation::TimePoint now = animation::Clock::now(); + animation::Duration delta = now - previous_animation_time; + previous_animation_time = now; + + animation::Params params(delta); + component->OnAnimation(params); + attempt_draw = true; + return; + } + }, + task); + // clang-format on } }