Skip to content
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

Canvas is not full screen when using ScreenInteractive #997

Open
niosus opened this issue Feb 2, 2025 · 1 comment
Open

Canvas is not full screen when using ScreenInteractive #997

niosus opened this issue Feb 2, 2025 · 1 comment

Comments

@niosus
Copy link
Contributor

niosus commented Feb 2, 2025

I might be doing something completely wrong but I am breaking my brain on this for a while now.

I'm trying to create a single full-screen canvas so that I could draw into it at any point in the terminal. I expect that when I create a ftxui::ScreenInteractive::Fullscreen() interactive screen, it should initialize its size to the full size of the terminal, which, I believe it doesn't. Then, when I create a canvas it is initialized to an even smaller size, so that I can effectively draw in only part of the screen.

It feels like the task should be fairly simple, so I wonder what I might be doing wrong here. The code I use to test this out is below:

#include <ftxui/component/screen_interactive.hpp>
#include <ftxui/screen/string.hpp>
#include <string>

#include "ftxui/component/component.hpp"
#include "ftxui/component/event.hpp"
#include "ftxui/component/loop.hpp"
#include "ftxui/dom/elements.hpp"
#include "ftxui/screen/color.hpp"

namespace {
const ftxui::Color kYellowishColor = ftxui::Color::RGB(255, 200, 100);
}

int main() {
  auto screen = ftxui::ScreenInteractive::Fullscreen();

  int x{};
  int y{};

  auto component = ftxui::Renderer([&] {
    auto c = ftxui::Canvas{screen.dimx(), screen.dimy()};
    c.DrawBlock(x, y, true, kYellowishColor);
    c.DrawBlock(x + 1, y, true, kYellowishColor);
    return ftxui::vbox(
        {ftxui::hbox({ftxui::text("canvas: " + std::to_string(screen.dimx()) +
                                  " " + std::to_string(screen.dimy())),
                      ftxui::separator(),
                      ftxui::text("pos: " + std::to_string(x) + " " +
                                  std::to_string(y))}),
         ftxui::canvas(std::move(c))});
  });

  component |= ftxui::CatchEvent([&](ftxui::Event event) {
    if (event.is_character()) {
      if (event.character()[0] == 'q') { screen.Exit(); }
    }
    if (event == ftxui::Event::ArrowRight) { x += 2; }
    if (event == ftxui::Event::ArrowLeft) { x -= 2; }
    if (event == ftxui::Event::ArrowDown) { y++; }
    if (event == ftxui::Event::ArrowUp) { y--; }
    return true;
  });

  ftxui::Loop loop{&screen, component};
  while (!loop.HasQuitted()) {
    loop.RunOnce();
    std::this_thread::sleep_for(std::chrono::milliseconds(10));
  }

  return EXIT_SUCCESS;
}
@niosus niosus changed the title ftxui::ScreenInteractive::Fullscreen and ftxui::Canvas do not render a full screen canvas ftxui::Canvas is not full screen when using ScreenInteractive Feb 3, 2025
@niosus niosus changed the title ftxui::Canvas is not full screen when using ScreenInteractive Canvas is not full screen when using ScreenInteractive Feb 3, 2025
@niosus
Copy link
Contributor Author

niosus commented Feb 3, 2025

This is probably related to #344
But the question for me remains of how I could create a canvas that fits the size of the current terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant