Always make word and kind column visible (#34)
Allow popup to make smaller again
This commit is contained in:
parent
cb1a1fbece
commit
d31ec7d581
@ -6,6 +6,7 @@ use gtk;
|
|||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use glib;
|
use glib;
|
||||||
use gdk::{EventButton, EventType};
|
use gdk::{EventButton, EventType};
|
||||||
|
use pango::{self, LayoutExt};
|
||||||
|
|
||||||
use neovim_lib::{Neovim, NeovimApi};
|
use neovim_lib::{Neovim, NeovimApi};
|
||||||
|
|
||||||
@ -23,6 +24,9 @@ struct State {
|
|||||||
scroll: gtk::ScrolledWindow,
|
scroll: gtk::ScrolledWindow,
|
||||||
css_provider: gtk::CssProvider,
|
css_provider: gtk::CssProvider,
|
||||||
info_label: gtk::Label,
|
info_label: gtk::Label,
|
||||||
|
word_column: gtk::TreeViewColumn,
|
||||||
|
kind_column: gtk::TreeViewColumn,
|
||||||
|
menu_column: gtk::TreeViewColumn,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
@ -34,24 +38,25 @@ impl State {
|
|||||||
style_context.add_provider(&css_provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
|
style_context.add_provider(&css_provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||||
|
|
||||||
let renderer = gtk::CellRendererText::new();
|
let renderer = gtk::CellRendererText::new();
|
||||||
|
renderer.set_property_ellipsize(pango::EllipsizeMode::End);
|
||||||
|
|
||||||
// word
|
// word
|
||||||
let column = gtk::TreeViewColumn::new();
|
let word_column = gtk::TreeViewColumn::new();
|
||||||
column.pack_start(&renderer, true);
|
word_column.pack_start(&renderer, true);
|
||||||
column.add_attribute(&renderer, "text", 0);
|
word_column.add_attribute(&renderer, "text", 0);
|
||||||
tree.append_column(&column);
|
tree.append_column(&word_column);
|
||||||
|
|
||||||
// kind
|
// kind
|
||||||
let column = gtk::TreeViewColumn::new();
|
let kind_column = gtk::TreeViewColumn::new();
|
||||||
column.pack_start(&renderer, true);
|
kind_column.pack_start(&renderer, true);
|
||||||
column.add_attribute(&renderer, "text", 1);
|
kind_column.add_attribute(&renderer, "text", 1);
|
||||||
tree.append_column(&column);
|
tree.append_column(&kind_column);
|
||||||
|
|
||||||
// menu
|
// menu
|
||||||
let column = gtk::TreeViewColumn::new();
|
let menu_column = gtk::TreeViewColumn::new();
|
||||||
column.pack_start(&renderer, true);
|
menu_column.pack_start(&renderer, true);
|
||||||
column.add_attribute(&renderer, "text", 2);
|
menu_column.add_attribute(&renderer, "text", 2);
|
||||||
tree.append_column(&column);
|
tree.append_column(&menu_column);
|
||||||
|
|
||||||
let info_label = gtk::Label::new(None);
|
let info_label = gtk::Label::new(None);
|
||||||
info_label.set_line_wrap(true);
|
info_label.set_line_wrap(true);
|
||||||
@ -63,6 +68,9 @@ impl State {
|
|||||||
renderer,
|
renderer,
|
||||||
css_provider,
|
css_provider,
|
||||||
info_label,
|
info_label,
|
||||||
|
word_column,
|
||||||
|
kind_column,
|
||||||
|
menu_column,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,11 +86,57 @@ impl State {
|
|||||||
self.select(selected);
|
self.select(selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn limit_column_widths(&self, menu: &[CompleteItem], shell: &shell::State) {
|
||||||
|
let layout = shell.font_ctx.create_layout();
|
||||||
|
let kind_chars = menu.iter().map(|i| i.kind.len()).max().unwrap();
|
||||||
|
let max_width = self.scroll.get_max_content_width();
|
||||||
|
let (xpad, _) = self.renderer.get_padding();
|
||||||
|
|
||||||
|
const DEFAULT_PADDING: i32 = 5;
|
||||||
|
|
||||||
|
if kind_chars > 0 {
|
||||||
|
layout.set_text("[v]");
|
||||||
|
let (kind_width, _) = layout.get_pixel_size();
|
||||||
|
|
||||||
|
self.word_column.set_fixed_width(max_width - kind_width);
|
||||||
|
|
||||||
|
self.kind_column.set_fixed_width(kind_width + xpad * 2 + DEFAULT_PADDING);
|
||||||
|
self.kind_column.set_visible(true);
|
||||||
|
} else {
|
||||||
|
let max_line = menu.iter().max_by_key(|m| m.word.len()).unwrap();
|
||||||
|
layout.set_text(max_line.word);
|
||||||
|
let (word_max_width, _) = layout.get_pixel_size();
|
||||||
|
|
||||||
|
self.kind_column.set_visible(false);
|
||||||
|
|
||||||
|
let word_column_width = word_max_width + xpad * 2 + DEFAULT_PADDING;
|
||||||
|
if word_column_width > max_width {
|
||||||
|
self.word_column.set_fixed_width(max_width);
|
||||||
|
} else {
|
||||||
|
self.word_column.set_fixed_width(word_column_width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let max_line = menu.iter().max_by_key(|m| m.menu.len()).unwrap();
|
||||||
|
|
||||||
|
if max_line.menu.len() > 0 {
|
||||||
|
layout.set_text(max_line.menu);
|
||||||
|
let (menu_max_width, _) = layout.get_pixel_size();
|
||||||
|
self.menu_column.set_fixed_width(menu_max_width + xpad * 2 + DEFAULT_PADDING);
|
||||||
|
self.menu_column.set_visible(true);
|
||||||
|
} else {
|
||||||
|
self.menu_column.set_visible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn update_tree(&self, menu: &[CompleteItem], shell: &shell::State) {
|
fn update_tree(&self, menu: &[CompleteItem], shell: &shell::State) {
|
||||||
if menu.is_empty() {
|
if menu.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.limit_column_widths(menu, shell);
|
||||||
|
|
||||||
self.renderer.set_property_font(
|
self.renderer.set_property_font(
|
||||||
Some(&shell.get_font_desc().to_string()),
|
Some(&shell.get_font_desc().to_string()),
|
||||||
);
|
);
|
||||||
|
@ -38,6 +38,10 @@ impl Context {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_layout(&self) -> pango::Layout {
|
||||||
|
pango::Layout::new(&self.state.pango_context)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn font_description(&self) -> &pango::FontDescription {
|
pub fn font_description(&self) -> &pango::FontDescription {
|
||||||
&self.state.font_desc
|
&self.state.font_desc
|
||||||
|
@ -836,9 +836,8 @@ fn set_nvim_initialized(state_arc: Arc<UiMutex<State>>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draw_initializing(state: &State, ctx: &cairo::Context) {
|
fn draw_initializing(state: &State, ctx: &cairo::Context) {
|
||||||
let layout = pangocairo::functions::create_layout(ctx).unwrap();
|
|
||||||
let desc = state.get_font_desc();
|
|
||||||
let alloc = state.drawing_area.get_allocation();
|
let alloc = state.drawing_area.get_allocation();
|
||||||
|
let layout = state.font_ctx.create_layout();
|
||||||
|
|
||||||
ctx.set_source_rgb(
|
ctx.set_source_rgb(
|
||||||
state.color_model.bg_color.0,
|
state.color_model.bg_color.0,
|
||||||
@ -847,7 +846,6 @@ fn draw_initializing(state: &State, ctx: &cairo::Context) {
|
|||||||
);
|
);
|
||||||
ctx.paint();
|
ctx.paint();
|
||||||
|
|
||||||
layout.set_font_description(desc);
|
|
||||||
layout.set_text("Loading->");
|
layout.set_text("Loading->");
|
||||||
let (width, height) = layout.get_pixel_size();
|
let (width, height) = layout.get_pixel_size();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user