From 5ff0764e77bf7b903908354b518c8da3320d0986 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sat, 6 Apr 2024 17:41:43 +0200 Subject: [PATCH] Add changelog and example. --- CHANGELOG.md | 1 + examples/component/dropdown_custom.cpp | 35 +++++++++++++++++++ include/ftxui/component/component_options.hpp | 4 +++ 3 files changed, 40 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4963ac57..17dff7c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ current (development) ### Component - Feature: Add support for `Input`'s insert mode. Add `InputOption::insert` option. Added by @mingsheng13. +- Feature: Add `DropdownOption` to configure the dropdown. See #826. - Bugfix/Breaking change: `Mouse transition`: - Detect when the mouse move, as opposed to being pressed. The Mouse::Moved motion was added. diff --git a/examples/component/dropdown_custom.cpp b/examples/component/dropdown_custom.cpp index e07581d1..462d7f7b 100644 --- a/examples/component/dropdown_custom.cpp +++ b/examples/component/dropdown_custom.cpp @@ -61,9 +61,44 @@ int main() { }, }); + 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, })); } diff --git a/include/ftxui/component/component_options.hpp b/include/ftxui/component/component_options.hpp index 881a9829..100a99d9 100644 --- a/include/ftxui/component/component_options.hpp +++ b/include/ftxui/component/component_options.hpp @@ -268,9 +268,13 @@ struct WindowOptions { /// @ingroup component /// A dropdown menu is a checkbox opening/closing a radiobox. struct DropdownOption { + /// Whether the dropdown is open or closed: Ref open = false; + // The options for the checkbox: CheckboxOption checkbox; + // The options for the radiobox: RadioboxOption radiobox; + // The transformation function: std::function transform; };