mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-07 05:01:03 +02:00
BREAKING CHANGE: To allow for the `name` property, any widgets that were previously targeted by name should be targeted by class instead. This affects **all modules and all popups**, as well as several widgets inside modules. **This will break a lot of rules in your stylesheet**. To attempt to mitigate the damage, a migration script can be found [here](https://raw.githubusercontent.com/JakeStanger/ironbar/master/scripts/migrate-styles.sh) that should get you most of the way. Resolves #75.
57 lines
1.6 KiB
Rust
57 lines
1.6 KiB
Rust
use super::ImageProvider;
|
|
use crate::gtk_helpers::add_class;
|
|
use gtk::prelude::*;
|
|
use gtk::{Button, IconTheme, Image, Label, Orientation};
|
|
use tracing::error;
|
|
|
|
#[cfg(any(feature = "music", feature = "workspaces", feature = "clipboard"))]
|
|
pub fn new_icon_button(input: &str, icon_theme: &IconTheme, size: i32) -> Button {
|
|
let button = Button::new();
|
|
|
|
if ImageProvider::is_definitely_image_input(input) {
|
|
let image = Image::new();
|
|
add_class(&image, "image");
|
|
|
|
match ImageProvider::parse(input, icon_theme, size)
|
|
.and_then(|provider| provider.load_into_image(image.clone()))
|
|
{
|
|
Ok(_) => {
|
|
button.set_image(Some(&image));
|
|
button.set_always_show_image(true);
|
|
}
|
|
Err(err) => {
|
|
error!("{err:?}");
|
|
button.set_label(input);
|
|
}
|
|
}
|
|
} else {
|
|
button.set_label(input);
|
|
}
|
|
|
|
button
|
|
}
|
|
|
|
#[cfg(feature = "music")]
|
|
pub fn new_icon_label(input: &str, icon_theme: &IconTheme, size: i32) -> gtk::Box {
|
|
let container = gtk::Box::new(Orientation::Horizontal, 0);
|
|
|
|
if ImageProvider::is_definitely_image_input(input) {
|
|
let image = Image::new();
|
|
add_class(&image, "image");
|
|
|
|
container.add(&image);
|
|
|
|
if let Err(err) = ImageProvider::parse(input, icon_theme, size)
|
|
.and_then(|provider| provider.load_into_image(image))
|
|
{
|
|
error!("{err:?}");
|
|
}
|
|
} else {
|
|
let label = Label::new(Some(input));
|
|
add_class(&label, "label");
|
|
|
|
container.add(&label);
|
|
}
|
|
|
|
container
|
|
}
|