mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-25 12:11:33 +08:00
Refactor and bug fix: Wrong vbox height.
This commit is contained in:
parent
e6614d6363
commit
cf63aefa02
@ -25,8 +25,7 @@ class ScreenInteractive : public ftxui::screen::Screen {
|
||||
class Delegate;
|
||||
std::unique_ptr<Delegate> delegate_;
|
||||
|
||||
void Clear();
|
||||
void Draw();
|
||||
void PrepareDraw();
|
||||
bool quit_ = false;
|
||||
|
||||
enum class Dimension {
|
||||
|
@ -127,21 +127,20 @@ void ScreenInteractive::Loop() {
|
||||
terminal_configuration_new.c_lflag &= ~ECHO;
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &terminal_configuration_new);
|
||||
|
||||
Draw();
|
||||
std::string reset_position;
|
||||
while (!quit_) {
|
||||
delegate_->OnEvent(GetEvent());
|
||||
PrepareDraw();
|
||||
std::cout << reset_position << ToString() << std::flush;
|
||||
reset_position = ResetPosition();
|
||||
Clear();
|
||||
Draw();
|
||||
delegate_->OnEvent(GetEvent());
|
||||
}
|
||||
while (!quit_)
|
||||
;
|
||||
// std::cout << std::endl;
|
||||
|
||||
// Restore the old terminal configuration.
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &terminal_configuration_old);
|
||||
}
|
||||
|
||||
void ScreenInteractive::Draw() {
|
||||
void ScreenInteractive::PrepareDraw() {
|
||||
auto document = delegate_->component()->Render();
|
||||
size_t dimx;
|
||||
size_t dimy;
|
||||
@ -168,12 +167,6 @@ void ScreenInteractive::Draw() {
|
||||
}
|
||||
|
||||
Render(*this, document.get());
|
||||
std::cout << ToString() << std::flush;
|
||||
}
|
||||
|
||||
void ScreenInteractive::Clear() {
|
||||
std::cout << ResetPosition();
|
||||
Screen::Clear();
|
||||
}
|
||||
|
||||
component::Delegate* ScreenInteractive::delegate() {
|
||||
|
@ -51,7 +51,7 @@ class VBox : public Node {
|
||||
remaining_flex -= child->requirement().flex.y;
|
||||
child_box.bottom += added_space;
|
||||
}
|
||||
child_box.bottom = std::min(child_box.bottom, box.bottom-1);
|
||||
child_box.bottom = std::min(child_box.bottom, box.bottom);
|
||||
|
||||
child->SetBox(child_box);
|
||||
y = child_box.bottom + 1;
|
||||
|
@ -56,17 +56,18 @@ std::string Screen::ToString() {
|
||||
Pixel previous_pixel;
|
||||
|
||||
for (size_t y = 0; y < dimy_; ++y) {
|
||||
if (y != 0)
|
||||
ss << '\n';
|
||||
for (size_t x = 0; x < dimx_; ++x) {
|
||||
UpdatePixelStyle(ss, previous_pixel, pixels_[y][x]);
|
||||
ss << pixels_[y][x].character;
|
||||
}
|
||||
|
||||
if (y + 1 < dimy_)
|
||||
ss << '\n';
|
||||
Pixel final_pixel;
|
||||
UpdatePixelStyle(ss, previous_pixel, final_pixel);
|
||||
}
|
||||
|
||||
Pixel final_pixel;
|
||||
UpdatePixelStyle(ss, previous_pixel, final_pixel);
|
||||
|
||||
return to_string(ss.str());
|
||||
}
|
||||
|
||||
@ -93,10 +94,10 @@ Screen Screen::TerminalOutput(std::unique_ptr<dom::Node>& element) {
|
||||
|
||||
std::string Screen::ResetPosition() {
|
||||
std::stringstream ss;
|
||||
//ss << '\r';
|
||||
for (size_t y = 1; y < dimy_; ++y) {
|
||||
ss << "\e[2K\r\e[1A";
|
||||
}
|
||||
ss << '\r';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user