1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-18 15:21:03 +02:00

feat: fully implement orientation/justify options

Adds `orientation` and `justify` options to all modules and custom
widgets where it makes sense to do so.

Any modules without support document this. Widgets fully document the
options inline where present for now.

Resolves #296
This commit is contained in:
Jake Stanger 2025-03-22 19:19:47 +00:00
parent 0855039bce
commit c20feb77b7
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
29 changed files with 317 additions and 161 deletions

View file

@ -9,7 +9,7 @@ use crate::{read_lock, try_send};
use glib::Propagation;
use gtk::gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY};
use gtk::prelude::*;
use gtk::{Button, IconTheme, Image, Label, Orientation};
use gtk::{Align, Button, IconTheme, Image, Justification, Label, Orientation};
use indexmap::IndexMap;
use std::ops::Deref;
use std::rc::Rc;
@ -156,6 +156,9 @@ pub struct AppearanceOptions {
pub show_icons: bool,
pub icon_size: i32,
pub truncate: TruncateMode,
pub orientation: Orientation,
pub angle: f64,
pub justify: Justification,
}
impl ItemButton {
@ -167,11 +170,13 @@ impl ItemButton {
tx: &Sender<ModuleUpdateEvent<LauncherUpdate>>,
controller_tx: &Sender<ItemEvent>,
) -> Self {
let button = ImageTextButton::new();
let button = ImageTextButton::new(appearance.orientation);
if appearance.show_names {
button.label.set_label(&item.name);
button.label.truncate(appearance.truncate);
button.label.set_angle(appearance.angle);
button.label.set_justify(appearance.justify);
}
if appearance.show_icons {
@ -329,18 +334,20 @@ pub struct ImageTextButton {
}
impl ImageTextButton {
pub(crate) fn new() -> Self {
pub(crate) fn new(orientation: Orientation) -> Self {
let button = Button::new();
let container = gtk::Box::new(Orientation::Horizontal, 0);
let container = gtk::Box::new(orientation, 0);
let label = Label::new(None);
let image = Image::new();
button.add(&container);
container.add(&image);
container.add(&label);
button.add(&container);
container.set_halign(Align::Center);
container.set_valign(Align::Center);
ImageTextButton {
button,
label,

View file

@ -6,7 +6,7 @@ use self::item::{AppearanceOptions, Item, ItemButton, Window};
use self::open_state::OpenState;
use super::{Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, WidgetContext};
use crate::clients::wayland::{self, ToplevelEvent};
use crate::config::{CommonConfig, EllipsizeMode, TruncateMode};
use crate::config::{CommonConfig, EllipsizeMode, LayoutConfig, TruncateMode};
use crate::desktop_file::find_desktop_file;
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt};
use crate::modules::launcher::item::ImageTextButton;
@ -105,6 +105,10 @@ pub struct LauncherModule {
#[serde(default = "default_truncate_popup")]
truncate_popup: TruncateMode,
/// See [layout options](module-level-options#layout)
#[serde(default, flatten)]
layout: LayoutConfig,
/// See [common options](module-level-options#common-options).
#[serde(flatten)]
pub common: Option<CommonConfig>,
@ -451,13 +455,13 @@ impl Module<gtk::Box> for LauncherModule {
) -> crate::Result<ModuleParts<gtk::Box>> {
let icon_theme = info.icon_theme;
let container = gtk::Box::new(info.bar_position.orientation(), 0);
let container = gtk::Box::new(self.layout.orientation(info), 0);
let page_size = self.page_size;
let pagination = Pagination::new(
&container,
self.page_size,
info.bar_position.orientation(),
self.layout.orientation(info),
IconContext {
icon_back: &self.icons.page_back,
icon_fwd: &self.icons.page_forward,
@ -477,6 +481,9 @@ impl Module<gtk::Box> for LauncherModule {
show_icons: self.show_icons,
icon_size: self.icon_size,
truncate: self.truncate,
orientation: self.layout.orientation(info),
angle: self.layout.angle(info),
justify: self.layout.justify.into(),
};
let show_names = self.show_names;
@ -636,7 +643,7 @@ impl Module<gtk::Box> for LauncherModule {
.into_iter()
.map(|(_, win)| {
// TODO: Currently has a useless image
let button = ImageTextButton::new();
let button = ImageTextButton::new(Orientation::Horizontal);
button.set_height_request(40);
button.label.set_label(&win.name);
button.label.truncate(self.truncate_popup);
@ -662,7 +669,7 @@ impl Module<gtk::Box> for LauncherModule {
if let Some(buttons) = buttons.get_mut(&app_id) {
// TODO: Currently has a useless image
let button = ImageTextButton::new();
let button = ImageTextButton::new(Orientation::Horizontal);
button.set_height_request(40);
button.label.set_label(&win.name);
button.label.truncate(self.truncate_popup);

View file

@ -1,5 +1,5 @@
use crate::gtk_helpers::IronbarGtkExt;
use crate::image::new_icon_button;
use crate::image::IconButton;
use gtk::prelude::*;
use gtk::{Button, IconTheme, Orientation};
use std::cell::RefCell;
@ -29,13 +29,13 @@ impl Pagination {
) -> Self {
let scroll_box = gtk::Box::new(orientation, 0);
let scroll_back = new_icon_button(
let scroll_back = IconButton::new(
icon_context.icon_back,
icon_context.icon_theme,
icon_context.icon_size,
);
let scroll_fwd = new_icon_button(
let scroll_fwd = IconButton::new(
icon_context.icon_fwd,
icon_context.icon_theme,
icon_context.icon_size,
@ -48,8 +48,8 @@ impl Pagination {
scroll_back.add_class("btn-back");
scroll_fwd.add_class("btn-forward");
scroll_box.add(&scroll_back);
scroll_box.add(&scroll_fwd);
scroll_box.add(&*scroll_back);
scroll_box.add(&*scroll_fwd);
container.add(&scroll_box);
let offset = Rc::new(RefCell::new(1));
@ -103,7 +103,7 @@ impl Pagination {
offset,
controls_container: scroll_box,
btn_fwd: scroll_fwd,
btn_fwd: scroll_fwd.deref().clone(),
}
}