mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 18:59:59 +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++) {
|
for (int x = 0; x < size; x++) {
|
||||||
float dx = x - mx;
|
float dx = x - mx;
|
||||||
float dy = y - my;
|
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++) {
|
for (int y = 0; y < size; y++) {
|
||||||
|
@ -79,7 +79,7 @@ class ScreenInteractive : public Screen {
|
|||||||
std::atomic<bool> quit_ = false;
|
std::atomic<bool> quit_ = false;
|
||||||
std::thread event_listener_;
|
std::thread event_listener_;
|
||||||
std::thread animation_listener_;
|
std::thread animation_listener_;
|
||||||
bool animation_requested_ = true;
|
bool animation_requested_ = false;
|
||||||
animation::TimePoint previous_animation_time;
|
animation::TimePoint previous_animation_time;
|
||||||
|
|
||||||
int cursor_x_ = 1;
|
int cursor_x_ = 1;
|
||||||
|
@ -512,9 +512,9 @@ Component MenuEntry(ConstStringRef label, Ref<MenuEntryOption> option) {
|
|||||||
|
|
||||||
EntryState state = {
|
EntryState state = {
|
||||||
*label_,
|
*label_,
|
||||||
|
false,
|
||||||
hovered_,
|
hovered_,
|
||||||
focused,
|
focused,
|
||||||
false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Element element =
|
Element element =
|
||||||
|
@ -485,21 +485,19 @@ void ScreenInteractive::Main(Component component) {
|
|||||||
Clear();
|
Clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
draw();
|
bool attempt_draw = true;
|
||||||
|
|
||||||
while (!quit_) {
|
while (!quit_) {
|
||||||
if (!task_receiver_->HasPending())
|
if (attempt_draw && !task_receiver_->HasPending()) {
|
||||||
draw();
|
draw();
|
||||||
|
attempt_draw = false;
|
||||||
|
}
|
||||||
|
|
||||||
bool continue_event_loop = true;
|
|
||||||
while (continue_event_loop) {
|
|
||||||
continue_event_loop = false;
|
|
||||||
Task task;
|
Task task;
|
||||||
if (!task_receiver_->Receive(&task))
|
if (!task_receiver_->Receive(&task))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
std::visit(
|
// clang-format off
|
||||||
[&](auto&& arg) {
|
std::visit([&](auto&& arg) {
|
||||||
using T = std::decay_t<decltype(arg)>;
|
using T = std::decay_t<decltype(arg)>;
|
||||||
|
|
||||||
// Handle Event.
|
// Handle Event.
|
||||||
@ -517,6 +515,8 @@ void ScreenInteractive::Main(Component component) {
|
|||||||
|
|
||||||
arg.screen_ = this;
|
arg.screen_ = this;
|
||||||
component->OnEvent(arg);
|
component->OnEvent(arg);
|
||||||
|
attempt_draw = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle callback
|
// Handle callback
|
||||||
@ -527,10 +527,9 @@ void ScreenInteractive::Main(Component component) {
|
|||||||
|
|
||||||
// Handle Animation
|
// Handle Animation
|
||||||
if constexpr (std::is_same_v<T, AnimationTask>) {
|
if constexpr (std::is_same_v<T, AnimationTask>) {
|
||||||
if (!animation_requested_) {
|
if (!animation_requested_)
|
||||||
continue_event_loop = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
animation_requested_ = false;
|
animation_requested_ = false;
|
||||||
animation::TimePoint now = animation::Clock::now();
|
animation::TimePoint now = animation::Clock::now();
|
||||||
animation::Duration delta = now - previous_animation_time;
|
animation::Duration delta = now - previous_animation_time;
|
||||||
@ -538,10 +537,12 @@ void ScreenInteractive::Main(Component component) {
|
|||||||
|
|
||||||
animation::Params params(delta);
|
animation::Params params(delta);
|
||||||
component->OnAnimation(params);
|
component->OnAnimation(params);
|
||||||
|
attempt_draw = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
task);
|
task);
|
||||||
}
|
// clang-format on
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user