Trouble creating a Pango Layout

Using Rust and GTK
I’m trying to draw some test in a DrawingArea. The call back to the draw function passes me a Cairo context but when trying to create a Pango Layout, I find I have the wrong Context.

        let layout = pangocairo::create_layout(cr).expect("Failed to create Pango layout");

I have a gtk::cairo::Context, but the function takes a cairo::cairo::Context

I feel there must be a different way to do this but I haven’t been able to find anything.

You need to use GTK to create the PangoLayout: WidgetExt in gtk4::prelude - Rust

This will take care of using the correct pango context, with the appropriate font options.


That worked fine. I now have

 let layout = drawing_area.create_pango_layout(Some(&text));

My problem now is I can’t find any way to actually get the layout to paint in the drawing area.
The examples I have found use something of the form pc_ctx.show_layout(pc_layout) but I can’t find any methods like that.
I’m completely puzzled once again.

Also, should I bu using the pango crate or the pangocairo crate?

I have abandoned using pango. No doc & no examples that work just makes it too difficult.
Just using “Toy” text cr.show_text(&text);

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.