mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-23 13:28:08 +08:00
Make component more functionnal
This commit is contained in:
@@ -1,35 +1,36 @@
|
||||
#include <string> // for wstring, operator+
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/component.hpp" // for Component
|
||||
#include "ftxui/component/radiobox.hpp" // for RadioBox
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Make, Radiobox
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for Element, operator|
|
||||
#include "ftxui/screen/box.hpp" // for ftxui
|
||||
#include "ftxui/screen/string.hpp" // for to_wstring
|
||||
#include "ftxui/dom/elements.hpp" // for Element, operator|, size, border, frame, HEIGHT, LESS_THAN
|
||||
#include "ftxui/screen/string.hpp" // for to_wstring
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
class MyComponent : public Component {
|
||||
RadioBox radiobox;
|
||||
class MyComponent : public ComponentBase {
|
||||
private:
|
||||
std::vector<std::wstring> entries_;
|
||||
int selected_ = 0;
|
||||
|
||||
public:
|
||||
MyComponent() {
|
||||
for (int i = 0; i < 30; ++i) {
|
||||
radiobox.entries.push_back(L"RadioBox " + to_wstring(i));
|
||||
}
|
||||
Add(&radiobox);
|
||||
for (int i = 0; i < 30; ++i)
|
||||
entries_.push_back(L"RadioBox " + to_wstring(i));
|
||||
Add(Radiobox(&entries_, &selected_));
|
||||
}
|
||||
|
||||
Element Render() override {
|
||||
return radiobox.Render() | frame | size(HEIGHT, LESS_THAN, 10) | border;
|
||||
return ComponentBase::Render() | frame | size(HEIGHT, LESS_THAN, 10) |
|
||||
border;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
MyComponent component;
|
||||
screen.Loop(&component);
|
||||
screen.Loop(Make<MyComponent>());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user