FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
menu_entries_animated.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// 本原始碼的使用受 MIT 授權條款的約束,詳情請參閱 LICENSE 檔案。
3#include <iostream> // for basic_ostream::operator<<, operator<<, endl, basic_ostream, basic_ostream<>::__ostream_type, cout, ostream
4#include <memory> // for shared_ptr, __shared_ptr_access
5#include <string> // for to_string, allocator
6
7#include "ftxui/component/captured_mouse.hpp" // for ftxui
8#include "ftxui/component/component.hpp" // for MenuEntryAnimated, Renderer, Vertical
9#include "ftxui/component/component_base.hpp" // for ComponentBase
10#include "ftxui/component/component_options.hpp" // for MenuEntryAnimated
11#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
12#include "ftxui/dom/elements.hpp" // for operator|, separator, Element, Decorator, color, text, hbox, size, bold, frame, inverted, vbox, HEIGHT, LESS_THAN, border
13#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Cyan, Color::Green, Color::Red, Color::Yellow
14
15using namespace ftxui;
16
17// 為某些菜單項目定義特殊樣式。
28
29int main() {
31
32 int selected = 0;
33 auto menu = Container::Vertical(
34 {
35 MenuEntry(" 1. rear", Colored(Color::Red)),
36 MenuEntry(" 2. drown", Colored(Color::Yellow)),
37 MenuEntry(" 3. nail", Colored(Color::Green)),
38 MenuEntry(" 4. quit", Colored(Color::Cyan)),
39 MenuEntry(" 5. decorative", Colored(Color::Blue)),
40 MenuEntry(" 7. costume"),
41 MenuEntry(" 8. pick"),
42 MenuEntry(" 9. oral"),
43 MenuEntry("11. minister"),
44 MenuEntry("12. football"),
45 MenuEntry("13. welcome"),
46 MenuEntry("14. copper"),
47 MenuEntry("15. inhabitant"),
48 },
49 &selected);
50
51 // 帶邊框的菜單一起顯示
52 auto renderer = Renderer(menu, [&] {
53 return vbox({
54 hbox(text("selected = "), text(std::to_string(selected))),
55 separator(),
56 menu->Render() | frame,
57 }) |
58 border | bgcolor(Color::Black);
59 });
60
61 screen.Loop(renderer);
62
63 std::cout << "Selected element = " << selected << std::endl;
64}
auto menu
Definition gallery.cpp:39
static ScreenInteractive TerminalOutput()
AnimatedColorsOption animated_colors
Component MenuEntry(MenuEntryOption options)
一個特定的菜單條目。它們可以放入 Container::Vertical 中以形成菜單。
Component Renderer(Component child, std::function< Element()>)
回傳一個新的元件,類似於 |child|,但使用 |render| 作為 Component::Render() 事件。
MenuEntry 元件的選項。
virtual void Render(Screen &screen)
Decorator bgcolor(Color)
使用背景顏色進行裝飾。
Element text(std::wstring text)
顯示一段 Unicode 文字。
Definition text.cpp:160
Element separator()
在兩個元素之間繪製垂直或水平分隔線。
Element vbox(Elements)
一個垂直一個接一個顯示元素的容器。
Definition vbox.cpp:95
Color 是一個在終端使用者介面中表示顏色的類別。
Definition color.hpp:20
MenuEntryOption Colored(ftxui::Color c)
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
Element hbox(Elements)
一個逐一水平顯示元素的容器。
Definition hbox.cpp:94
Element frame(Element)
允許元素顯示在「虛擬」區域內。其大小可以大於其容器。在這種情況下,只會顯示較小的一部分。視圖可滾動以使聚焦元素可見。
Definition frame.cpp:116