mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 10:40:00 +08:00
Bug fixes. (#367)
- Do not draw more frames than what is needed. - Fix MenuEntry transform state. - Fix Canvas animated example.
This commit is contained in:
parent
548fa51b71
commit
62fb6298be
@ -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++) {
|
||||
|
@ -79,7 +79,7 @@ class ScreenInteractive : public Screen {
|
||||
std::atomic<bool> 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;
|
||||
|
@ -512,9 +512,9 @@ Component MenuEntry(ConstStringRef label, Ref<MenuEntryOption> option) {
|
||||
|
||||
EntryState state = {
|
||||
*label_,
|
||||
false,
|
||||
hovered_,
|
||||
focused,
|
||||
false,
|
||||
};
|
||||
|
||||
Element element =
|
||||
|
@ -485,21 +485,19 @@ void ScreenInteractive::Main(Component component) {
|
||||
Clear();
|
||||
};
|
||||
|
||||
draw();
|
||||
|
||||
bool attempt_draw = true;
|
||||
while (!quit_) {
|
||||
if (!task_receiver_->HasPending())
|
||||
if (attempt_draw && !task_receiver_->HasPending()) {
|
||||
draw();
|
||||
attempt_draw = false;
|
||||
}
|
||||
|
||||
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) {
|
||||
// clang-format off
|
||||
std::visit([&](auto&& arg) {
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
|
||||
// Handle Event.
|
||||
@ -517,6 +515,8 @@ void ScreenInteractive::Main(Component component) {
|
||||
|
||||
arg.screen_ = this;
|
||||
component->OnEvent(arg);
|
||||
attempt_draw = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle callback
|
||||
@ -527,10 +527,9 @@ void ScreenInteractive::Main(Component component) {
|
||||
|
||||
// Handle Animation
|
||||
if constexpr (std::is_same_v<T, AnimationTask>) {
|
||||
if (!animation_requested_) {
|
||||
continue_event_loop = true;
|
||||
if (!animation_requested_)
|
||||
return;
|
||||
}
|
||||
|
||||
animation_requested_ = false;
|
||||
animation::TimePoint now = animation::Clock::now();
|
||||
animation::Duration delta = now - previous_animation_time;
|
||||
@ -538,10 +537,12 @@ void ScreenInteractive::Main(Component component) {
|
||||
|
||||
animation::Params params(delta);
|
||||
component->OnAnimation(params);
|
||||
attempt_draw = true;
|
||||
return;
|
||||
}
|
||||
},
|
||||
task);
|
||||
}
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user