limikael / appy

Declarative UI framework in Rust
MIT License
66 stars 2 forks source link

refactor text system #9

Closed limikael closed 1 year ago

limikael commented 1 year ago

The vision is to have a use_font hook. so it would be like:

#[function_component]
fn my_comp(p: MyProps, c:Elements)->Elements {
  let f=use_font(FontSpec::new("thefont").size(10).charset(Charset::Ascii));
  f.get_line_width("blabla") // the with of a line of text
  f.get_paragraph_height("blasdf\nasdfasf",100) // the height of a paragraph, if fit into a width of 100

  apx!{
    <text text="hello" font=f/>
  }
}

currently there is a gpu cache thingy, but it doesn't work well at all. look at:

limikael commented 1 year ago

The gpu cache wasn't that bad, it just needs to update its size dynamically, which it now does...

The syntax for using fonts:


#[function_component]
fn my_comp(p: MyProps, c:Elements)->Elements {
    let f=use_font_data(||include_bytes!("./thefont.ttf"));
    f.get_str_width("blabla",10) // the with of a line of text

    apx!{
       <text text="hello" font=f size=Dp(10.0)/>
    }
}```