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

concept frame: truncate overly long titles #126

Closed
wants to merge 2 commits into from
Closed
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
93 changes: 51 additions & 42 deletions src/window/concept_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,27 +596,6 @@ impl Frame for ConceptFrame {
);
header_canvas.draw(&header_bar);

draw_buttons(
&mut header_canvas,
width,
header_scale,
true,
self.active,
&self
.pointers
.iter()
.flat_map(|p| {
if p.as_ref().is_alive() {
let data: &RefCell<PointerUserData> =
p.as_ref().user_data().get().unwrap();
Some(data.borrow().location)
} else {
None
}
})
.collect::<Vec<Location>>(),
&self.config,
);
if let Some((ref font_face, font_size)) = self.config.title_font {
if let Some(title) = self.title.clone() {
// If theres no stored font data, find the first ttf regular sans font and
Expand All @@ -643,21 +622,6 @@ impl Frame for ConceptFrame {

// Create text from stored title and font data
if let Some(ref font_data) = self.font_data {
let title_color = self.config.title_color.get_for(self.active);
let mut title_text = text::Text::new(
(
0,
(HEADER_SIZE as usize / 2)
.saturating_sub((font_size / 2.0).ceil() as usize)
* header_scale as usize,
),
title_color.into(),
font_data,
font_size * header_scale as f32,
1.0,
title,
);

let mut button_count = 0isize;
if self.config.close_button.is_some() {
button_count += 1;
Expand All @@ -674,18 +638,63 @@ impl Frame for ConceptFrame {
let button_space = button_count * scaled_button_size;
let scaled_header_width = width as isize * header_scale as isize;

// Check if text is bigger then the available width
if (scaled_header_width - button_space)
> (title_text.get_width() as isize + scaled_button_size)
{
let title_color =
self.config.title_color.get_for(self.active).into();

let text_pos = (
0,
(HEADER_SIZE as usize / 2)
.saturating_sub((font_size / 2.0).ceil() as usize)
* header_scale as usize,
);

let mut title_text = text::Text::new(
text_pos,
title_color,
font_data,
font_size * header_scale as f32,
1.0,
&title,
);

let text_width = title_text.get_width();

// Center the title in the header area if possible
if (scaled_header_width - button_space) > (text_width as isize) {
title_text.pos.0 =
(scaled_header_width - button_space) as usize / 2
- (title_text.get_width() / 2);
header_canvas.draw(&title_text);
- (text_width / 2);
}

// Note that long titles will leak out of the header area,
// so we render this text before we draw the buttons over
// the top of it.
header_canvas.draw(&title_text);
}
}
}

draw_buttons(
&mut header_canvas,
width,
header_scale,
true,
self.active,
&self
.pointers
.iter()
.flat_map(|p| {
if p.as_ref().is_alive() {
let data: &RefCell<PointerUserData> =
p.as_ref().user_data().get().unwrap();
Some(data.borrow().location)
} else {
None
}
})
.collect::<Vec<Location>>(),
&self.config,
);
}

// For each pixel in borders
Expand Down