- Notifications
You must be signed in to change notification settings - Fork 663
api/dotnet: Add internal Slint Runtime Library for .NET API #3913
New issue
Have a question about this project? Sign up for a free account to open an issue and contact its maintainers and the community.
By clicking “Sign up for ”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on ? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
c089b73
to ba3353f
Compare Thanks a lot for the PR! 🤩. As for the CI errors: the problems on the mac about the new headers can be ignored. This is a temporary failure. 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. |
It's ok, I will remove my, I'm ok to be a Slint Developer 😄
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 |
ba3353f
to 5d09110
Compare Ok, the stable has been passed, but you guys are also compiling it against the |
Signed-off-by: Matheus Castello <[email protected]>
5d09110
to c686769
Compare 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| { |
There was a problem hiding this comment.
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" } |
There was a problem hiding this comment.
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.
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. |
There was a problem hiding this 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() {} |
There was a problem hiding this comment.
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
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; |
There was a problem hiding this comment.
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.
// 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(); | ||
}) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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!("{:?}", ""); |
There was a problem hiding this comment.
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()
?
for prop in props { | ||
let p_name = prop.0; | ||
let p_type = prop.1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style suggestion:
for prop in props { | |
let p_name = prop.0; | |
let p_type = prop.1; | |
for (p_name, p_type) in props { |
Contributing back the work from https://.com/microhobby/slint-dotnet