Skip to content

[dependencies] Add support for ftxui 6.0.0. #2095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

KerstinKeller
Copy link
Contributor

ftxui has released a new major version.
This branch tries to ensure compatibility with the new release and all older releases.

Todo: It seems that 6.0.0 breaks the ability to select an item from the list of topics. This needs to be investigated.
image
(background ftxui 6.0.0, foreground ftxui 5.0.0 - the elements are no longer selectable).

(This PR does not update the submodule, so the current build is still using 5.0.0)

@brakmic-aleksandar There is no chance that you might quickly look into this? I am not quite sure where to start.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@hannemn hannemn added cherry-pick-to-NONE Don't cherry-pick these changes cherry-pick-to-support/v5.13 Cherry pick these changes to support/v5.13 and removed cherry-pick-to-NONE Don't cherry-pick these changes labels Mar 28, 2025
@ArthurSonzogni
Copy link

Some context about why Render is now split into OnRender (users) and Render (ftxui) side.

Context I had to split this function in two:

  • Render controlled by FTXUI.
  • OnRender controlled by the users.

Render() allows me to tag element as "active" or "inactive" depending on the Component state. This allows to select the focused element in a hiearchical manner. This replaces the previous focus/select decorator where only a 2-level global focus was previously applied.

See Render implementation

@KerstinKeller
Copy link
Contributor Author

@ArthurSonzogni I did just what you explained, however, it leads to a different behavior and the app is broken for ftxui 6.0.0. I can no longer select elements from the list in the given application.
As I am not the author of the code, I don't fully grasp the concept. However, from what I have seen, OnRender of some components call Render of other components, see

#if FTXUI_VERSION_MAJOR >= 6
Element OnRender() final
#else
Element Render() final
#endif
{
auto focused = Focused() ? focus : ftxui::select;
auto style = Focused() ? inverted : nothing;
Element background = ComponentBase::Render();
background->ComputeRequirement();
size_ = background->requirement().min_y;
auto el = dbox({
std::move(background),
vbox({
text(L"") | size(HEIGHT, EQUAL, selected_),
text(L"") | style | focused,
}),
}) |
vscroll_indicator | yframe | yflex | reflect(box_);
return el;
}

Is this allowed?
From quickly looking through the code, it was the first thing that stuck out.

@@ -108,7 +108,11 @@ class CommandLineView : public View
return true;
}

#if FTXUI_VERSION_MAJOR >= 6

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about introducing some helper macro?

// Usage:
// FTXUI_RENDER() override {
//   using namespace ftxui;
//   return text("Hello, world!") | border;
// }
#if FTXUI_VERSION_MAJOR >= 6
#define FTXUI_RENDER() ftxui::Element OnRender()
#else
#define FTXUI_RENDER() ftxui::Element Render()
#endif

Element Render() final
#endif
{
auto focused = Focused() ? focus : ftxui::select;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that with ftxui 6.0.0, focus and select are now alias of each others. You don't need to make it conditional on Focused() anymore and it should work select the focused element of the active component automatically.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said, you can keep it if you want to keep 5.0.0 compatibility.

Element Render() final
#endif
{
auto focused = Focused() ? focus : ftxui::select;
auto style = Focused() ? inverted : nothing;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    Element background = ComponentBase::Render();

must be:

    Element background = ComponentBase::OnRender();

Or else the background won't be focused when active.

KerstinKeller and others added 2 commits April 9, 2025 15:38
Todo: It seems that 6.0.0 breaks the ability to select an item from the list of topics. This needs to be investigated.
@KerstinKeller
Copy link
Contributor Author

@ArthurSonzogni I had made the changes that you suggested, however, the problem I described on top remains.
Basically I have some kind of list, where one element should be selected, and then additional information for that element is to be displayed.
Updating ftxui to 6.0 breaks this functionality.

Since I haven't authored the code, I have a hard time locating the source of the issue. Maybe the element of choice is no longer selected correctly (regarding the "focused" issue?)

Anything I can pay attention to in particular?

@ArthurSonzogni
Copy link

I would be happy to debug this. The problem is that the last time I tried, there was too many obstacle to build the project.

If you can provide some instructions for me to try, I will figure this out.

@KerstinKeller
Copy link
Contributor Author

So in general, it should not be too difficult to build.
You will need a fairly recent CMake version (>3.25) and clone the repo including submodules (recursively), from this branch (feature/update-ftxui-6). Alternatively you can download the fat sources archive from the github actions (https://github.com/eclipse-ecal/ecal/actions/runs/14757653830/artifacts/3038617643)

You don't need to build everything, i'd recommend samples & console apps (no gui), so you will have mon_tui and some samples (ecal_sample_person_send, ecal_sample_blob_send) to test with.

However, since I just tried a complete clean rebuild with which I though were good options for you, and failed, this might have to wait a little longer :/

I will let you know! And thanks so much for offering to help.

ArthurSonzogni added a commit to ArthurSonzogni/FTXUI that referenced this pull request May 2, 2025
@ArthurSonzogni
Copy link

I found the issue.

This is due to how the dbox has been updated in:
ArthurSonzogni/FTXUI@ff30514

In order to support color alpha and "blend" the bgcolor of the top layer on top of the layers below, we blend its bgcolor. Outside of those, we replace everything including the modifier like inverted as long as the top layer contains a non empty character.

In your case the "scroller" is implemented by adding an inverted empty line. Since this is empty, this has no effect.

What you can do:

  1. Copy-paste the dbox implementation from ftxui5 and use it.
  2. Try to set a black background and use an transparent bgcolor on the selected line. Example:
test-2025-05-01_17.02.29.mp4
  1. I reverted the change to dbox. I think I would have liked to use a differement name to avoid breaking users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-to-support/v5.13 Cherry pick these changes to support/v5.13
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants