Skip to content

Commit

Permalink
Make nav bar more compact
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Nov 27, 2023
1 parent 518e791 commit 4fbf3e4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ features = ["syntect", "vi"]

[dependencies.libcosmic]
git = "https://github.com/pop-os/libcosmic"
branch = "customizable-nav-bar"
default-features = false
features = ["tokio", "winit", "wgpu"]
#path = "../libcosmic"
Expand Down
36 changes: 34 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use cosmic::{
widget::{row, text},
window, Alignment, Length, Point,
},
style,
style, theme,
widget::{self, button, icon, nav_bar, segmented_button, view_switcher},
Application, ApplicationExt, Element,
Application, ApplicationExt, Apply, Element,
};
use cosmic_text::{Cursor, Edit, Family, FontSystem, SwashCache, SyntaxSystem, ViMode};
use std::{
Expand Down Expand Up @@ -539,6 +539,38 @@ impl Application for App {
(app, command)
}

// The default nav_bar widget needs to be condensed for cosmic-edit
fn nav_bar(&self) -> Option<Element<message::Message<Self::Message>>> {
if !self.core().nav_bar_active() {
return None;
}

let nav_model = self.nav_model()?;

let mut nav = segmented_button::vertical(nav_model)
.button_height(24)
.button_padding([16, 4, 16, 4])
.button_spacing(4)
.on_activate(|entity| message::cosmic(cosmic::app::cosmic::Message::NavBar(entity)))
.spacing(0)
.style(theme::SegmentedButton::ViewSwitcher)
.apply(widget::container)
.padding([8, 16])
.width(Length::Fill);

if !self.core().is_condensed() {
nav = nav.max_width(300);
}

Some(
nav.apply(widget::scrollable)
.apply(widget::container)
.height(Length::Fill)
.style(theme::Container::custom(nav_bar::nav_bar_style))
.into(),
)
}

fn nav_model(&self) -> Option<&nav_bar::Model> {
Some(&self.nav_model)
}
Expand Down

0 comments on commit 4fbf3e4

Please sign in to comment.