Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api/dotnet: Add internal Slint Runtime Library for .NET API #3913

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

microhobby
Copy link

Contributing back the work from https://github.com/microhobby/slint-dotnet

@CLAassistant
Copy link

CLAassistant commented Nov 12, 2023

CLA assistant check
All committers have signed the CLA.

@microhobby microhobby marked this pull request as draft November 12, 2023 18:06
@microhobby microhobby force-pushed the castello/dotnet branch 3 times, most recently from c089b73 to ba3353f Compare November 13, 2023 04:08
@ogoffart
Copy link
Member

Thanks a lot for the PR! 🤩.
Unfortunately I'm traveling this week so it'll take a bit of time before I can spend enough time to review it.

As for the CI errors: the problems on the mac about the new headers can be ignored. This is a temporary failure.
The problem with the license header in the docs we can adjust the license check to accept it.

The problem in rnet about transmute of TypeId seems more worrisome. TypeId changed its size a few rust version ago. So this seems to be a problem in the rnet crate.

@microhobby
Copy link
Author

microhobby commented Nov 13, 2023

@ogoffart

Thanks a lot for the PR! 🤩. Unfortunately I'm traveling this week so it'll take a bit of time before I can spend enough time to review it.

As for the CI errors: the problems on the mac about the new headers can be ignored. This is a temporary failure. The problem with the license header in the docs we can adjust the license check to accept it.

It's ok, I will remove my, I'm ok to be a Slint Developer 😄

The problem in rnet about transmute of TypeId seems more worrisome. TypeId changed its size a few rust version ago. So this seems to be a problem in the rnet crate.

yeah, this one also got me because I do not check first on the project and appears to be abandoned. I will engage with the maintainer to see the status. Thanks

@microhobby
Copy link
Author

Ok, the stable has been passed, but you guys are also compiling it against the v1.70. I need to also check this.

@microhobby
Copy link
Author

ok, now all working as expected. I need to work now on the .NET C# specific stuff.


let mut ret: Vec<DotNetValue> = Vec::new();

CURRENT_INSTANCE.with(|current| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of thread locals is something I find worth improving. It would be better if the instance could be wrapped in an opaque type and become a parameter to all the functions (and return value for the initial loading).

As far as I can see rnet support Box and Arc wrapped types. Is this something you’d like to pursue?

crate-type = ["lib", "cdylib", "staticlib"]

[dependencies]
async-std = { version = "1.10.0" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use the more lightweight spin-on crate for this (block_on). We use that in other places as well.

@tronical
Copy link
Member

For the record: while there's a lot that can be done (thread local, CI, etc) , I'd be fine if we decide to take this in early and incrementally improve.

Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just went quickly through the code and made some comments.
As simon said, I don't think it needs to be perfect to be merged, and we can iterate over it within the master branch as beta.
But even in the beta stage, this is not so useful without the C# code and some C# examples/docs.
So perhaps this should be added at the same time.

// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial

fn main() {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to have a build.rs file if it doesn't do anything. (just need to be removed from Cargo.toml as well

Comment on lines +4 to +16
use std::{path::Path, time::Duration};

use rnet::{net, Delegate0, Net};

use i_slint_core::api::{ComponentHandle, Weak};

use i_slint_core::graphics::Image;

use i_slint_core::timers::{Timer, TimerMode};

use slint_interpreter::{ComponentInstance, Value, ValueType};

use i_slint_compiler::langtype::Type;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: IMHO it would looks better without all the new line.

Comment on lines +568 to +577
// reject modernity, back to the monke
let weak_ref = unsafe { MAIN_WEAK_INSTANCE.take().unwrap() };
unsafe {
MAIN_WEAK_INSTANCE = Some(weak_ref.clone());
};

weak_ref
.upgrade_in_event_loop(move |_| {
callback.call();
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use slint_interpreter::invoke_from_event_loop , no need to have a weak_ref. That way you can get rid of this MAIN_WEAK_INSTANCE entirely


rnet::root!();

macro_rules! printdebug {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to keep this macro in released code?


let m_calls = ret_handle.callbacks().collect();

let tokens = Tokens { props: m_props, calls: m_calls };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably keep the ret_handle instead of letting it go out of scope.

pub fn interprete(path: &str) -> Tokens {
let mut compiler = slint_interpreter::ComponentCompiler::default();
let path = std::path::Path::new(path);
let ret_handle = async_std::task::block_on(compiler.build_from_path(path)).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of unwrap and panic, we should return an error to the caller.

let val_type;
let mut val_struct = false;
let mut val_props = Vec::new();
let val_val = format!("{:?}", "");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that just "".to_string or String::new()?

Comment on lines +77 to +79
for prop in props {
let p_name = prop.0;
let p_type = prop.1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style suggestion:

Suggested change
for prop in props {
let p_name = prop.0;
let p_type = prop.1;
for (p_name, p_type) in props {

@Vadoola Vadoola mentioned this pull request Dec 21, 2023
@ogoffart ogoffart linked an issue Jan 15, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

C# binding
4 participants