Skip to content

Commit

Permalink
Merge pull request #201 from squidowl/custom-width-sidebar
Browse files Browse the repository at this point in the history
custom width sidebar
  • Loading branch information
casperstorm authored Sep 11, 2023
2 parents 9393792 + e322338 commit de36914
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
12 changes: 8 additions & 4 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ buffer:

# Dashboard settings
dashboard:
# Default action when selecting channels in the sidebar:
# - NewPane: Open a new pane for each unique channel [default]
# - ReplacePane: Replace the currently selected pane
sidebar_default_action: NewPane
sidebar:
# Default action when selecting channels in the sidebar:
# - NewPane: Open a new pane for each unique channel [default]
# - ReplacePane: Replace the currently selected pane
default_action: NewPane
# Maximum width of the sidebar
# - Default: 120
width: 120
2 changes: 1 addition & 1 deletion data/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{environment, Theme};

mod buffer;
pub mod channel;
mod dashboard;
pub mod dashboard;
mod keys;
pub mod server;

Expand Down
23 changes: 22 additions & 1 deletion data/src/config/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,26 @@ use crate::dashboard::DefaultAction;
#[derive(Debug, Copy, Default, Clone, Deserialize)]
pub struct Dashboard {
#[serde(default)]
pub sidebar_default_action: DefaultAction,
pub sidebar: Sidebar,
}

#[derive(Debug, Copy, Clone, Deserialize)]
pub struct Sidebar {
#[serde(default)]
pub default_action: DefaultAction,
#[serde(default = "default_sidebar_width")]
pub width: u16,
}

impl Default for Sidebar {
fn default() -> Self {
Sidebar {
default_action: Default::default(),
width: default_sidebar_width(),
}
}
}

fn default_sidebar_width() -> u16 {
120
}
2 changes: 1 addition & 1 deletion src/screen/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ impl Dashboard {
&self.history,
&self.panes,
self.focus,
config.dashboard.sidebar_default_action,
config.dashboard.sidebar,
)
.map(|e| e.map(Message::SideMenu));

Expand Down
12 changes: 6 additions & 6 deletions src/screen/dashboard/side_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl SideMenu {
history: &'a history::Manager,
panes: &pane_grid::State<Pane>,
focus: Option<pane_grid::Pane>,
default_action: DefaultAction,
config: data::config::dashboard::Sidebar,
) -> Option<Element<'a, Message>> {
if self.hidden {
return None;
Expand All @@ -74,7 +74,7 @@ impl SideMenu {
Buffer::Server(server.clone()),
false,
false,
default_action,
config.default_action,
));
}
data::client::State::Ready(connection) => {
Expand All @@ -84,7 +84,7 @@ impl SideMenu {
Buffer::Server(server.clone()),
true,
false,
default_action,
config.default_action,
));

for channel in connection.channels() {
Expand All @@ -94,7 +94,7 @@ impl SideMenu {
Buffer::Channel(server.clone(), channel.clone()),
true,
history.has_unread(server, &history::Kind::Channel(channel.clone())),
default_action,
config.default_action,
));
}

Expand All @@ -106,7 +106,7 @@ impl SideMenu {
Buffer::Query(server.clone(), user.clone()),
true,
history.has_unread(server, &history::Kind::Query(user.clone())),
default_action,
config.default_action,
));
}

Expand All @@ -125,7 +125,7 @@ impl SideMenu {
)
.padding([8, 0, 6, 6])
.center_x()
.max_width(120)
.max_width(config.width)
.into(),
)
}
Expand Down

0 comments on commit de36914

Please sign in to comment.