Skip to content
Snippets Groups Projects
Verified Commit 7c3ce8e4 authored by Benny Baumann's avatar Benny Baumann
Browse files

add: Allow to sync UI interactions on any callable

parent 3d1ba2aa
No related branches found
No related tags found
No related merge requests found
#include <iostream>
#include "ui/View.h"
int main() {
auto ui_handle = std::make_shared<rmrf::ui::display>();
using rmrf::ui::display;
auto h_nc = std::make_shared<display>();
h_nc->sync([](const display::ptr_type &) {
std::cout << "Hello World!\n" << std::flush;
});
return 0;
}
-lncursesw
-lncursesw -pthread
......@@ -8,7 +8,7 @@
namespace rmrf::ui {
display::display() {
display::display() : m{} {
initscr();
}
......
#pragma once
#include <functional>
#include <memory>
#include <shared_mutex>
namespace rmrf::ui {
struct display : std::enable_shared_from_this<display> {
class display : public std::enable_shared_from_this<display> {
public:
typedef display self_type;
typedef std::shared_ptr<self_type> ptr_type;
private:
typedef std::shared_mutex mutex_type;
typedef std::lock_guard<mutex_type> lock_type;
mutable mutex_type m;
public:
display();
~display();
public:
template<typename F, typename ...Args>
decltype(auto) sync(F &&f, Args &&... args) {
lock_type lock(m);
return std::forward<F>(f)(shared_from_this(), std::forward<Args>(args)...);
}
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment