Skip to content
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 book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
- [Notifications](configuration/notifications/README.md)
- [Pane](configuration/pane/README.md)
- [Gap](configuration/pane/gap.md)
- [Spacing](configuration/spacing/README.md)
- [Platform Specific](configuration/platform-specific/README.md)
- [Linux](configuration/platform-specific/linux.md)
- [macOS](configuration/platform-specific/macos.md)
Expand Down
30 changes: 30 additions & 0 deletions book/src/configuration/spacing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Spacing

Spacing settings for Halloy.

This section provides aliases for spacing-related options that also exist under other sections (e.g. `[buffer]`, `[pane]`, `[sidebar]`, `[context_menu]`). Values set here take precedence when both are present.

## Configuration

```toml
[spacing.buffer]
# Alias of: [buffer] line_spacing
line_spacing = 4

[spacing.pane.gap]
# Alias of: [pane.gap] inner / outer
inner = 6
outer = 10

[spacing.sidebar.padding]
# Alias of: [sidebar.padding] buffer
buffer = [5, 5]

[spacing.sidebar.spacing]
# Alias of: [sidebar.spacing] server
server = 12

[spacing.context_menu.padding]
# Alias of: [context_menu.padding] entry
entry = [2, 5]
```
105 changes: 101 additions & 4 deletions data/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub use self::preview::Preview;
pub use self::proxy::Proxy;
pub use self::server::Server;
pub use self::sidebar::Sidebar;
pub use self::spacing::Spacing;
use crate::appearance::theme::Styles;
use crate::appearance::{self, Appearance};
use crate::audio::{self};
Expand All @@ -48,6 +49,7 @@ pub mod preview;
pub mod proxy;
pub mod server;
pub mod sidebar;
pub mod spacing;

const CONFIG_TEMPLATE: &str = include_str!("../../config.toml");
const DEFAULT_THEME_NAME: &str = "ferra";
Expand All @@ -60,6 +62,7 @@ pub struct Config {
pub proxy: Option<Proxy>,
pub font: Font,
pub scale_factor: ScaleFactor,
pub spacing: Spacing,
pub buffer: Buffer,
pub pane: Pane,
pub sidebar: Sidebar,
Expand Down Expand Up @@ -312,6 +315,7 @@ impl Config {
pub proxy: Option<Proxy>,
pub font: Font,
pub scale_factor: ScaleFactor,
pub spacing: Spacing,
pub buffer: Buffer,
pub pane: Pane,
pub sidebar: Sidebar,
Expand All @@ -336,6 +340,7 @@ impl Config {
proxy: None,
font: Font::default(),
scale_factor: ScaleFactor::default(),
spacing: Spacing::default(),
buffer: Buffer::default(),
pane: Pane::default(),
sidebar: Sidebar::default(),
Expand All @@ -353,6 +358,71 @@ impl Config {
}
}

fn config_migrate<T: Copy>(
raw_toml: &toml::Value,
old_path: &[&str],
new_path: &[&str],
old_value: T,
new_value: &mut T,
) {
if !toml_path_exists(raw_toml, new_path)
&& toml_path_exists(raw_toml, old_path)
{
*new_value = old_value;
}
}

fn apply_config_migrations(
config: &mut Configuration,
raw_toml: &toml::Value,
) {
config_migrate(
raw_toml,
&["buffer", "line_spacing"],
&["spacing", "buffer", "line_spacing"],
config.buffer.line_spacing,
&mut config.spacing.buffer.line_spacing,
);

config_migrate(
raw_toml,
&["pane", "gap", "inner"],
&["spacing", "pane", "gap", "inner"],
config.pane.gap.inner,
&mut config.spacing.pane.gap.inner,
);
config_migrate(
raw_toml,
&["pane", "gap", "outer"],
&["spacing", "pane", "gap", "outer"],
config.pane.gap.outer,
&mut config.spacing.pane.gap.outer,
);

config_migrate(
raw_toml,
&["sidebar", "padding", "buffer"],
&["spacing", "sidebar", "padding", "buffer"],
config.sidebar.padding.buffer,
&mut config.spacing.sidebar.padding.buffer,
);
config_migrate(
raw_toml,
&["sidebar", "spacing", "server"],
&["spacing", "sidebar", "spacing", "server"],
config.sidebar.spacing.server,
&mut config.spacing.sidebar.spacing.server,
);

config_migrate(
raw_toml,
&["context_menu", "padding", "entry"],
&["spacing", "context_menu", "padding", "entry"],
config.context_menu.padding.entry,
&mut config.spacing.context_menu.padding.entry,
);
}

let path = Self::path();
if !path.try_exists()? {
return Err(Error::ConfigMissing);
Expand All @@ -363,13 +433,25 @@ impl Config {

let config = toml::Deserializer::new(content.as_ref());

let mut configuration: Configuration =
serde_ignored::deserialize(config, |ignored| {
log::warn!("[config.toml] Ignoring unknown setting: {ignored}");
})
.map_err(|e| Error::Parse(e.to_string()))?;

let raw_toml: toml::Value = toml::from_str(content.as_ref())
.map_err(|e| Error::Parse(e.to_string()))?;

apply_config_migrations(&mut configuration, &raw_toml);

let Configuration {
theme,
servers,
context_menu,
font,
proxy,
scale_factor,
spacing,
buffer,
sidebar,
keyboard,
Expand All @@ -383,10 +465,7 @@ impl Config {
ctcp,
logs,
platform_specific,
} = serde_ignored::deserialize(config, |ignored| {
log::warn!("[config.toml] Ignoring unknown setting: {ignored}");
})
.map_err(|e| Error::Parse(e.to_string()))?;
} = configuration;

let servers = ServerMap::new(servers).await?;

Expand All @@ -401,6 +480,7 @@ impl Config {
font,
proxy,
scale_factor,
spacing,
buffer,
sidebar,
keyboard,
Expand Down Expand Up @@ -530,6 +610,23 @@ impl Config {
}
}

fn toml_path_exists(root: &toml::Value, path: &[&str]) -> bool {
let mut current = root;

for key in path {
let Some(table) = current.as_table() else {
return false;
};
let Some(value) = table.get(*key) else {
return false;
};

current = value;
}

true
}

pub fn random_nickname() -> String {
let mut rng = ChaCha8Rng::from_rng(&mut rand::rng());
random_nickname_with_seed(&mut rng)
Expand Down
84 changes: 84 additions & 0 deletions data/src/config/spacing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use serde::Deserialize;

#[derive(Debug, Clone, Default, Copy, Deserialize)]
#[serde(default)]
pub struct Spacing {
pub buffer: Buffer,
pub pane: Pane,
pub sidebar: Sidebar,
pub context_menu: ContextMenu,
}

#[derive(Debug, Clone, Default, Copy, Deserialize)]
#[serde(default)]
pub struct Buffer {
pub line_spacing: u32,
}

#[derive(Debug, Clone, Default, Copy, Deserialize)]
#[serde(default)]
pub struct Pane {
pub gap: Gap,
}

#[derive(Debug, Clone, Copy, Deserialize)]
#[serde(default)]
pub struct Gap {
pub inner: u32,
pub outer: u16,
}

impl Default for Gap {
fn default() -> Self {
Self { inner: 4, outer: 8 }
}
}

#[derive(Debug, Clone, Default, Copy, Deserialize)]
#[serde(default)]
pub struct Sidebar {
pub padding: SidebarPadding,
pub spacing: SidebarSpacing,
}

#[derive(Debug, Clone, Copy, Deserialize)]
#[serde(default)]
pub struct SidebarPadding {
pub buffer: [u16; 2],
}

impl Default for SidebarPadding {
fn default() -> Self {
Self { buffer: [5, 5] }
}
}

#[derive(Debug, Clone, Copy, Deserialize)]
#[serde(default)]
pub struct SidebarSpacing {
pub server: u32,
}

impl Default for SidebarSpacing {
fn default() -> Self {
Self { server: 12 }
}
}

#[derive(Debug, Clone, Default, Copy, Deserialize)]
#[serde(default)]
pub struct ContextMenu {
pub padding: ContextMenuPadding,
}

#[derive(Debug, Clone, Copy, Deserialize)]
#[serde(default)]
pub struct ContextMenuPadding {
pub entry: [u16; 2],
}

impl Default for ContextMenuPadding {
fn default() -> Self {
Self { entry: [5, 5] }
}
}
4 changes: 2 additions & 2 deletions src/buffer/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,14 @@ fn menu_button(
.style(theme::text::primary)
.font_maybe(theme::font_style::primary(theme).map(font::get)),
)
.padding(config.context_menu.padding.entry)
.padding(config.spacing.context_menu.padding.entry)
.width(length)
.on_press_maybe(message)
.into()
}

fn right_justified_padding(config: &Config) -> Padding {
let padding = config.context_menu.padding.entry;
let padding = config.spacing.context_menu.padding.entry;
Padding::from(padding)
.right(padding[1] as f32 + double_pass::horizontal_expansion())
}
Expand Down
2 changes: 1 addition & 1 deletion src/buffer/input_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ pub fn view<'a>(
.align_y(iced::Alignment::Center),
)
.width(length)
.padding(config.context_menu.padding.entry)
.padding(config.spacing.context_menu.padding.entry)
.on_press_maybe(message)
.into()
};
Expand Down
8 changes: 4 additions & 4 deletions src/buffer/scroll_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,12 @@ pub fn view<'a>(
let content = on_resize(
column![
top_row,
column(old).spacing(config.buffer.line_spacing),
column(old).spacing(config.spacing.buffer.line_spacing),
keyed(keyed::Key::Divider, divider),
column(new).spacing(config.buffer.line_spacing),
space::vertical().height(config.buffer.line_spacing),
column(new).spacing(config.spacing.buffer.line_spacing),
space::vertical().height(config.spacing.buffer.line_spacing),
]
.spacing(config.buffer.line_spacing),
.spacing(config.spacing.buffer.line_spacing),
Message::ContentResized,
);

Expand Down
8 changes: 4 additions & 4 deletions src/screen/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1502,12 +1502,12 @@ impl Dashboard {
window != self.main_window(),
)
})
.spacing(config.pane.gap.inner)
.spacing(config.spacing.pane.gap.inner)
.on_click(pane::Message::PaneClicked),
)
.width(Length::Fill)
.height(Length::Fill)
.padding(config.pane.gap.outer);
.padding(config.spacing.pane.gap.outer);

return Element::new(content)
.map(move |message| Message::Pane(window, message));
Expand Down Expand Up @@ -1559,7 +1559,7 @@ impl Dashboard {
.on_click(pane::Message::PaneClicked)
.on_resize(6, pane::Message::PaneResized)
.on_drag(pane::Message::PaneDragged)
.spacing(config.pane.gap.inner)
.spacing(config.spacing.pane.gap.inner)
.into();

let pane_grid =
Expand All @@ -1568,7 +1568,7 @@ impl Dashboard {
}))
.width(Length::Fill)
.height(Length::Fill)
.padding(config.pane.gap.outer);
.padding(config.spacing.pane.gap.outer);

let side_menu = self
.side_menu
Expand Down
Loading