sergrt
Topic Author
Posts: 2
Joined: 02 Feb 2021, 19:37

UI modifications using ApplicationFramework

06 Feb 2021, 20:53

Hello.

I am new to NoesisGUI, and taking first steps trying to mate NoesisGUI with RxCpp. I modified Rss example - made a window with ListBox, and trying to insert items based on some data. Actual code is below:
const std::string content = /*some content*/;
if (auto list_box = FindName<ListBox>("listBox")) {
    auto item = new ListBoxItem();
    item->SetContent(content.c_str());
    if (auto items = list_box->GetItems()) {
        items->Insert(0, item);
    }
}
As far as I modified existing example code, I use ApplicationFramework, and from time to time I get application crash in this function:
void Window::Render(double time)

And also output console full of messages like these:
[NOESIS/E] The calling thread (26264) cannot access this object (RssReader.MainWindow) because a different thread owns it (31924)
[NOESIS/E] The calling thread (26264) cannot access this object (ListBox) because a different thread owns it (31924)
Obviously I do something wrong with threads, like inserting items from another thread, which is not the way it should be done. Could anyone tell me is it possible to implement UI modifications somewhere in the UI thread loop - using ApplicationFramework, or I need to write my own loop from scratch?

Tags:
 
sergrt
Topic Author
Posts: 2
Joined: 02 Feb 2021, 19:37

Re: UI modifications using ApplicationFramework

07 Feb 2021, 13:51

In case anyone with similar question ever stumbles upon this post:
It seems that the easiest way to do this (since ApplicationFramework source code is available) - to inject rxcpp::schedulers::run_loop to the Display implementation (in my case it is Win32Display class). I ended up with the following code:
/* rlp_ is a shared_ptr<rxcpp::schedulers::run_loop>, created on main thread on application start and provided via DisplayLauncher::Run */

if (rlp_ && !rlp_->empty() && rlp_->peek().when < rlp_->now())
    rlp_->dispatch();
And inserted it right before calling
mRender(this);
UI-manipulating subscriptions should be made using observe_on like this:
auto ui_thread = rxcpp::observe_on_run_loop(*rlp_);
observable.observe_on(ui_thread).subscribe(func);
 
User avatar
sfernandez
Site Admin
Posts: 2254
Joined: 22 Dec 2011, 19:20

Re: UI modifications using ApplicationFramework

08 Feb 2021, 10:13

Hi, as you found a Noesis View and its UI elements can only be modified from the same thread where the view was created.
Thanks for sharing your integration with RxCpp, I'm sure some people may find it useful.

Who is online

Users browsing this forum: No registered users and 2 guests