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
2 changes: 1 addition & 1 deletion src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ fn draw_ui(session: &Session, canvas: &mut shape2d::Batch, text: &mut TextBatch)
if session.settings["ui/status"].is_set() {
// Active view status
text.add(
&view.status(),
&view.status(session.width, MARGIN),
MARGIN,
MARGIN + self::LINE_HEIGHT,
self::TEXT_LAYER,
Expand Down
17 changes: 15 additions & 2 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,21 @@ impl<R> View<R> {
}

/// Return the file status as a string.
pub fn status(&self) -> String {
self.file_status.to_string()
pub fn status(&self, width: f32, margin: f32) -> String {
let mut shortened_status: String = self.file_status.to_string();
let pixel_bound: f32 = (width * 0.4) - 32.0;
let name_width: i32 = (shortened_status.len() as i32 * 8) + margin as i32;
let pixel_diff: i32 = pixel_bound.floor() as i32 - name_width;
let midpoint_index: i32 = shortened_status.len() as i32 / 6;
let endpoint: i32 = (midpoint_index - 3) - (pixel_diff / 8);

// If the user makes the window too small, nothing will be replaced and it will just
// display the full status
if pixel_diff < 0 && midpoint_index > 3 && endpoint < shortened_status.len() as i32 {
shortened_status.replace_range((midpoint_index - 3) as usize..endpoint as usize, "...");
}

return shortened_status;
}

/// Return the view extent.
Expand Down