add filename image support

This commit is contained in:
yggverse 2024-07-24 19:01:56 +03:00
parent 80766fb62c
commit 4f6445d167

View file

@ -65,15 +65,39 @@ abstract class Button
int $size = \GtkIconSize::BUTTON int $size = \GtkIconSize::BUTTON
): void ): void
{ {
if (\GtkIconTheme::get_default()->has_icon($image)) switch (true)
{ {
$this->gtk->set_image( case file_exists(
\GtkImage::new_from_icon_name( $image
$image, ) && is_readable(
$size $image
) ):
);
} else throw new \Exception; $this->gtk->set_image(
\GtkImage::new_from_file(
$image,
$size
)
);
break;
case \GtkIconTheme::get_default()->has_icon(
$image
):
$this->gtk->set_image(
\GtkImage::new_from_icon_name(
$image,
$size
)
);
break;
default:
throw new \Exception;
}
} }
} }