mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 02:39:28 +00:00
C++: fix string to float so that it doesn't depends on the current locale
This commit is contained in:
parent
8996948fd1
commit
5c3732c74e
2 changed files with 19 additions and 6 deletions
|
@ -9,6 +9,7 @@ extern crate alloc;
|
|||
use alloc::rc::Rc;
|
||||
use core::ffi::c_void;
|
||||
use i_slint_core::window::{ffi::WindowAdapterRcOpaque, WindowAdapter};
|
||||
use i_slint_core::SharedString;
|
||||
|
||||
pub mod platform;
|
||||
|
||||
|
@ -100,8 +101,8 @@ pub unsafe extern "C" fn slint_quit_event_loop() {
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn slint_register_font_from_path(
|
||||
win: *const WindowAdapterRcOpaque,
|
||||
path: &i_slint_core::SharedString,
|
||||
error_str: *mut i_slint_core::SharedString,
|
||||
path: &SharedString,
|
||||
error_str: *mut SharedString,
|
||||
) {
|
||||
let window_adapter = &*(win as *const Rc<dyn WindowAdapter>);
|
||||
core::ptr::write(
|
||||
|
@ -119,7 +120,7 @@ pub unsafe extern "C" fn slint_register_font_from_path(
|
|||
pub unsafe extern "C" fn slint_register_font_from_data(
|
||||
win: *const WindowAdapterRcOpaque,
|
||||
data: i_slint_core::slice::Slice<'static, u8>,
|
||||
error_str: *mut i_slint_core::SharedString,
|
||||
error_str: *mut SharedString,
|
||||
) {
|
||||
let window_adapter = &*(win as *const Rc<dyn WindowAdapter>);
|
||||
core::ptr::write(
|
||||
|
@ -140,6 +141,17 @@ pub unsafe extern "C" fn slint_register_bitmap_font(
|
|||
window_adapter.renderer().register_bitmap_font(font_data);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn slint_string_to_float(string: &SharedString, value: &mut f32) -> bool {
|
||||
match string.as_str().parse::<f32>() {
|
||||
Ok(v) => {
|
||||
*value = v;
|
||||
true
|
||||
}
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
mod allocator {
|
||||
use core::alloc::Layout;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue