From cdb2a729945057529deaea69e60b9c01bfd4c7c3 Mon Sep 17 00:00:00 2001 From: Dmitry Sapozhnikov Date: Mon, 12 Apr 2021 20:46:32 +0500 Subject: [PATCH] UI: refactoring --- src/netxs/console/console.hpp | 1 + src/netxs/ui/controls.hpp | 18 +++++-- src/vtmd.cpp | 97 +++++++++++++++++------------------ 3 files changed, 61 insertions(+), 55 deletions(-) diff --git a/src/netxs/console/console.hpp b/src/netxs/console/console.hpp index 4a938c5394..f4c35cd229 100644 --- a/src/netxs/console/console.hpp +++ b/src/netxs/console/console.hpp @@ -1655,6 +1655,7 @@ namespace netxs::console auto plugin(Args&&... args) { plugins.emplace_back(std::make_unique>(boss, std::forward(args)...)); + boss.base::reflow(); return boss.template This(); } template diff --git a/src/netxs/ui/controls.hpp b/src/netxs/ui/controls.hpp index 11aefc6656..8035c9bf7d 100644 --- a/src/netxs/ui/controls.hpp +++ b/src/netxs/ui/controls.hpp @@ -831,15 +831,15 @@ namespace netxs::ui } } // fork: Create a new item of the specified subtype and attach it to a specified slot. - template - auto attach(slot client_slot, Args&&... args) + template + auto attach(Args&&... args) { static_assert(std::is_base_of::value, "The only a derivative of the «base» class can be attached to the «mold»."); auto item = create(std::forward(args)...); - if (client_slot == slot::_1) client_1 = item; - else client_2 = item; + if (SLOT == slot::_1) client_1 = item; + else client_2 = item; item->SIGNAL(e2::release, e2::form::upon::attached, This()); // Send creator base::reflow(); // Ask the client about the new size (the client can override the size) @@ -1935,7 +1935,7 @@ namespace netxs::ui subs tokens{}; // pads: Subscriptions on client moveto and resize. bool locked{}; // pads: Client is under resizing. -public: + public: sptr client; pads(dent const& padding_value = {}, dent const& margins_value = {}) : boost{*this }, @@ -2000,6 +2000,14 @@ namespace netxs::ui } }; + // controls: Pluggable dummy object. + class mock + : public base, public pro::boost + { + public: + mock() : boost{*this } { }; + }; + // controls: Menu controller. class menu : public base diff --git a/src/vtmd.cpp b/src/vtmd.cpp index 22b5c3ea8d..5478bf889f 100644 --- a/src/vtmd.cpp +++ b/src/vtmd.cpp @@ -1,9 +1,9 @@ // Copyright (c) NetXS Group. // Licensed under the MIT license. -#define DEMO +//#define DEMO #define MONOTTY_VER "Monotty Desktopio Preview v0.3.3" -//#define PROD +#define PROD // Terminal's default line wrapping mode. #define WRAPPING (wrap::on) @@ -1328,20 +1328,20 @@ utility like ctags is used to locate the definitions. auto scroll_bars = [](auto layers, auto master) { auto scroll_bars = layers->template attach(); - auto scroll_down = scroll_bars->template attach(fork::_1, fork::vertical); - auto hz = scroll_down->template attach>(fork::_2, master); - auto vt = scroll_bars->template attach>(fork::_2, master); + auto scroll_down = scroll_bars->template attach(fork::vertical); + auto hz = scroll_down->template attach>(master); + auto vt = scroll_bars->template attach>(master); }; auto scroll_bars_term = [](auto layers, auto master) { auto scroll_bars = layers->template attach(); - auto scroll_head = scroll_bars->template attach(fork::_1, fork::vertical); - auto hz = scroll_head->template attach>(fork::_1, master); - auto vt = scroll_bars->template attach>(fork::_2, master); + auto scroll_head = scroll_bars->template attach(fork::vertical); + auto hz = scroll_head->template attach>(master); + auto vt = scroll_bars->template attach>(master); }; auto main_menu = [](auto master) { - auto menu_area = master->template attach(fork::_1); + auto menu_area = master->template attach(); auto inner_pads = dent{ -1,-2,-1,-1 }; auto menu_items = { std::pair{ " ≡"s, dent{ 0 } }, @@ -1351,13 +1351,13 @@ utility like ctags is used to locate the definitions. std::pair{ ansi::und(true) + "D" + ansi::nil() + "ata", dent{ -1 } } }; auto c2 = cell{ whitespace }.bgc(tint::bluelt); auto c1 = c2; c1.alpha(0x00); - auto menu_list = menu_area->template attach(fork::_1) - ->template attach(fork::_1, faux); + auto menu_list = menu_area->template attach() + ->template attach(faux); for (auto& body : menu_items) menu_list->template attach(inner_pads, body.second) ->template plugin() ->template plugin(c1, c2, 150ms) ->template attach(body.first); - menu_area->template attach(fork::_2, dent{ -2,-2,-1,-1 }, dent{}) + menu_area->template attach(dent{ -2,-2,-1,-1 }, dent{}) ->template plugin() ->template plugin(c1, c2, 150ms) ->template attach(ansi::und(true) + "H" + ansi::nil() + "elp"); @@ -1509,11 +1509,11 @@ utility like ctags is used to locate the definitions. auto object = window ->attach(fork::vertical) ->plugin(whitelt, 0); - object->attach(fork::_1) + object->attach() ->plugin(twod{ 37,-1 }, twod{ -1,-1 }) ->upload(appstore_head); - auto layers = object->attach(fork::_2); + auto layers = object->attach(); auto scroll = layers ->attach() ->plugin(whitedk, 0xFF0f0f0f) @@ -1542,7 +1542,8 @@ utility like ctags is used to locate the definitions. case Cellatix: case Calc: { - /* Calc Interface Layout + //todo XAML converter + /* Calc Interface Layout (a bit outdated) * * window:mold * object:fork_v @@ -1578,47 +1579,38 @@ utility like ctags is used to locate the definitions. ->attach(fork::vertical) ->plugin(whitelt, 0); main_menu(object); - auto c2 = cell{ whitespace }.fgc(whitelt).bgc(tint::bluelt); auto c1 = cell{ whitespace }.fgc(blackdk).bgc(whitedk); auto c0 = c2; c0.alpha(0x00); - auto all_stat = object->attach(fork::_2, fork::vertical); - auto func_body_pad = all_stat->attach(fork::_1, dent { -1,-1 }) + auto all_stat = object->attach(fork::vertical); + auto func_body_pad = all_stat->attach(dent { -1,-1 }) ->plugin(); auto func_body = func_body_pad->attach(fork::vertical); - auto func_line = func_body->attach(fork::_1); - auto fx_sum = func_line->attach(fork::_1); - auto fx = fx_sum->attach(fork::_1) + auto func_line = func_body->attach(); + auto fx_sum = func_line->attach(); + auto fx = fx_sum->attach() ->plugin() ->plugin(c1, c2, 150ms) ->plugin(twod{ 3,-1 }, twod{ 4,-1 }) ->upload(ansi::wrp(wrap::off) + " Fx "); - auto sum = fx_sum->attach(fork::_2) + auto sum = fx_sum->attach() ->plugin(0, whitelt) ->upload(ansi::bgc(whitelt).fgc(blacklt) + " =SUM(B1:B10) "); - auto ellipsis = func_line->attach(fork::_2) + auto ellipsis = func_line->attach() ->plugin() ->plugin(c1, c2, 150ms) ->plugin(twod{ -1,1 }, twod{ 3,-1 }) ->upload(ansi::wrp(wrap::off) + " ⋯ "); - auto body_area = func_body->attach(fork::_2, fork::vertical); - auto corner_cols = body_area->attach(fork::_1); - auto corner = corner_cols->attach(fork::_1) + auto body_area = func_body->attach(fork::vertical); + auto corner_cols = body_area->attach(); + auto corner = corner_cols->attach() ->plugin(twod{ 4,1 }, twod{ 4,1 }) ->upload(ansi::bgc(0xffffff - 0x1f1f1f).fgc(0) + " "); - auto cols_area = corner_cols->attach(fork::_2, axes::ONLY_X, axes::ONLY_X); - auto cols = cols_area->attach() - ->plugin(twod{ -1,1 }, twod{ -1,1 }) - ->upload(cellatix_cols); // A B C ... - auto rows_body = body_area->attach(fork::_2); - auto rows_area = rows_body->attach(fork::_1, axes::ONLY_Y, axes::ONLY_Y) - ->plugin(twod{ 4,-1 }, twod{ 4,-1 }); - auto rows = rows_area->attach() - ->upload(cellatix_rows); // " 1 \n 2 \n 3 \n" - auto layers = rows_body->attach(fork::_2); + auto rows_body = body_area->attach(); + auto layers = rows_body->attach(); auto scroll = layers->attach() ->plugin(twod{ -1,1 }, twod{ -1,-1 }) ->config(true, true); @@ -1626,29 +1618,35 @@ utility like ctags is used to locate the definitions. ->plugin() ->plugin(0xFF000000, 0xFFffffff) ->upload(cellatix_text); - auto stat_area = all_stat->attach(fork::_2) + auto cols_area = corner_cols->attach(axes::ONLY_X, axes::ONLY_X) + ->follow(scroll); + auto cols = cols_area->attach() + ->plugin(twod{ -1,1 }, twod{ -1,1 }) + ->upload(cellatix_cols); //todo grid A B C ... + auto rows_area = rows_body->attach(axes::ONLY_Y, axes::ONLY_Y) + ->follow(scroll) + ->plugin(twod{ 4,-1 }, twod{ 4,-1 }); + auto rows = rows_area->attach() + ->upload(cellatix_rows); //todo grid 1 \n 2 \n 3 \n ... + auto stat_area = all_stat->attach() ->plugin(twod{ -1,1 }, twod{ -1,1 }) ->locate(-5); auto sheet_plus = stat_area->attach(); - auto sheet = sheet_plus->attach(fork::_1) + auto sheet = sheet_plus->attach() ->plugin(twod{ -1,-1 }, twod{ 13,-1 }) ->upload(ansi::wrp(wrap::off) + " " + ansi::bgc(whitelt).fgc(blackdk) + " Sheet1 "); - auto plus_pad = sheet_plus->attach(fork::_2); - auto plus = plus_pad->attach(fork::_1) + auto plus_pad = sheet_plus->attach(); + auto plus = plus_pad->attach() ->plugin() ->plugin(c1, c2, 150ms) ->plugin(twod{ 2,-1 }, twod{ 2,-1 }) ->upload(ansi::wrp(wrap::off) + "+"); - auto pad = plus_pad->attach(fork::_2) //todo use dummy instead of post - ->plugin(twod{ 1,1 }, twod{ 1,1 }) - ->upload(ansi::wrp(wrap::off) - + " "); - cols_area->follow(scroll); - rows_area->follow(scroll); + auto pad = plus_pad->attach() + ->plugin(twod{ 1,1 }, twod{ 1,1 }); scroll_bars(layers, scroll); break; } @@ -1660,15 +1658,14 @@ utility like ctags is used to locate the definitions. window->blurred = true; window->highlight_center = faux; window->set_border(dot_00); - auto object = window ->attach(fork::vertical) ->plugin(whitelt, 0); main_menu(object); auto body_area = object - ->attach(fork::_2, fork::vertical); + ->attach(fork::vertical); auto fields = body_area - ->attach(fork::_1, dent{ -1,-1 }) + ->attach(dent{ -1,-1 }) ->plugin(); auto layers = fields ->attach(); @@ -1685,7 +1682,7 @@ utility like ctags is used to locate the definitions. + ansi::fgc(bluedk) + "From Wikipedia, the free encyclopedia"); auto status_line = body_area - ->attach(fork::_2) + ->attach() ->plugin(twod{ 1,1 }, twod{ -1,1 }) ->upload(ansi::wrp(wrap::off).mgl(1).mgr(1).jet(bias::right).fgc(whitedk) + "INS Sel: 0:0 Col: 26 Ln: 2/148" + ansi::nil());