par-term-settings-ui 0.19.0

Settings UI for par-term terminal emulator
Documentation
//! Tab Bar Appearance section: colors, borders, dimming, indicator colors.

use crate::SettingsUI;
use crate::search::SearchTag;
use crate::section::keyword_section;
use std::collections::HashSet;

pub(super) fn show_tab_bar_appearance_section(
    ui: &mut egui::Ui,
    settings: &mut SettingsUI,
    changes_this_frame: &mut bool,
    collapsed: &mut HashSet<String>,
) {
    keyword_section(
        ui,
        "Tab Bar Appearance",
        "window_tab_bar_appearance",
        &["tab style", "system tab style"],
        false,
        collapsed,
        |ui| {
            ui.horizontal(|ui| {
                ui.label("Minimum tab width:");
                if ui
                    .add(
                        egui::Slider::new(
                            &mut settings.config.tab_colors.tab_min_width,
                            120.0..=512.0,
                        )
                        .step_by(1.0)
                        .suffix(" px"),
                    )
                    .search_tag(&["tab_min_width"])
                    .on_hover_text("Minimum width for tabs before horizontal scrolling is enabled")
                    .changed()
                {
                    settings.has_changes = true;
                    *changes_this_frame = true;
                }
                crate::reset::reset_button(ui, settings, changes_this_frame, |c| {
                    &mut c.tab_colors.tab_min_width
                });
            });

            ui.add_space(8.0);
            ui.label(egui::RichText::new("Border").strong());

            ui.horizontal(|ui| {
                ui.label("Border width:");
                if ui
                    .add(
                        egui::Slider::new(
                            &mut settings.config.tab_colors.tab_border_width,
                            0.0..=3.0,
                        )
                        .step_by(0.5)
                        .suffix(" px"),
                    )
                    .search_tag(&["tab_border_width"])
                    .on_hover_text("Width of the border around each tab (0 = no border)")
                    .changed()
                {
                    settings.has_changes = true;
                    *changes_this_frame = true;
                }
                crate::reset::reset_button(ui, settings, changes_this_frame, |c| {
                    &mut c.tab_colors.tab_border_width
                });
            });

            ui.horizontal(|ui| {
                ui.label("Border color:");
                let mut color = settings.config.tab_colors.tab_border_color;
                if ui
                    .color_edit_button_srgb(&mut color)
                    .search_tag(&["tab_border_color"])
                    .changed()
                {
                    settings.config.tab_colors.tab_border_color = color;
                    settings.has_changes = true;
                    *changes_this_frame = true;
                }
            });

            if ui
                .checkbox(
                    &mut settings.config.tab_colors.tab_inactive_outline_only,
                    "Inactive tabs outline only",
                )
                .search_tag(&["tab_inactive_outline_only"])
                .on_hover_text("Render inactive tabs with just an outline border and no fill")
                .changed()
            {
                settings.has_changes = true;
                *changes_this_frame = true;
            }

            ui.add_space(8.0);
            ui.label(egui::RichText::new("Inactive Tab Dimming").strong());

            if ui
                .checkbox(
                    &mut settings.config.tab_colors.dim_inactive_tabs,
                    "Dim inactive tabs",
                )
                .search_tag(&["dim_inactive_tabs"])
                .changed()
            {
                settings.has_changes = true;
                *changes_this_frame = true;
            }

            crate::dependent::dependent(
                ui,
                settings.config.tab_colors.dim_inactive_tabs,
                "Dim inactive tabs",
                |ui| {
                    ui.horizontal(|ui| {
                        ui.label("Opacity:");
                        if ui
                            .add(
                                crate::units::percent(egui::Slider::new(
                                    &mut settings.config.tab_colors.inactive_tab_opacity,
                                    0.2..=1.0,
                                ))
                                .step_by(0.05),
                            )
                            .search_tag(&["inactive_tab_opacity"])
                            .changed()
                        {
                            settings.has_changes = true;
                            *changes_this_frame = true;
                        }
                        crate::reset::reset_button(ui, settings, changes_this_frame, |c| {
                            &mut c.tab_colors.inactive_tab_opacity
                        });
                    });
                },
            );

            ui.add_space(8.0);
            ui.label(egui::RichText::new("Background Colors").strong());

            ui.horizontal(|ui| {
                ui.label("Tab bar background:");
                let mut color = settings.config.tab_colors.tab_bar_background;
                if ui
                    .color_edit_button_srgb(&mut color)
                    .search_tag(&["tab_bar_background"])
                    .changed()
                {
                    settings.config.tab_colors.tab_bar_background = color;
                    settings.has_changes = true;
                    *changes_this_frame = true;
                }
            });

            ui.horizontal(|ui| {
                ui.label("Active tab:");
                let mut color = settings.config.tab_colors.tab_active_background;
                if ui
                    .color_edit_button_srgb(&mut color)
                    .search_tag(&["tab_active_background"])
                    .changed()
                {
                    settings.config.tab_colors.tab_active_background = color;
                    settings.has_changes = true;
                    *changes_this_frame = true;
                }
            });

            ui.horizontal(|ui| {
                ui.label("Inactive tab:");
                let mut color = settings.config.tab_colors.tab_inactive_background;
                if ui
                    .color_edit_button_srgb(&mut color)
                    .search_tag(&["tab_inactive_background"])
                    .changed()
                {
                    settings.config.tab_colors.tab_inactive_background = color;
                    settings.has_changes = true;
                    *changes_this_frame = true;
                }
            });

            ui.horizontal(|ui| {
                ui.label("Hovered tab:");
                let mut color = settings.config.tab_colors.tab_hover_background;
                if ui
                    .color_edit_button_srgb(&mut color)
                    .search_tag(&["tab_hover_background"])
                    .changed()
                {
                    settings.config.tab_colors.tab_hover_background = color;
                    settings.has_changes = true;
                    *changes_this_frame = true;
                }
            });

            ui.add_space(8.0);
            ui.label(egui::RichText::new("Text Colors").strong());

            ui.horizontal(|ui| {
                ui.label("Active tab text:");
                let mut color = settings.config.tab_colors.tab_active_text;
                if ui
                    .color_edit_button_srgb(&mut color)
                    .search_tag(&["tab_active_text"])
                    .changed()
                {
                    settings.config.tab_colors.tab_active_text = color;
                    settings.has_changes = true;
                    *changes_this_frame = true;
                }
            });

            ui.horizontal(|ui| {
                ui.label("Inactive tab text:");
                let mut color = settings.config.tab_colors.tab_inactive_text;
                if ui
                    .color_edit_button_srgb(&mut color)
                    .search_tag(&["tab_inactive_text"])
                    .changed()
                {
                    settings.config.tab_colors.tab_inactive_text = color;
                    settings.has_changes = true;
                    *changes_this_frame = true;
                }
            });

            ui.add_space(8.0);
            ui.label(egui::RichText::new("Indicator Colors").strong());

            ui.horizontal(|ui| {
                ui.label("Active tab border:");
                let mut color = settings.config.tab_colors.tab_active_indicator;
                if ui
                    .color_edit_button_srgb(&mut color)
                    .search_tag(&["tab_active_indicator"])
                    .changed()
                {
                    settings.config.tab_colors.tab_active_indicator = color;
                    settings.has_changes = true;
                    *changes_this_frame = true;
                }
            });

            ui.horizontal(|ui| {
                ui.label("Activity indicator:");
                let mut color = settings.config.tab_colors.tab_activity_indicator;
                if ui
                    .color_edit_button_srgb(&mut color)
                    .search_tag(&["tab_activity_indicator"])
                    .changed()
                {
                    settings.config.tab_colors.tab_activity_indicator = color;
                    settings.has_changes = true;
                    *changes_this_frame = true;
                }
            });

            ui.horizontal(|ui| {
                ui.label("Bell indicator:");
                let mut color = settings.config.tab_colors.tab_bell_indicator;
                if ui
                    .color_edit_button_srgb(&mut color)
                    .search_tag(&["tab_bell_indicator"])
                    .changed()
                {
                    settings.config.tab_colors.tab_bell_indicator = color;
                    settings.has_changes = true;
                    *changes_this_frame = true;
                }
            });

            ui.add_space(8.0);
            ui.label(egui::RichText::new("Close Button Colors").strong());

            ui.horizontal(|ui| {
                ui.label("Close button:");
                let mut color = settings.config.tab_colors.tab_close_button;
                if ui
                    .color_edit_button_srgb(&mut color)
                    .search_tag(&["tab_close_button"])
                    .changed()
                {
                    settings.config.tab_colors.tab_close_button = color;
                    settings.has_changes = true;
                    *changes_this_frame = true;
                }
            });

            ui.horizontal(|ui| {
                ui.label("Close button hover:");
                let mut color = settings.config.tab_colors.tab_close_button_hover;
                if ui
                    .color_edit_button_srgb(&mut color)
                    .search_tag(&["tab_close_button_hover"])
                    .changed()
                {
                    settings.config.tab_colors.tab_close_button_hover = color;
                    settings.has_changes = true;
                    *changes_this_frame = true;
                }
            });
        },
    );
}