mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-17 14:51:04 +02:00
feat(launcher): truncate
and truncate_popup
config options
This commit is contained in:
parent
8b05ed526d
commit
da13b9d500
5 changed files with 123 additions and 62 deletions
|
@ -1,15 +1,16 @@
|
|||
use super::open_state::OpenState;
|
||||
use crate::clients::wayland::ToplevelInfo;
|
||||
use crate::config::BarPosition;
|
||||
use crate::gtk_helpers::IronbarGtkExt;
|
||||
use crate::config::{BarPosition, TruncateMode};
|
||||
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt};
|
||||
use crate::image::ImageProvider;
|
||||
use crate::modules::launcher::{ItemEvent, LauncherUpdate};
|
||||
use crate::modules::ModuleUpdateEvent;
|
||||
use crate::{read_lock, try_send};
|
||||
use glib::Propagation;
|
||||
use gtk::prelude::*;
|
||||
use gtk::{Button, IconTheme};
|
||||
use gtk::{Button, IconTheme, Image, Label, Orientation};
|
||||
use indexmap::IndexMap;
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
use std::sync::RwLock;
|
||||
use tokio::sync::mpsc::Sender;
|
||||
|
@ -134,7 +135,7 @@ pub struct MenuState {
|
|||
}
|
||||
|
||||
pub struct ItemButton {
|
||||
pub button: Button,
|
||||
pub button: ImageTextButton,
|
||||
pub persistent: bool,
|
||||
pub show_names: bool,
|
||||
pub menu_state: Rc<RwLock<MenuState>>,
|
||||
|
@ -145,6 +146,7 @@ pub struct AppearanceOptions {
|
|||
pub show_names: bool,
|
||||
pub show_icons: bool,
|
||||
pub icon_size: i32,
|
||||
pub truncate: TruncateMode,
|
||||
}
|
||||
|
||||
impl ItemButton {
|
||||
|
@ -156,16 +158,14 @@ impl ItemButton {
|
|||
tx: &Sender<ModuleUpdateEvent<LauncherUpdate>>,
|
||||
controller_tx: &Sender<ItemEvent>,
|
||||
) -> Self {
|
||||
let mut button = Button::builder();
|
||||
let button = ImageTextButton::new();
|
||||
|
||||
if appearance.show_names {
|
||||
button = button.label(&item.name);
|
||||
button.label.set_label(&item.name);
|
||||
button.label.truncate(appearance.truncate);
|
||||
}
|
||||
|
||||
let button = button.build();
|
||||
|
||||
if appearance.show_icons {
|
||||
let gtk_image = gtk::Image::new();
|
||||
let input = if item.app_id.is_empty() {
|
||||
item.name.clone()
|
||||
} else {
|
||||
|
@ -173,26 +173,24 @@ impl ItemButton {
|
|||
};
|
||||
let image = ImageProvider::parse(&input, icon_theme, true, appearance.icon_size);
|
||||
if let Some(image) = image {
|
||||
button.set_image(Some(>k_image));
|
||||
button.set_always_show_image(true);
|
||||
|
||||
if let Err(err) = image.load_into_image(>k_image) {
|
||||
if let Err(err) = image.load_into_image(&button.image) {
|
||||
error!("{err:?}");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let style_context = button.style_context();
|
||||
style_context.add_class("item");
|
||||
button.add_class("item");
|
||||
|
||||
if item.favorite {
|
||||
style_context.add_class("favorite");
|
||||
button.add_class("favorite");
|
||||
}
|
||||
if item.open_state.is_open() {
|
||||
style_context.add_class("open");
|
||||
button.add_class("open");
|
||||
}
|
||||
if item.open_state.is_focused() {
|
||||
style_context.add_class("focused");
|
||||
button.add_class("focused");
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -297,3 +295,39 @@ impl ItemButton {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ImageTextButton {
|
||||
pub(crate) button: Button,
|
||||
pub(crate) label: Label,
|
||||
image: Image,
|
||||
}
|
||||
|
||||
impl ImageTextButton {
|
||||
pub(crate) fn new() -> Self {
|
||||
let button = Button::new();
|
||||
let container = gtk::Box::new(Orientation::Horizontal, 0);
|
||||
|
||||
let label = Label::new(None);
|
||||
let image = Image::new();
|
||||
|
||||
button.add(&container);
|
||||
|
||||
container.add(&image);
|
||||
container.add(&label);
|
||||
|
||||
ImageTextButton {
|
||||
button,
|
||||
label,
|
||||
image,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for ImageTextButton {
|
||||
type Target = Button;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.button
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue