d47081
(D47081)
January 28, 2025, 10:54am
1
I want to insert some icon from asset into the text buffer, by using insert_paintable .
It requires paintable implementation, but this code fails as paintable return NULL
(None
)
buffer.insert_paintable(
&mut buffer.end_iter(),
&Image::from_icon_name("user-available-symbolic")
.paintable()
.unwrap(), // fails
);
Can I use icon name with buffer, parse it or convert into the bytes array, or something else?
ebassi
(Emmanuele Bassi)
January 28, 2025, 11:03am
2
The paintable
accessor is only going to return you a Paintable
implementation if you set one; it will not turn any random data into a Paintable
.
If you want to load an icon and get a Paintable
back, use Gtk.IconTheme.lookup_icon()
.
1 Like
d47081
(D47081)
January 28, 2025, 11:16am
3
Thank you, this implementation works, but icon for some reasons not resolved:
buffer.insert_paintable(
&mut buffer.end_iter(),
&IconTheme::lookup_icon(
&IconTheme::default(),
"user-available-symbolic",
&[],
16,
16,
TextDirection::Ltr,
IconLookupFlags::FORCE_SYMBOLIC,
),
);
it looks like this:
The “user-available-symbolic” icon available in my system, suppose I forgot about something in lookup request…
d47081
(D47081)
January 28, 2025, 11:36am
4
Well, found the answer: I should define current Display just:
let display = Display::default();
let icon_theme = IconTheme::for_display(&display.unwrap()); // handle
buffer.insert_paintable(
&mut buffer.end_iter(),
&icon_theme.lookup_icon(
"user-available-symbolic",
&[],
16,
16,
TextDirection::None,
IconLookupFlags::FORCE_SYMBOLIC,
),
);
ebassi
(Emmanuele Bassi)
January 28, 2025, 11:40am
5
You cannot call GTK API without a display connection, which comes from calling gtk_init()
, either directly from an explicit call, or indirectly through GtkApplication
; if you’re not doing that, then you’re doing something appallingly wrong to begin with.
1 Like
d47081
(D47081)
January 28, 2025, 11:41am
6
Yes, sure - just forgot about that!
system
(system)
Closed
February 27, 2025, 11:41am
7
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.