-
-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Dropdown options with callback (#826)
Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
- Loading branch information
1 parent
2216f3a
commit 3c9fa60
Showing
9 changed files
with
202 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright 2020 Arthur Sonzogni. All rights reserved. | ||
// Use of this source code is governed by the MIT license that can be found in | ||
// the LICENSE file. | ||
#include <string> // for basic_string, string, allocator | ||
#include <vector> // for vector | ||
|
||
#include "ftxui/component/captured_mouse.hpp" // for ftxui | ||
#include "ftxui/component/component.hpp" // for Dropdown, Horizontal, Vertical | ||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive | ||
|
||
int main() { | ||
using namespace ftxui; | ||
|
||
std::vector<std::string> entries = { | ||
"tribute", "clearance", "ally", "bend", "electronics", | ||
"module", "era", "cultural", "sniff", "nationalism", | ||
"negotiation", "deliver", "figure", "east", "tribute", | ||
"clearance", "ally", "bend", "electronics", "module", | ||
"era", "cultural", "sniff", "nationalism", "negotiation", | ||
"deliver", "figure", "east", "tribute", "clearance", | ||
"ally", "bend", "electronics", "module", "era", | ||
"cultural", "sniff", "nationalism", "negotiation", "deliver", | ||
"figure", "east", | ||
}; | ||
|
||
auto dropdown_1 = Dropdown({ | ||
.radiobox = {.entries = &entries}, | ||
.transform = | ||
[](bool open, Element checkbox, Element radiobox) { | ||
if (open) { | ||
return vbox({ | ||
checkbox | inverted, | ||
radiobox | vscroll_indicator | frame | | ||
size(HEIGHT, LESS_THAN, 10), | ||
filler(), | ||
}); | ||
} | ||
return vbox({ | ||
checkbox, | ||
filler(), | ||
}); | ||
}, | ||
}); | ||
|
||
auto dropdown_2 = Dropdown({ | ||
.radiobox = {.entries = &entries}, | ||
.transform = | ||
[](bool open, Element checkbox, Element radiobox) { | ||
if (open) { | ||
return vbox({ | ||
checkbox | inverted, | ||
radiobox | vscroll_indicator | frame | | ||
size(HEIGHT, LESS_THAN, 10) | bgcolor(Color::Blue), | ||
filler(), | ||
}); | ||
} | ||
return vbox({ | ||
checkbox | bgcolor(Color::Blue), | ||
filler(), | ||
}); | ||
}, | ||
}); | ||
|
||
auto dropdown_3 = Dropdown({ | ||
.radiobox = | ||
{ | ||
.entries = &entries, | ||
.transform = | ||
[](const EntryState& s) { | ||
auto t = text(s.label) | borderEmpty; | ||
if (s.active) { | ||
t |= bold; | ||
} | ||
if (s.focused) { | ||
t |= inverted; | ||
} | ||
return t; | ||
}, | ||
}, | ||
.transform = | ||
[](bool open, Element checkbox, Element radiobox) { | ||
checkbox |= borderEmpty; | ||
if (open) { | ||
return vbox({ | ||
checkbox | inverted, | ||
radiobox | vscroll_indicator | frame | | ||
size(HEIGHT, LESS_THAN, 20) | bgcolor(Color::Red), | ||
filler(), | ||
}); | ||
} | ||
return vbox({ | ||
checkbox | bgcolor(Color::Red), | ||
filler(), | ||
}); | ||
}, | ||
}); | ||
|
||
auto screen = ScreenInteractive::FitComponent(); | ||
screen.Loop(Container::Horizontal({ | ||
dropdown_1, | ||
dropdown_2, | ||
dropdown_3, | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters