Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added adjustable inner padding slider #396

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions i18n/en/cosmic_term.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ syntax-dark = Color scheme dark
syntax-light = Color scheme light
default-zoom-step = Zoom steps
opacity = Background opacity
padding = Inner padding

### Font
font = Font
Expand Down
10 changes: 10 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ pub struct Config {
pub font_stretch: u16,
pub font_size_zoom_step_mul_100: u16,
pub opacity: u8,
pub padding: u16,
pub profiles: BTreeMap<ProfileId, Profile>,
pub show_headerbar: bool,
pub use_bright_bold: bool,
Expand All @@ -253,6 +254,7 @@ impl Default for Config {
font_stretch: Stretch::Normal.to_number(),
font_weight: Weight::NORMAL.0,
opacity: 100,
padding: 0,
profiles: BTreeMap::new(),
show_headerbar: true,
syntax_theme_dark: COSMIC_THEME_DARK.to_string(),
Expand Down Expand Up @@ -333,6 +335,14 @@ impl Config {
f32::from(self.opacity) / 100.0
}

pub fn padding_value(&self, space_xxs: u16) -> u16 {
if self.padding <= space_xxs {
u16::from(space_xxs)
} else {
u16::from(self.padding)
}
}

// Get a sorted and adjusted for duplicates list of profile names and ids
pub fn profile_names(&self) -> Vec<(String, ProfileId)> {
let mut profile_names = Vec::<(String, ProfileId)>::with_capacity(self.profiles.len());
Expand Down
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ pub enum Message {
Modifiers(Modifiers),
MouseEnter(pane_grid::Pane),
Opacity(u8),
Padding(u16),
PaneClicked(pane_grid::Pane),
PaneDragged(pane_grid::DragEvent),
PaneFocusAdjacent(pane_grid::Direction),
Expand Down Expand Up @@ -1063,6 +1064,8 @@ impl App {
.iter()
.position(|zoom_step| zoom_step == &self.config.font_size_zoom_step_mul_100);

let cosmic_theme::Spacing { space_xxs, .. } = self.core().system_theme().cosmic().spacing;

let appearance_section = widget::settings::section()
.title(fl!("appearance"))
.add(
Expand Down Expand Up @@ -1107,6 +1110,13 @@ impl App {
.control(widget::slider(0..=100, self.config.opacity, |opacity| {
Message::Opacity(opacity)
})),
)
.add(
widget::settings::item::builder(fl!("padding"))
.description(format!("{}px", self.config.padding))
.control(widget::slider(space_xxs..=100, self.config.padding, |padding| {
Message::Padding(padding)
})),
);

let mut font_section = widget::settings::section()
Expand Down Expand Up @@ -2046,6 +2056,9 @@ impl Application for App {
Message::Opacity(opacity) => {
config_set!(opacity, cmp::min(100, opacity));
}
Message::Padding(padding) => {
config_set!(padding, cmp::min(100, padding));
}
Message::PaneClicked(pane) => {
self.pane_model.focus = pane;
return self.update_title(Some(pane));
Expand Down Expand Up @@ -2674,7 +2687,7 @@ impl Application for App {
.on_middle_click(move || Message::MiddleClick(pane, Some(entity_middle_click)))
.on_open_hyperlink(Some(Box::new(Message::LaunchUrl)))
.opacity(self.config.opacity_ratio())
.padding(space_xxs)
.padding(self.config.padding_value(space_xxs))
.show_headerbar(self.config.show_headerbar);

if self.config.focus_follow_mouse {
Expand Down