Skip to content

Commit

Permalink
directvt#393 WIP: Move plugins to ui::base
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Jan 3, 2025
1 parent 58a9210 commit 5df22f1
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 125 deletions.
3 changes: 2 additions & 1 deletion src/netxs/apps/desk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,8 @@ namespace netxs::app::desk
{
usrcfg.win = {};
usrcfg.gear_id = seed.gear_id;
boss.base::riseup(tier::release, scripting::events::invoke, usrcfg);
//todo scripting
//boss.base::riseup(tier::release, scripting::events::invoke, usrcfg);
oneshot->reset();
};
};
Expand Down
5 changes: 3 additions & 2 deletions src/netxs/desktopio/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "console.hpp"
#include "system.hpp"
#include "scripting.hpp"
//#include "scripting.hpp"
#include "gui.hpp"

#include <fstream>
Expand Down Expand Up @@ -781,7 +781,8 @@ namespace netxs::app::shared
{
app::shared::splice(client, gui_config);
}};
auto domain = ui::host::ctor(server, config)->plugin<scripting::host>();
//todo scripting
auto domain = ui::host::ctor(server, config);// ->plugin<scripting::host>();
auto appcfg = eccc{ .cmd = cmd };
auto applet = app::shared::builder(aclass)(appcfg, config);
config_lock.unlock();
Expand Down
25 changes: 25 additions & 0 deletions src/netxs/desktopio/baseui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ namespace netxs::ui
{
using e2 = netxs::events::userland::e2;

// controls: UI extensions.
namespace pro
{
struct skill;
}

//todo reimplement
struct skin
{
Expand Down Expand Up @@ -578,6 +584,7 @@ namespace netxs::ui
bool locked; // base: Object has fixed size.
bool master; // base: Anycast root.
si32 family; // base: Object type.
std::map<std::type_index, uptr<pro::skill>> depo;

template<class T = base>
auto This() { return std::static_pointer_cast<std::remove_reference_t<T>>(shared_from_this()); }
Expand Down Expand Up @@ -889,6 +896,24 @@ namespace netxs::ui
base::intpad = new_intpad;
base::extpad = new_extpad;
}
// base: Detach the specified plugin.
template<class S>
void unplug()
{
depo.erase(std::type_index(typeid(S)));
}
// base: Return a reference to a plugin of the specified type. Create an instance of the specified plugin (using the specified arguments) if it does not exist.
template<class S, class ...Args>
auto& plugin(Args&&... args)
{
auto it = depo.find(std::type_index(typeid(S)));
if (it == depo.end())
{
it = depo.emplace(std::type_index(typeid(S)), std::make_unique<S>(*this, std::forward<Args>(args)...)).first;
}
auto ptr = static_cast<S*>(it->second.get());
return *ptr;
}
// base: Render to the canvas. Trim = trim viewport to the nested object region.
template<bool Forced = faux>
void render(face& canvas, bool trim = true, bool pred = true, bool post = true)
Expand Down
17 changes: 8 additions & 9 deletions src/netxs/desktopio/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ namespace netxs::ui

public:
pipe& canal; // gate: Channel to outside.
props_t props; // gate: Application properties.
props_t props; // gate: Input gate properties.
diff paint; // gate: Render.
link conio; // gate: Input data parser.
bool direct; // gate: .
Expand Down Expand Up @@ -557,6 +557,13 @@ namespace netxs::ui
}
return std::pair{ id_t{}, netxs::sptr<hids>{} };
}
id_t get_int_gear_id(id_t ext_gear_id)
{
auto int_gear_id = id_t{};
auto gear_it = gears.find(ext_gear_id);
if (gear_it != gears.end()) int_gear_id = gear_it->second->id;
return int_gear_id;
}
void draw_foreign_names(face& parent_canvas)
{
auto& header = *uname.lyric;
Expand Down Expand Up @@ -660,14 +667,6 @@ namespace netxs::ui
if (result) base::strike();
}

// gate: .
id_t get_int_gear_id(id_t ext_gear_id)
{
auto int_gear_id = id_t{};
auto gear_it = gears.find(ext_gear_id);
if (gear_it != gears.end()) int_gear_id = gear_it->second->id;
return int_gear_id;
}
// gate: Attach a new item.
auto attach(sptr& item)
{
Expand Down
29 changes: 10 additions & 19 deletions src/netxs/desktopio/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2886,7 +2886,6 @@ namespace netxs::ui
class form
: public base
{
std::map<std::type_index, uptr<pro::skill>> depo;
std::map<id_t, subs> memomap; // form: Token set for dependent subscriptions.

public:
Expand All @@ -2897,33 +2896,25 @@ namespace netxs::ui
auto item = ui::tui_domain().template create<TT>(std::forward<Args>(args)...);
return item;
}
// form: Attach feature and return itself.
// form: Attach a plugin of the specified type and return self.
template<class S, class ...Args>
auto plugin(Args&&... args)
{
auto backup = This();
depo[std::type_index(typeid(S))] = std::make_unique<S>(*backup, std::forward<Args>(args)...);
return backup;
base::plugin<S>(std::forward<Args>(args)...);
return This();
}
// form: Detach feature and return itself.
// form: Detach the specified plugin and return self.
template<class S>
auto unplug()
{
auto backup = This();
depo.erase(std::type_index(typeid(S)));
return backup;
base::unplug<S>();
return This();
}
// form: Return plugin reference of specified type. Add the specified plugin (using specified args) if it is missing.
template<class S, class ...Args>
auto& plugins(Args&&... args)
{
auto it = depo.find(std::type_index(typeid(S)));
if (it == depo.end())
{
it = depo.emplace(std::type_index(typeid(S)), std::make_unique<S>(*this, std::forward<Args>(args)...)).first;
}
auto ptr = static_cast<S*>(it->second.get());
return *ptr;
return base::plugin<S>(std::forward<Args>(args)...);
}
// form: Fill object region using parametrized fx.
template<auto Tier = tier::release, auto RenderOrder = e2::render::background::any, class Fx, class Event = noop, bool fixed = std::is_same_v<Event, noop>>
Expand Down Expand Up @@ -2963,7 +2954,7 @@ namespace netxs::ui
}
return This();
}
// form: deprecated in favor of pro::brush. Set colors and return itself.
// form: deprecated in favor of pro::brush. Set colors and return self.
template<class ...Args>
auto colors(Args&&... args)
{
Expand All @@ -2987,15 +2978,15 @@ namespace netxs::ui
{
return active(base::color());
}
// form: Invoke arbitrary functor(itself/*This/boss) in place.
// form: Invoke an arbitrary functor(self/*This/boss) in place.
template<class P>
auto invoke(P functor)
{
auto backup = This();
functor(*backup);
return backup;
}
// form: Attach homeless branch and return itself.
// form: Attach a homeless branch and return self.
template<class ...Args>
auto branch(Args&&... args)
{
Expand Down
8 changes: 5 additions & 3 deletions src/vtm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ int main(int argc, char* argv[])
using e2 = ui::e2;
auto config_lock = ui::tui_domain().unique_lock(); // Sync multithreaded access to config.
auto domain = ui::host::ctor<app::vtm::hall>(server, config);
domain->plugin<scripting::host>();
//todo scripting
//domain->plugin<scripting::host>();
domain->autorun();
auto settings = config.utf8();
config_lock.unlock();
Expand All @@ -474,7 +475,8 @@ int main(int argc, char* argv[])
if (active)
{
onecmd.cmd = cmd;
domain->bell::signal(tier::release, scripting::events::invoke, onecmd);
//todo scripting
//domain->bell::signal(tier::release, scripting::events::invoke, onecmd);
}
else
{
Expand Down Expand Up @@ -503,7 +505,7 @@ int main(int argc, char* argv[])
}
}};

auto execline = [&](qiew line){ domain->bell::signal(tier::release, scripting::events::invoke, { .cmd = line }); };
auto execline = [&](qiew /*line*/) { /*domain->bell::signal(tier::release, scripting::events::invoke, {.cmd = line});*/ }; //todo scripting
auto shutdown = [&]{ domain->bell::signal(tier::general, e2::shutdown, utf::concat(prompt::main, "Shutdown on signal")); };
execline(script);
auto readline = os::tty::readline(execline, shutdown);
Expand Down
Loading

0 comments on commit 5df22f1

Please sign in to comment.