51class SliderBase :
public SliderOption<T>,
public ComponentBase {
53 explicit SliderBase(SliderOption<T> options) : SliderOption<T>(options) {}
57 Focused() ?
color(this->color_active) : color(this->color_inactive);
59 float(this->value() - this->min()) / float(this->max() - this->min());
61 flexDirection(this->direction) |
reflect(gauge_box_) | gauge_color;
65 if (pressed == this->direction) {
66 this->value() += this->increment();
70 if (pressed == Opposite(this->direction)) {
71 this->value() -= this->increment();
76 bool OnEvent(Event event)
final {
77 if (event.is_mouse()) {
78 return OnMouseEvent(event);
81 T old_value = this->value();
95 this->value() = std::max(this->min(), std::min(this->max(), this->value()));
96 if (old_value != this->value()) {
97 if (this->on_change) {
106 bool OnCapturedMouseEvent(Event event) {
108 captured_mouse_ =
nullptr;
112 T old_value = this->value();
113 switch (this->direction) {
115 this->value() = this->min() + (
event.mouse().x - gauge_box_.x_min) *
116 (this->max() - this->min()) /
117 (gauge_box_.x_max - gauge_box_.x_min);
122 this->value() = this->max() - (
event.mouse().x - gauge_box_.x_min) *
123 (this->max() - this->min()) /
124 (gauge_box_.x_max - gauge_box_.x_min);
128 this->value() = this->min() + (
event.mouse().y - gauge_box_.y_min) *
129 (this->max() - this->min()) /
130 (gauge_box_.y_max - gauge_box_.y_min);
134 this->value() = this->max() - (
event.mouse().y - gauge_box_.y_min) *
135 (this->max() - this->min()) /
136 (gauge_box_.y_max - gauge_box_.y_min);
141 this->value() = std::max(this->min(), std::min(this->max(), this->value()));
143 if (old_value != this->value() && this->on_change) {
149 bool OnMouseEvent(Event event) {
150 if (captured_mouse_) {
151 return OnCapturedMouseEvent(event);
161 if (!gauge_box_.Contain(event.mouse().x, event.mouse().y)) {
165 captured_mouse_ = CaptureMouse(event);
167 if (captured_mouse_) {
169 return OnCapturedMouseEvent(event);
175 bool Focusable() const final {
return true; }
182class SliderWithLabel :
public ComponentBase {
184 SliderWithLabel(ConstStringRef label,
Component inner)
185 : label_(std::move(label)) {
186 Add(std::move(inner));
187 SetActiveChild(ChildAt(0));
191 bool OnEvent(Event event)
final {
196 if (!event.is_mouse()) {
200 mouse_hover_ = box_.Contain(event.mouse().x, event.mouse().y);
206 if (!CaptureMouse(event)) {
216 auto element =
hbox({
224 gauge_color | xflex |
reflect(box_);
230 ConstStringRef label_;
232 bool mouse_hover_ =
false;
263 option.
value = value;
267 auto slider = Make<SliderBase<int>>(option);
277 option.
value = value;
281 auto slider = Make<SliderBase<float>>(option);
290 option.
value = value;
294 auto slider = Make<SliderBase<long>>(option);
313 return Make<SliderBase<T>>(options);
一個適配器。擁有或引用一個常數字串。為方便起見,此類別將多個不可變字串轉換為共享表示。
Element Render()
繪製組件。 建構一個 ftxui::Element,用於在表示此 ftxui::ComponentBase 的 ftxui::Screen 上繪製。請覆寫 OnRender() 以修改渲染。
static const Event ArrowUp
static const Event ArrowDown
virtual bool OnEvent(Event)
回應事件時呼叫。
static const Event ArrowLeft
static const Event ArrowRight
Element xflex(Element)
在 X 軸上盡可能擴展/在需要時最小化。
Element gaugeDirection(float progress, Direction direction)
繪製一個指定方向的高解析度進度條。
Direction
Direction 是一個列舉,表示四個主要方向。
Element yflex(Element)
在 Y 軸上盡可能擴展/在需要時最小化。
Element underlined(Element)
為給定元素加上底線。
Element text(std::wstring text)
顯示一段 Unicode 文字。
Element focus(Element)
將 child 設置為其同級元素中被聚焦的元素。
Element vcenter(Element)
垂直置中一個元素。
Decorator color(Color)
使用前景顏色進行裝飾。
std::function< Element(Element)> Decorator
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< T > Make(Args &&... args)
std::shared_ptr< Node > Element
Element hbox(Elements)
一個逐一水平顯示元素的容器。
Component Slider(SliderOption< T > options)
Decorator reflect(Box &box)
std::shared_ptr< ComponentBase > Component