You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new to Rust so this might be a basic problem. I couldn't find an example of MeasureFuncs in stretch.
I'm trying to create a text leaf node. I wrote a font loading mechanism which returns Font, and I wrote a basic text layout algorithm which takes a borrow to Font (lets call this function layout(in_bounds: Size<Number>, f: &Font) -> Size<f32>, where the returned vector is the bounds of the text. It also takes the bounds where we should layout text into). I'd like to be able to call this layout function inside the MeasureFunc, but no matter what I try it says font does not live long enough. borrowed value does not live long enough.
let mut stretch = stretch::node::Stretch::new();
let font = load_font(...);
let text_node = stretch.new_leaf(
Style { ..Default::default() },
Box::new(|size|{
Ok(layout(size, &f))
})).unwrap();
stretch.compute_layout(text_node, Size{ width: Number::Defined(500), height: Number::Undefined }).unwrap();
I tried boxing and Rc-ing the font with no luck.
let mut stretch = stretch::node::Stretch::new();
let font = load_font(...);
let rc_font = Rc::new(font);
let text_node = stretch.new_leaf(
Style { ..Default::default() },
Box::new(|size|{
Ok(layout(size, rc_font.as_ref()))
})).unwrap();
stretch.compute_layout(text_node, Size{ width: Number::Defined(500), height: Number::Undefined }).unwrap();
What's the proper way to do this? An example of this in the future would be immensely useful!
The text was updated successfully, but these errors were encountered:
I'm new to Rust so this might be a basic problem. I couldn't find an example of MeasureFuncs in stretch.
I'm trying to create a text leaf node. I wrote a font loading mechanism which returns
Font
, and I wrote a basic text layout algorithm which takes a borrow toFont
(lets call this functionlayout(in_bounds: Size<Number>, f: &Font) -> Size<f32>
, where the returned vector is the bounds of the text. It also takes the bounds where we should layout text into). I'd like to be able to call thislayout
function inside the MeasureFunc, but no matter what I try it saysfont does not live long enough. borrowed value does not live long enough
.I tried boxing and Rc-ing the font with no luck.
What's the proper way to do this? An example of this in the future would be immensely useful!
The text was updated successfully, but these errors were encountered: