Bg/Fg colors, fix popup in case of string wrap
This commit is contained in:
parent
5f7019dd0d
commit
f32ddbd69c
@ -5,13 +5,12 @@ use std::cmp::min;
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
use glib;
|
||||
use pango::FontDescription;
|
||||
use gdk::{EventButton, EventType};
|
||||
|
||||
use neovim_lib::{Neovim, NeovimApi};
|
||||
|
||||
use nvim::ErrorReport;
|
||||
|
||||
use shell;
|
||||
use input;
|
||||
|
||||
const MAX_VISIBLE_ROWS: i32 = 10;
|
||||
@ -34,25 +33,26 @@ impl State {
|
||||
}
|
||||
|
||||
fn before_show(&mut self,
|
||||
nvim: &Rc<RefCell<Neovim>>,
|
||||
font_desc: &FontDescription,
|
||||
shell: &shell::State,
|
||||
menu_items: &Vec<Vec<&str>>,
|
||||
selected: i64) {
|
||||
if self.nvim.is_none() {
|
||||
self.nvim = Some(nvim.clone());
|
||||
self.nvim = Some(shell.nvim_clone());
|
||||
}
|
||||
|
||||
self.update_tree(menu_items, font_desc);
|
||||
self.update_tree(menu_items, shell);
|
||||
self.select(selected);
|
||||
}
|
||||
|
||||
fn update_tree(&self, menu: &Vec<Vec<&str>>, font_desc: &FontDescription) {
|
||||
fn update_tree(&self, menu: &Vec<Vec<&str>>, shell: &shell::State) {
|
||||
if menu.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
self.renderer
|
||||
.set_property_font(Some(&font_desc.to_string()));
|
||||
.set_property_font(Some(&shell.get_font_desc().to_string()));
|
||||
self.renderer.set_property_foreground_rgba(Some(&shell.get_foreground().into()));
|
||||
self.renderer.set_property_background_rgba(Some(&shell.get_background().into()));
|
||||
|
||||
let col_count = menu.get(0).unwrap().len();
|
||||
let columns = self.tree.get_columns();
|
||||
@ -164,8 +164,7 @@ impl PopupMenu {
|
||||
}
|
||||
|
||||
pub fn show(&mut self,
|
||||
nvim: &Rc<RefCell<Neovim>>,
|
||||
font_desc: &FontDescription,
|
||||
shell: &shell::State,
|
||||
menu_items: &Vec<Vec<&str>>,
|
||||
selected: i64,
|
||||
x: i32,
|
||||
@ -184,13 +183,16 @@ impl PopupMenu {
|
||||
});
|
||||
self.state
|
||||
.borrow_mut()
|
||||
.before_show(&nvim, font_desc, menu_items, selected);
|
||||
self.popover.popup();
|
||||
.before_show(shell, menu_items, selected);
|
||||
self.popover.popup()
|
||||
}
|
||||
|
||||
pub fn hide(&mut self) {
|
||||
self.open = false;
|
||||
self.popover.popdown();
|
||||
// popdown() in case of fast hide/show
|
||||
// situation does not work and just close popup window
|
||||
// so hide() is important here
|
||||
self.popover.hide();
|
||||
}
|
||||
|
||||
pub fn select(&self, selected: i64) {
|
||||
|
29
src/shell.rs
29
src/shell.rs
@ -48,7 +48,7 @@ pub struct State {
|
||||
nvim: Option<Rc<RefCell<Neovim>>>,
|
||||
font_desc: FontDescription,
|
||||
cursor: Option<Cursor>,
|
||||
popup_menu: PopupMenu,
|
||||
popup_menu: RefCell<PopupMenu>,
|
||||
settings: Rc<RefCell<Settings>>,
|
||||
|
||||
line_height: Option<f64>,
|
||||
@ -62,7 +62,7 @@ pub struct State {
|
||||
impl State {
|
||||
pub fn new(settings: Rc<RefCell<Settings>>, parent: &Arc<UiMutex<ui::Components>>) -> State {
|
||||
let drawing_area = DrawingArea::new();
|
||||
let popup_menu = PopupMenu::new(&drawing_area);
|
||||
let popup_menu = RefCell::new(PopupMenu::new(&drawing_area));
|
||||
|
||||
State {
|
||||
model: UiModel::new(24, 80),
|
||||
@ -88,10 +88,22 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_foreground(&self) -> &Color {
|
||||
&self.fg_color
|
||||
}
|
||||
|
||||
pub fn get_background(&self) -> &Color {
|
||||
&self.bg_color
|
||||
}
|
||||
|
||||
pub fn nvim(&self) -> RefMut<Neovim> {
|
||||
self.nvim.as_ref().unwrap().borrow_mut()
|
||||
}
|
||||
|
||||
pub fn nvim_clone(&self) -> Rc<RefCell<Neovim>> {
|
||||
self.nvim.as_ref().unwrap().clone()
|
||||
}
|
||||
|
||||
fn create_pango_font(&self) -> FontDescription {
|
||||
self.font_desc.clone()
|
||||
}
|
||||
@ -115,6 +127,10 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_font_desc(&self) -> &FontDescription {
|
||||
&self.font_desc
|
||||
}
|
||||
|
||||
pub fn set_font_desc(&mut self, desc: &str) {
|
||||
self.font_desc = FontDescription::from_string(desc);
|
||||
self.line_height = None;
|
||||
@ -138,7 +154,7 @@ impl State {
|
||||
}
|
||||
|
||||
fn close_popup_menu(&self) {
|
||||
if self.popup_menu.is_open() {
|
||||
if self.popup_menu.borrow().is_open() {
|
||||
let mut nvim = self.nvim();
|
||||
nvim.input("<Esc>").report_err(&mut *nvim);
|
||||
}
|
||||
@ -825,8 +841,7 @@ impl RedrawEvents for State {
|
||||
let point = ModelRect::point(col as usize, row as usize);
|
||||
let (x, y, width, height) = point.to_area(line_height, char_width);
|
||||
|
||||
self.popup_menu.show(self.nvim.as_ref().unwrap(),
|
||||
&self.font_desc,
|
||||
self.popup_menu.borrow_mut().show(&self,
|
||||
menu,
|
||||
selected,
|
||||
x,
|
||||
@ -841,12 +856,12 @@ impl RedrawEvents for State {
|
||||
}
|
||||
|
||||
fn popupmenu_hide(&mut self) -> RepaintMode {
|
||||
self.popup_menu.hide();
|
||||
self.popup_menu.borrow_mut().hide();
|
||||
RepaintMode::Nothing
|
||||
}
|
||||
|
||||
fn popupmenu_select(&mut self, selected: i64) -> RepaintMode {
|
||||
self.popup_menu.select(selected);
|
||||
self.popup_menu.borrow().select(selected);
|
||||
RepaintMode::Nothing
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
use std::slice::Iter;
|
||||
|
||||
use gdk;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct Color(pub f64, pub f64, pub f64);
|
||||
|
||||
@ -7,6 +9,17 @@ pub const COLOR_BLACK: Color = Color(0.0, 0.0, 0.0);
|
||||
pub const COLOR_WHITE: Color = Color(1.0, 1.0, 1.0);
|
||||
pub const COLOR_RED: Color = Color(1.0, 0.0, 0.0);
|
||||
|
||||
impl <'a> Into<gdk::RGBA> for &'a Color {
|
||||
fn into(self) -> gdk::RGBA {
|
||||
gdk::RGBA {
|
||||
red: self.0,
|
||||
green: self.1,
|
||||
blue: self.2,
|
||||
alpha: 1.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Attrs {
|
||||
pub italic: bool,
|
||||
|
Loading…
Reference in New Issue
Block a user