FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
linear_gradient_gallery.cpp
Go to the documentation of this file.
1// Copyright 2023 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#include <ftxui/component/component_base.hpp> // for ComponentBase, Component
5#include <ftxui/dom/elements.hpp> // for operator|, Element, flex, bgcolor, text, vbox, center
6#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient
7#include <ftxui/screen/color.hpp> // for Color, Color::Blue, Color::Red
8#include <memory> // for __shared_ptr_access, shared_ptr
9#include <string> // for allocator, operator+, char_traits, string, to_string
10
11#include "ftxui/component/captured_mouse.hpp" // for ftxui
12#include "ftxui/component/component.hpp" // for Slider, Renderer, Vertical
13#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
14
15int main() {
16 using namespace ftxui;
17 auto screen = ScreenInteractive::Fullscreen();
18
19 int angle = 180.f;
20 float start = 0.f;
21 float end = 1.f;
22
23 std::string slider_angle_text;
24 std::string slider_start_text;
25 std::string slider_end_text;
26
27 auto slider_angle = Slider(&slider_angle_text, &angle, 0, 360);
28 auto slider_start = Slider(&slider_start_text, &start, 0.f, 1.f, 0.05f);
29 auto slider_end = Slider(&slider_end_text, &end, 0.f, 1.f, 0.05f);
30
31 auto layout = Container::Vertical({
32 slider_angle,
33 slider_start,
34 slider_end,
35 });
36
37 auto renderer = Renderer(layout, [&] {
38 slider_angle_text = "angle = " + std::to_string(angle) + "°";
39 slider_start_text = "start = " + std::to_string(int(start * 100)) + "%";
40 slider_end_text = "end = " + std::to_string(int(end * 100)) + "%";
41
42 auto background = text("Gradient") | center |
43 bgcolor(LinearGradient()
44 .Angle(angle)
45 .Stop(Color::Blue, start)
46 .Stop(Color::Red, end));
47 return vbox({
48 background | flex,
49 layout->Render(),
50 }) |
51 flex;
52 });
53
54 screen.Loop(renderer);
55}
A class representing the settings for linear-gradient color effect.
The FTXUI ftxui:: namespace.
Definition animation.hpp:10