mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 16:29:34 +08:00
Use shared_ptr instead of unique_ptr for elements.
This allow users to pass it into initializer list. Then clang-format will produce 'acceptable' indentations. This fixes: https://github.com/ArthurSonzogni/FTXUI/issues/18
This commit is contained in:
@@ -57,27 +57,28 @@ class MyComponent : public Component {
|
||||
container.Add(&input);
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
Element Render(std::wstring name, Component& component) {
|
||||
return
|
||||
hbox(
|
||||
return hbox({
|
||||
text(name) | size(WIDTH, EQUAL, 8),
|
||||
separator(),
|
||||
component.Render()
|
||||
);
|
||||
component.Render(),
|
||||
});
|
||||
}
|
||||
|
||||
Element Render() override {
|
||||
return
|
||||
vbox(
|
||||
Render(L"menu", menu), separator(),
|
||||
Render(L"toggle", toggle), separator(),
|
||||
Render(L"checkbox", checkbox_container), separator(),
|
||||
Render(L"radiobox", radiobox), separator(),
|
||||
Render(L"input", input) | size(WIDTH, LESS_THAN, 30)
|
||||
) | border;
|
||||
return vbox({
|
||||
Render(L"menu", menu),
|
||||
separator(),
|
||||
Render(L"toggle", toggle),
|
||||
separator(),
|
||||
Render(L"checkbox", checkbox_container),
|
||||
separator(),
|
||||
Render(L"radiobox", radiobox),
|
||||
separator(),
|
||||
Render(L"input", input) | size(WIDTH, LESS_THAN, 30),
|
||||
}) |
|
||||
border;
|
||||
}
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
|
@@ -41,49 +41,60 @@ class HTopComponent : public Component {
|
||||
HTopComponent() {}
|
||||
~HTopComponent() override {}
|
||||
|
||||
// clang-format off
|
||||
Element Render() override {
|
||||
return
|
||||
hbox(
|
||||
vbox(
|
||||
// --- Frequency ---
|
||||
text(L"Frequency [Mhz]") | hcenter,
|
||||
hbox(
|
||||
vbox(
|
||||
text(L"2400 "), filler(),
|
||||
text(L"1200 "), filler(),
|
||||
text(L"0% ")
|
||||
),
|
||||
graph(std::ref(my_graph))
|
||||
) | flex,
|
||||
separator(),
|
||||
// --- Utilization ---
|
||||
text(L"Utilization [%]") | hcenter,
|
||||
hbox(
|
||||
vbox(
|
||||
text(L"100 "), filler(),
|
||||
text(L"50 "), filler(),
|
||||
text(L"0 ")
|
||||
),
|
||||
graph(std::ref(my_graph)) | color(Color::RedLight)
|
||||
) | flex
|
||||
) | flex,
|
||||
separator(),
|
||||
// --- Ram ---
|
||||
vbox(
|
||||
text(L"Ram [Mo]") | hcenter,
|
||||
hbox(
|
||||
vbox(
|
||||
text(L"8192"), filler(),
|
||||
text(L"4096 "), filler(),
|
||||
text(L"0 ")
|
||||
),
|
||||
graph(std::ref(my_graph)) | color(Color::BlueLight)
|
||||
) | flex
|
||||
) | flex
|
||||
) | flex | border;
|
||||
auto frequency = vbox({
|
||||
text(L"Frequency [Mhz]") | hcenter,
|
||||
hbox({
|
||||
vbox({
|
||||
text(L"2400 "),
|
||||
filler(),
|
||||
text(L"1200 "),
|
||||
filler(),
|
||||
text(L"0% "),
|
||||
}),
|
||||
graph(std::ref(my_graph)) | flex,
|
||||
}) | flex,
|
||||
});
|
||||
|
||||
auto utilization = vbox({
|
||||
text(L"Utilization [%]") | hcenter,
|
||||
hbox({
|
||||
vbox({
|
||||
text(L"100 "),
|
||||
filler(),
|
||||
text(L"50 "),
|
||||
filler(),
|
||||
text(L"0 "),
|
||||
}),
|
||||
graph(std::ref(my_graph)) | color(Color::RedLight),
|
||||
}) | flex,
|
||||
});
|
||||
|
||||
auto ram = vbox({
|
||||
text(L"Ram [Mo]") | hcenter,
|
||||
hbox({
|
||||
vbox({
|
||||
text(L"8192"),
|
||||
filler(),
|
||||
text(L"4096 "),
|
||||
filler(),
|
||||
text(L"0 "),
|
||||
}),
|
||||
graph(std::ref(my_graph)) | color(Color::BlueLight),
|
||||
}) | flex,
|
||||
});
|
||||
|
||||
return hbox({
|
||||
vbox({
|
||||
frequency | flex,
|
||||
separator(),
|
||||
utilization | flex,
|
||||
}) | flex,
|
||||
separator(),
|
||||
ram | flex,
|
||||
}) |
|
||||
flex | border;
|
||||
}
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
class CompilerComponent : public Component {
|
||||
@@ -173,37 +184,38 @@ class CompilerComponent : public Component {
|
||||
input_container.Add(&input);
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
Element Render() override {
|
||||
return
|
||||
vbox(
|
||||
hbox(
|
||||
window(text(L"Compiler"),
|
||||
compiler.Render() | frame | size(HEIGHT, LESS_THAN, 6)
|
||||
),
|
||||
window(text(L"Flags"), flag.Render()),
|
||||
vbox(
|
||||
window(text(L"Executable:"), executable.Render())
|
||||
| size(WIDTH, EQUAL, 20),
|
||||
window(text(L"Input"),
|
||||
hbox(
|
||||
vbox(
|
||||
hbox(text(L"Add: "), input_add.Render())
|
||||
| size(WIDTH, EQUAL, 20)
|
||||
| size(HEIGHT, EQUAL, 1),
|
||||
filler()
|
||||
),
|
||||
separator(),
|
||||
input.Render() | frame | size(HEIGHT, EQUAL, 3) | flex
|
||||
)
|
||||
) | size(WIDTH, EQUAL, 60)
|
||||
),
|
||||
filler()
|
||||
),
|
||||
hflow(RenderCommandLine())
|
||||
) | border;
|
||||
auto compiler_win = window(text(L"Compiler"), compiler.Render() | frame);
|
||||
auto flags_win = window(text(L"Flags"), flag.Render());
|
||||
auto executable_win = window(text(L"Executable:"), executable.Render());
|
||||
auto input_win =
|
||||
window(text(L"Input"),
|
||||
hbox({
|
||||
vbox({
|
||||
hbox({
|
||||
text(L"Add: "),
|
||||
input_add.Render(),
|
||||
}) | size(WIDTH, EQUAL, 20) |
|
||||
size(HEIGHT, EQUAL, 1),
|
||||
filler(),
|
||||
}),
|
||||
separator(),
|
||||
input.Render() | frame | size(HEIGHT, EQUAL, 3) | flex,
|
||||
}));
|
||||
return vbox({
|
||||
hbox({
|
||||
compiler_win | size(HEIGHT, LESS_THAN, 6),
|
||||
flags_win,
|
||||
vbox({
|
||||
executable_win | size(WIDTH, EQUAL, 20),
|
||||
input_win | size(WIDTH, EQUAL, 60),
|
||||
}),
|
||||
filler(),
|
||||
}),
|
||||
hflow(RenderCommandLine()),
|
||||
}) |
|
||||
border;
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
Elements RenderCommandLine() {
|
||||
Elements line;
|
||||
@@ -230,100 +242,94 @@ class CompilerComponent : public Component {
|
||||
};
|
||||
|
||||
class SpinnerComponent : public Component {
|
||||
// clang-format off
|
||||
Element Render() override {
|
||||
Elements entries;
|
||||
for(int i = 0; i<22; ++i) {
|
||||
for (int i = 0; i < 22; ++i) {
|
||||
if (i != 0)
|
||||
entries.push_back(
|
||||
spinner(i, shift/2)
|
||||
| bold
|
||||
| size(WIDTH, GREATER_THAN, 2)
|
||||
| border
|
||||
);
|
||||
entries.push_back(spinner(i, shift / 2) | bold |
|
||||
size(WIDTH, GREATER_THAN, 2) | border);
|
||||
}
|
||||
return hflow(std::move(entries)) | border;
|
||||
}
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
class ColorComponent : public Component {
|
||||
// clang-format off
|
||||
Element Render() override {
|
||||
return
|
||||
hbox(
|
||||
vbox(
|
||||
color(Color::Default, text(L"Default")),
|
||||
color(Color::Black, text(L"Black")),
|
||||
color(Color::GrayDark, text(L"GrayDark")),
|
||||
color(Color::GrayLight, text(L"GrayLight")),
|
||||
color(Color::White, text(L"White")),
|
||||
color(Color::Blue, text(L"Blue")),
|
||||
color(Color::BlueLight, text(L"BlueLight")),
|
||||
color(Color::Cyan, text(L"Cyan")),
|
||||
color(Color::CyanLight, text(L"CyanLight")),
|
||||
color(Color::Green, text(L"Green")),
|
||||
color(Color::GreenLight, text(L"GreenLight")),
|
||||
color(Color::Magenta, text(L"Magenta")),
|
||||
color(Color::MagentaLight, text(L"MagentaLight")),
|
||||
color(Color::Red, text(L"Red")),
|
||||
color(Color::RedLight, text(L"RedLight")),
|
||||
color(Color::Yellow, text(L"Yellow")),
|
||||
color(Color::YellowLight, text(L"YellowLight"))
|
||||
),
|
||||
vbox(
|
||||
bgcolor(Color::Default, text(L"Default")),
|
||||
bgcolor(Color::Black, text(L"Black")),
|
||||
bgcolor(Color::GrayDark, text(L"GrayDark")),
|
||||
bgcolor(Color::GrayLight, text(L"GrayLight")),
|
||||
bgcolor(Color::White, text(L"White")),
|
||||
bgcolor(Color::Blue, text(L"Blue")),
|
||||
bgcolor(Color::BlueLight, text(L"BlueLight")),
|
||||
bgcolor(Color::Cyan, text(L"Cyan")),
|
||||
bgcolor(Color::CyanLight, text(L"CyanLight")),
|
||||
bgcolor(Color::Green, text(L"Green")),
|
||||
bgcolor(Color::GreenLight, text(L"GreenLight")),
|
||||
bgcolor(Color::Magenta, text(L"Magenta")),
|
||||
bgcolor(Color::MagentaLight, text(L"MagentaLight")),
|
||||
bgcolor(Color::Red, text(L"Red")),
|
||||
bgcolor(Color::RedLight, text(L"RedLight")),
|
||||
bgcolor(Color::Yellow, text(L"Yellow")),
|
||||
bgcolor(Color::YellowLight, text(L"YellowLight"))
|
||||
)
|
||||
) | hcenter | border;
|
||||
// clang-format on
|
||||
return hbox({
|
||||
vbox({
|
||||
color(Color::Default, text(L"Default")),
|
||||
color(Color::Black, text(L"Black")),
|
||||
color(Color::GrayDark, text(L"GrayDark")),
|
||||
color(Color::GrayLight, text(L"GrayLight")),
|
||||
color(Color::White, text(L"White")),
|
||||
color(Color::Blue, text(L"Blue")),
|
||||
color(Color::BlueLight, text(L"BlueLight")),
|
||||
color(Color::Cyan, text(L"Cyan")),
|
||||
color(Color::CyanLight, text(L"CyanLight")),
|
||||
color(Color::Green, text(L"Green")),
|
||||
color(Color::GreenLight, text(L"GreenLight")),
|
||||
color(Color::Magenta, text(L"Magenta")),
|
||||
color(Color::MagentaLight, text(L"MagentaLight")),
|
||||
color(Color::Red, text(L"Red")),
|
||||
color(Color::RedLight, text(L"RedLight")),
|
||||
color(Color::Yellow, text(L"Yellow")),
|
||||
color(Color::YellowLight, text(L"YellowLight")),
|
||||
}),
|
||||
vbox({
|
||||
bgcolor(Color::Default, text(L"Default")),
|
||||
bgcolor(Color::Black, text(L"Black")),
|
||||
bgcolor(Color::GrayDark, text(L"GrayDark")),
|
||||
bgcolor(Color::GrayLight, text(L"GrayLight")),
|
||||
bgcolor(Color::White, text(L"White")),
|
||||
bgcolor(Color::Blue, text(L"Blue")),
|
||||
bgcolor(Color::BlueLight, text(L"BlueLight")),
|
||||
bgcolor(Color::Cyan, text(L"Cyan")),
|
||||
bgcolor(Color::CyanLight, text(L"CyanLight")),
|
||||
bgcolor(Color::Green, text(L"Green")),
|
||||
bgcolor(Color::GreenLight, text(L"GreenLight")),
|
||||
bgcolor(Color::Magenta, text(L"Magenta")),
|
||||
bgcolor(Color::MagentaLight, text(L"MagentaLight")),
|
||||
bgcolor(Color::Red, text(L"Red")),
|
||||
bgcolor(Color::RedLight, text(L"RedLight")),
|
||||
bgcolor(Color::Yellow, text(L"Yellow")),
|
||||
bgcolor(Color::YellowLight, text(L"YellowLight")),
|
||||
}),
|
||||
}) |
|
||||
hcenter | border;
|
||||
}
|
||||
};
|
||||
|
||||
class GaugeComponent : public Component {
|
||||
// clang-format off
|
||||
Element RenderGauge(int delta) {
|
||||
float progress = (shift + delta) % 1000 / 1000.f;
|
||||
return hbox(text(std::to_wstring(int(progress * 100)) + L"% ") | size(WIDTH, EQUAL, 5),
|
||||
gauge(progress));
|
||||
return hbox({
|
||||
text(std::to_wstring(int(progress * 100)) + L"% ") |
|
||||
size(WIDTH, EQUAL, 5),
|
||||
gauge(progress),
|
||||
});
|
||||
}
|
||||
Element Render() override {
|
||||
return
|
||||
vbox(
|
||||
RenderGauge(0) | color(Color::Black),
|
||||
RenderGauge(100) | color(Color::GrayDark),
|
||||
RenderGauge(50) | color(Color::GrayLight),
|
||||
RenderGauge(6894) | color(Color::White), separator(),
|
||||
RenderGauge(6841) | color(Color::Blue),
|
||||
RenderGauge(9813) | color(Color::BlueLight),
|
||||
RenderGauge(98765) | color(Color::Cyan),
|
||||
RenderGauge(98) | color(Color::CyanLight),
|
||||
RenderGauge(9846) | color(Color::Green),
|
||||
RenderGauge(1122) | color(Color::GreenLight),
|
||||
RenderGauge(84) | color(Color::Magenta),
|
||||
RenderGauge(645) | color(Color::MagentaLight),
|
||||
RenderGauge(568) | color(Color::Red),
|
||||
RenderGauge(2222) | color(Color::RedLight),
|
||||
RenderGauge(220) | color(Color::Yellow),
|
||||
RenderGauge(348) | color(Color::YellowLight)
|
||||
) | border;
|
||||
return vbox({
|
||||
RenderGauge(0) | color(Color::Black),
|
||||
RenderGauge(100) | color(Color::GrayDark),
|
||||
RenderGauge(50) | color(Color::GrayLight),
|
||||
RenderGauge(6894) | color(Color::White),
|
||||
separator(),
|
||||
RenderGauge(6841) | color(Color::Blue),
|
||||
RenderGauge(9813) | color(Color::BlueLight),
|
||||
RenderGauge(98765) | color(Color::Cyan),
|
||||
RenderGauge(98) | color(Color::CyanLight),
|
||||
RenderGauge(9846) | color(Color::Green),
|
||||
RenderGauge(1122) | color(Color::GreenLight),
|
||||
RenderGauge(84) | color(Color::Magenta),
|
||||
RenderGauge(645) | color(Color::MagentaLight),
|
||||
RenderGauge(568) | color(Color::Red),
|
||||
RenderGauge(2222) | color(Color::RedLight),
|
||||
RenderGauge(220) | color(Color::Yellow),
|
||||
RenderGauge(348) | color(Color::YellowLight),
|
||||
}) |
|
||||
border;
|
||||
};
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
class Tab : public Component {
|
||||
@@ -354,8 +360,11 @@ class Tab : public Component {
|
||||
}
|
||||
|
||||
Element Render() override {
|
||||
return vbox(text(L"FTXUI Demo") | bold | hcenter,
|
||||
tab_selection.Render() | hcenter, container.Render());
|
||||
return vbox({
|
||||
text(L"FTXUI Demo") | bold | hcenter,
|
||||
tab_selection.Render() | hcenter,
|
||||
container.Render(),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -33,18 +33,13 @@ class MyComponent : public Component {
|
||||
Input input_2;
|
||||
Input input_3;
|
||||
|
||||
// clang-format off
|
||||
Element Render() override {
|
||||
return
|
||||
border(
|
||||
vbox(
|
||||
hbox(text(L" input_1 : "), input_1.Render()),
|
||||
hbox(text(L" input_2 : "), input_2.Render()),
|
||||
hbox(text(L" input_3 : "), input_3.Render())
|
||||
)
|
||||
);
|
||||
return border(vbox({
|
||||
hbox({text(L" input_1 : "), input_1.Render()}),
|
||||
hbox({text(L" input_2 : "), input_2.Render()}),
|
||||
hbox({text(L" input_3 : "), input_3.Render()}),
|
||||
}));
|
||||
}
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
|
@@ -40,38 +40,39 @@ class MyComponent : public Component {
|
||||
Menu left_menu;
|
||||
Menu right_menu;
|
||||
|
||||
// clang-format off
|
||||
Element Render() override {
|
||||
int sum = left_menu.selected * 10 + right_menu.selected;
|
||||
return
|
||||
border(
|
||||
vbox(
|
||||
// -------- Top panel --------------
|
||||
hbox(
|
||||
// -------- Left Menu --------------
|
||||
vbox(
|
||||
hcenter(bold(text(L"Percentage by 10%"))),
|
||||
separator(),
|
||||
left_menu.Render()
|
||||
) | flex,
|
||||
// -------- Right Menu --------------
|
||||
vbox(
|
||||
hcenter(bold(text(L"Percentage by 1%"))),
|
||||
separator(),
|
||||
right_menu.Render()
|
||||
) | flex,
|
||||
filler()
|
||||
),
|
||||
separator(),
|
||||
// -------- Bottom panel --------------
|
||||
vbox(
|
||||
hbox(text(L" gauge : "), gauge(sum/100.0)),
|
||||
hbox(text(L" text : "), text(to_wstring(std::to_string(sum) + " %")))
|
||||
) | flex
|
||||
)
|
||||
);
|
||||
}
|
||||
// clang-format on
|
||||
Element Render() override {
|
||||
int sum = left_menu.selected * 10 + right_menu.selected;
|
||||
return border(vbox({
|
||||
// -------- Top panel --------------
|
||||
hbox({
|
||||
// -------- Left Menu --------------
|
||||
vbox({
|
||||
hcenter(bold(text(L"Percentage by 10%"))),
|
||||
separator(),
|
||||
left_menu.Render(),
|
||||
}) | flex,
|
||||
// -------- Right Menu --------------
|
||||
vbox({
|
||||
hcenter(bold(text(L"Percentage by 1%"))),
|
||||
separator(),
|
||||
right_menu.Render(),
|
||||
}) | flex,
|
||||
filler(),
|
||||
}),
|
||||
separator(),
|
||||
// -------- Bottom panel --------------
|
||||
vbox({
|
||||
hbox({
|
||||
text(L" gauge : "),
|
||||
gauge(sum / 100.0),
|
||||
}),
|
||||
hbox({
|
||||
text(L" text : "),
|
||||
text(to_wstring(std::to_string(sum) + " %")),
|
||||
}),
|
||||
}) | flex,
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
|
@@ -57,14 +57,14 @@ class MyComponent : public Component {
|
||||
// clang-format off
|
||||
Element Render() override {
|
||||
return
|
||||
hbox(
|
||||
hbox({
|
||||
menu_1.Render() | flex, separator(),
|
||||
menu_2.Render() | flex, separator(),
|
||||
menu_3.Render() | flex, separator(),
|
||||
menu_4.Render() | flex, separator(),
|
||||
menu_5.Render() | flex, separator(),
|
||||
menu_6.Render() | flex
|
||||
) | border;
|
||||
menu_6.Render() | flex,
|
||||
}) | border;
|
||||
}
|
||||
// clang-format on
|
||||
};
|
||||
|
@@ -38,19 +38,24 @@ class MyComponent : public Component {
|
||||
Toggle toggle_3_;
|
||||
Toggle toggle_4_;
|
||||
|
||||
// clang-format off
|
||||
Element Render() override {
|
||||
return
|
||||
vbox(
|
||||
return vbox({
|
||||
text(L"Choose your options:"),
|
||||
text(L""),
|
||||
hbox(text(L" * Poweroff on startup : "), toggle_1_.Render()),
|
||||
hbox(text(L" * Out of process : "), toggle_2_.Render()),
|
||||
hbox(text(L" * Price of the information : "), toggle_3_.Render()),
|
||||
hbox(text(L" * Number of elements : "), toggle_4_.Render())
|
||||
);
|
||||
hbox(text(L" * Number of elements : "), toggle_4_.Render()),
|
||||
});
|
||||
}
|
||||
|
||||
bool OnEvent(Event event) {
|
||||
if (event == Event::Return) {
|
||||
on_enter();
|
||||
return true;
|
||||
}
|
||||
return Component::OnEvent(event);
|
||||
}
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
|
Reference in New Issue
Block a user