mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-22 20:58:10 +08:00
Add menu styles.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define FTXUI_COMPONENT_MENU
|
||||
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace ftxui {
|
||||
@@ -16,6 +17,10 @@ class Menu : public Component {
|
||||
std::vector<std::wstring> entries = {};
|
||||
int selected = 0;
|
||||
|
||||
dom::Decorator active_style = dom::inverted;
|
||||
dom::Decorator selected_style = dom::bold;
|
||||
dom::Decorator normal_style = dom::nothing;
|
||||
|
||||
// State update callback.
|
||||
std::function<void()> on_change = [](){};
|
||||
std::function<void()> on_enter = [](){};
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
@@ -13,9 +14,8 @@ class Toggle : public Component {
|
||||
Toggle(Delegate*);
|
||||
|
||||
// State.
|
||||
bool activated = true;
|
||||
std::wstring on = L"On";
|
||||
std::wstring off = L"Off";
|
||||
size_t activated = 0;
|
||||
std::vector<std::wstring> options = {L"On", L"Off"};
|
||||
|
||||
// Callback.
|
||||
std::function<void()> on_change = [](){};
|
||||
|
@@ -1,6 +1,8 @@
|
||||
#ifndef FTXUI_DOM_ELEMENTS_HPP
|
||||
#define FTXUI_DOM_ELEMENTS_HPP
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "ftxui/color.hpp"
|
||||
#include "ftxui/dom/node.hpp"
|
||||
|
||||
@@ -8,12 +10,14 @@ namespace ftxui {
|
||||
namespace dom {
|
||||
|
||||
using Element = std::unique_ptr<Node>;
|
||||
using Decorator = std::function<Element(Element)>;
|
||||
using Child = std::unique_ptr<Node>;
|
||||
using Children = std::vector<Child>;
|
||||
|
||||
// --- Layout ----
|
||||
Element vbox(Children);
|
||||
Element hbox(Children);
|
||||
Element dbox(Children);
|
||||
Element flex();
|
||||
Element flex(Element);
|
||||
|
||||
@@ -32,6 +36,8 @@ Element underlined(Element);
|
||||
Element blink(Element);
|
||||
Element color(Color, Element);
|
||||
Element bgcolor(Color, Element);
|
||||
Decorator color(Color);
|
||||
Decorator bgcolor(Color);
|
||||
|
||||
// --- Util ---
|
||||
Element hcenter(Element);
|
||||
@@ -40,6 +46,7 @@ Element center(Element);
|
||||
|
||||
// --- Util ---
|
||||
Element nothing(Element element);
|
||||
Decorator compose(Decorator, Decorator);
|
||||
|
||||
template <class... Args>
|
||||
Children unpack(Args... args) {
|
||||
@@ -58,6 +65,11 @@ Element hbox(Args... children) {
|
||||
return hbox(unpack(std::forward<Args>(children)...));
|
||||
}
|
||||
|
||||
template <class... Args>
|
||||
Element dbox(Args... children) {
|
||||
return dbox(unpack(std::forward<Args>(children)...));
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
|
||||
|
Reference in New Issue
Block a user