mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-20 18:48:08 +08:00
Warn against Microsoft <windows.h> min and max macro (#1084)
Warn users they have defined the min/max macros which is not compatible with other code from the standard library or FTXUI. Co-authored-by: Sylko Olzscher <sylko.olzscher@solostec.ch> Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
@@ -133,8 +133,9 @@ int main() {
|
||||
float dy = 50.f;
|
||||
ys[x] = int(dy + 20 * cos(dx * 0.14) + 10 * sin(dx * 0.42));
|
||||
}
|
||||
for (int x = 1; x < 99; x++)
|
||||
for (int x = 1; x < 99; x++) {
|
||||
c.DrawPointLine(x, ys[x], x + 1, ys[x + 1]);
|
||||
}
|
||||
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
@@ -82,10 +82,12 @@ int main() {
|
||||
size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy) |
|
||||
bgcolor(Color::HSV(index * 25, 255, 255)) |
|
||||
color(Color::Black);
|
||||
if (element_xflex_grow)
|
||||
if (element_xflex_grow) {
|
||||
element = element | xflex_grow;
|
||||
if (element_yflex_grow)
|
||||
}
|
||||
if (element_yflex_grow) {
|
||||
element = element | yflex_grow;
|
||||
}
|
||||
return element;
|
||||
};
|
||||
|
||||
@@ -119,10 +121,12 @@ int main() {
|
||||
|
||||
group = group | notflex;
|
||||
|
||||
if (!group_xflex_grow)
|
||||
if (!group_xflex_grow) {
|
||||
group = hbox(group, filler());
|
||||
if (!group_yflex_grow)
|
||||
}
|
||||
if (!group_yflex_grow) {
|
||||
group = vbox(group, filler());
|
||||
}
|
||||
|
||||
group = group | flex;
|
||||
return group;
|
||||
|
@@ -1,11 +1,11 @@
|
||||
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <stddef.h> // for size_t
|
||||
#include <array> // for array
|
||||
#include <atomic> // for atomic
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <cmath> // for sin
|
||||
#include <stddef.h> // for size_t
|
||||
#include <array> // for array
|
||||
#include <atomic> // for atomic
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <cmath> // for sin
|
||||
#include <ftxui/component/loop.hpp>
|
||||
#include <functional> // for ref, reference_wrapper, function
|
||||
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
||||
@@ -514,7 +514,7 @@ int main() {
|
||||
});
|
||||
|
||||
Loop loop(&screen, main_renderer);
|
||||
while(!loop.HasQuitted()) {
|
||||
while (!loop.HasQuitted()) {
|
||||
// Update the state of the application.
|
||||
shift++;
|
||||
|
||||
@@ -525,7 +525,7 @@ int main() {
|
||||
loop.RunOnce();
|
||||
|
||||
// Sleep for a short duration to control the frame rate (60 FPS).
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000/60));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / 60));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@@ -22,10 +22,12 @@ MenuEntryOption Colored(ftxui::Color c) {
|
||||
option.transform = [c](EntryState state) {
|
||||
state.label = (state.active ? "> " : " ") + state.label;
|
||||
Element e = text(state.label) | color(c);
|
||||
if (state.focused)
|
||||
if (state.focused) {
|
||||
e = e | inverted;
|
||||
if (state.active)
|
||||
}
|
||||
if (state.active) {
|
||||
e = e | bold;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
return option;
|
||||
|
@@ -17,8 +17,9 @@ int main() {
|
||||
std::vector<std::string> entries;
|
||||
int selected = 0;
|
||||
|
||||
for (int i = 0; i < 30; ++i)
|
||||
for (int i = 0; i < 30; ++i) {
|
||||
entries.push_back("Entry " + std::to_string(i));
|
||||
}
|
||||
auto radiobox = Menu(&entries, &selected);
|
||||
auto renderer = Renderer(radiobox, [&] {
|
||||
return radiobox->Render() | vscroll_indicator | frame |
|
||||
|
@@ -17,8 +17,9 @@ int main() {
|
||||
std::vector<std::string> entries;
|
||||
int selected = 0;
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
entries.push_back(std::to_string(i));
|
||||
}
|
||||
auto radiobox = Menu(&entries, &selected, MenuOption::Horizontal());
|
||||
auto renderer = Renderer(
|
||||
radiobox, [&] { return radiobox->Render() | hscroll_indicator | frame; });
|
||||
|
@@ -116,10 +116,12 @@ Component VMenu1(std::vector<std::string>* entries, int* selected) {
|
||||
option.entries_option.transform = [](EntryState state) {
|
||||
state.label = (state.active ? "> " : " ") + state.label;
|
||||
Element e = text(state.label);
|
||||
if (state.focused)
|
||||
if (state.focused) {
|
||||
e = e | bgcolor(Color::Blue);
|
||||
if (state.active)
|
||||
}
|
||||
if (state.active) {
|
||||
e = e | bold;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
return Menu(entries, selected, option);
|
||||
@@ -130,10 +132,12 @@ Component VMenu2(std::vector<std::string>* entries, int* selected) {
|
||||
option.entries_option.transform = [](EntryState state) {
|
||||
state.label += (state.active ? " <" : " ");
|
||||
Element e = hbox(filler(), text(state.label));
|
||||
if (state.focused)
|
||||
if (state.focused) {
|
||||
e = e | bgcolor(Color::Red);
|
||||
if (state.active)
|
||||
}
|
||||
if (state.active) {
|
||||
e = e | bold;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
return Menu(entries, selected, option);
|
||||
@@ -144,13 +148,16 @@ Component VMenu3(std::vector<std::string>* entries, int* selected) {
|
||||
option.entries_option.transform = [](EntryState state) {
|
||||
Element e = state.active ? text("[" + state.label + "]")
|
||||
: text(" " + state.label + " ");
|
||||
if (state.focused)
|
||||
if (state.focused) {
|
||||
e = e | bold;
|
||||
}
|
||||
|
||||
if (state.focused)
|
||||
if (state.focused) {
|
||||
e = e | color(Color::Blue);
|
||||
if (state.active)
|
||||
}
|
||||
if (state.active) {
|
||||
e = e | bold;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
return Menu(entries, selected, option);
|
||||
@@ -245,10 +252,12 @@ Component HMenu5(std::vector<std::string>* entries, int* selected) {
|
||||
animation::easing::ElasticOut);
|
||||
option.entries_option.transform = [](EntryState state) {
|
||||
Element e = text(state.label) | hcenter | flex;
|
||||
if (state.active && state.focused)
|
||||
if (state.active && state.focused) {
|
||||
e = e | bold;
|
||||
if (!state.focused && !state.active)
|
||||
}
|
||||
if (!state.focused && !state.active) {
|
||||
e = e | dim;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
option.underline.color_inactive = Color::Default;
|
||||
|
@@ -20,8 +20,9 @@ using namespace ftxui;
|
||||
Component DummyComponent(int id) {
|
||||
return Renderer([id](bool focused) {
|
||||
auto t = text("component " + std::to_string(id));
|
||||
if (focused)
|
||||
if (focused) {
|
||||
t = t | inverted;
|
||||
}
|
||||
return t;
|
||||
});
|
||||
}
|
||||
|
@@ -17,8 +17,9 @@ int main() {
|
||||
std::vector<std::string> entries;
|
||||
int selected = 0;
|
||||
|
||||
for (int i = 0; i < 30; ++i)
|
||||
for (int i = 0; i < 30; ++i) {
|
||||
entries.push_back("RadioBox " + std::to_string(i));
|
||||
}
|
||||
auto radiobox = Radiobox(&entries, &selected);
|
||||
auto renderer = Renderer(radiobox, [&] {
|
||||
return radiobox->Render() | vscroll_indicator | frame |
|
||||
|
@@ -19,10 +19,11 @@ int main() {
|
||||
|
||||
// 1. Example of focusable renderer:
|
||||
auto renderer_focusable = Renderer([](bool focused) {
|
||||
if (focused)
|
||||
if (focused) {
|
||||
return text("FOCUSABLE RENDERER()") | center | bold | border;
|
||||
else
|
||||
} else {
|
||||
return text(" Focusable renderer() ") | center | border;
|
||||
}
|
||||
});
|
||||
|
||||
// 2. Examples of a non focusable renderer.
|
||||
@@ -33,10 +34,11 @@ int main() {
|
||||
// 3. Renderer can wrap other components to redefine their Render() function.
|
||||
auto button = Button("Wrapped quit button", screen.ExitLoopClosure());
|
||||
auto renderer_wrap = Renderer(button, [&] {
|
||||
if (button->Focused())
|
||||
if (button->Focused()) {
|
||||
return button->Render() | bold | color(Color::Red);
|
||||
else
|
||||
} else {
|
||||
return button->Render();
|
||||
}
|
||||
});
|
||||
|
||||
// Let's renderer everyone:
|
||||
|
@@ -32,10 +32,12 @@ int main() {
|
||||
|
||||
// Plot a function:
|
||||
std::vector<int> ys(100);
|
||||
for (int x = 0; x < 100; x++)
|
||||
for (int x = 0; x < 100; x++) {
|
||||
ys[x] = int(80 + 20 * cos(x * 0.2));
|
||||
for (int x = 0; x < 99; x++)
|
||||
}
|
||||
for (int x = 0; x < 99; x++) {
|
||||
c.DrawPointLine(x, ys[x], x + 1, ys[x + 1], Color::Red);
|
||||
}
|
||||
|
||||
auto document = canvas(&c) | border;
|
||||
|
||||
|
@@ -86,8 +86,9 @@ int main() {
|
||||
|
||||
auto render = [&]() {
|
||||
std::vector<Element> entries;
|
||||
for (auto& task : displayed_task)
|
||||
for (auto& task : displayed_task) {
|
||||
entries.push_back(renderTask(task));
|
||||
}
|
||||
|
||||
return vbox({
|
||||
// List of tasks.
|
||||
@@ -138,8 +139,9 @@ int main() {
|
||||
std::this_thread::sleep_for(0.01s);
|
||||
|
||||
// Exit
|
||||
if (nb_active + nb_queued == 0)
|
||||
if (nb_active + nb_queued == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Update the model for the next frame.
|
||||
updateModel();
|
||||
|
@@ -21,8 +21,9 @@ int main() {
|
||||
for (int index = 0; index < 200; ++index) {
|
||||
std::vector<Element> entries;
|
||||
for (int i = 0; i < 23; ++i) {
|
||||
if (i != 0)
|
||||
if (i != 0) {
|
||||
entries.push_back(separator());
|
||||
}
|
||||
entries.push_back( //
|
||||
hbox({
|
||||
text(std::to_string(i)) | size(WIDTH, EQUAL, 2),
|
||||
|
Reference in New Issue
Block a user