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;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use glib;
|
use glib;
|
||||||
use pango::FontDescription;
|
|
||||||
use gdk::{EventButton, EventType};
|
use gdk::{EventButton, EventType};
|
||||||
|
|
||||||
use neovim_lib::{Neovim, NeovimApi};
|
use neovim_lib::{Neovim, NeovimApi};
|
||||||
|
|
||||||
use nvim::ErrorReport;
|
use nvim::ErrorReport;
|
||||||
|
use shell;
|
||||||
use input;
|
use input;
|
||||||
|
|
||||||
const MAX_VISIBLE_ROWS: i32 = 10;
|
const MAX_VISIBLE_ROWS: i32 = 10;
|
||||||
@ -34,25 +33,26 @@ impl State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn before_show(&mut self,
|
fn before_show(&mut self,
|
||||||
nvim: &Rc<RefCell<Neovim>>,
|
shell: &shell::State,
|
||||||
font_desc: &FontDescription,
|
|
||||||
menu_items: &Vec<Vec<&str>>,
|
menu_items: &Vec<Vec<&str>>,
|
||||||
selected: i64) {
|
selected: i64) {
|
||||||
if self.nvim.is_none() {
|
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);
|
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() {
|
if menu.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.renderer
|
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 col_count = menu.get(0).unwrap().len();
|
||||||
let columns = self.tree.get_columns();
|
let columns = self.tree.get_columns();
|
||||||
@ -164,8 +164,7 @@ impl PopupMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn show(&mut self,
|
pub fn show(&mut self,
|
||||||
nvim: &Rc<RefCell<Neovim>>,
|
shell: &shell::State,
|
||||||
font_desc: &FontDescription,
|
|
||||||
menu_items: &Vec<Vec<&str>>,
|
menu_items: &Vec<Vec<&str>>,
|
||||||
selected: i64,
|
selected: i64,
|
||||||
x: i32,
|
x: i32,
|
||||||
@ -184,13 +183,16 @@ impl PopupMenu {
|
|||||||
});
|
});
|
||||||
self.state
|
self.state
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.before_show(&nvim, font_desc, menu_items, selected);
|
.before_show(shell, menu_items, selected);
|
||||||
self.popover.popup();
|
self.popover.popup()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hide(&mut self) {
|
pub fn hide(&mut self) {
|
||||||
self.open = false;
|
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) {
|
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>>>,
|
nvim: Option<Rc<RefCell<Neovim>>>,
|
||||||
font_desc: FontDescription,
|
font_desc: FontDescription,
|
||||||
cursor: Option<Cursor>,
|
cursor: Option<Cursor>,
|
||||||
popup_menu: PopupMenu,
|
popup_menu: RefCell<PopupMenu>,
|
||||||
settings: Rc<RefCell<Settings>>,
|
settings: Rc<RefCell<Settings>>,
|
||||||
|
|
||||||
line_height: Option<f64>,
|
line_height: Option<f64>,
|
||||||
@ -62,7 +62,7 @@ pub struct State {
|
|||||||
impl State {
|
impl State {
|
||||||
pub fn new(settings: Rc<RefCell<Settings>>, parent: &Arc<UiMutex<ui::Components>>) -> State {
|
pub fn new(settings: Rc<RefCell<Settings>>, parent: &Arc<UiMutex<ui::Components>>) -> State {
|
||||||
let drawing_area = DrawingArea::new();
|
let drawing_area = DrawingArea::new();
|
||||||
let popup_menu = PopupMenu::new(&drawing_area);
|
let popup_menu = RefCell::new(PopupMenu::new(&drawing_area));
|
||||||
|
|
||||||
State {
|
State {
|
||||||
model: UiModel::new(24, 80),
|
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> {
|
pub fn nvim(&self) -> RefMut<Neovim> {
|
||||||
self.nvim.as_ref().unwrap().borrow_mut()
|
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 {
|
fn create_pango_font(&self) -> FontDescription {
|
||||||
self.font_desc.clone()
|
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) {
|
pub fn set_font_desc(&mut self, desc: &str) {
|
||||||
self.font_desc = FontDescription::from_string(desc);
|
self.font_desc = FontDescription::from_string(desc);
|
||||||
self.line_height = None;
|
self.line_height = None;
|
||||||
@ -138,7 +154,7 @@ impl State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn close_popup_menu(&self) {
|
fn close_popup_menu(&self) {
|
||||||
if self.popup_menu.is_open() {
|
if self.popup_menu.borrow().is_open() {
|
||||||
let mut nvim = self.nvim();
|
let mut nvim = self.nvim();
|
||||||
nvim.input("<Esc>").report_err(&mut *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 point = ModelRect::point(col as usize, row as usize);
|
||||||
let (x, y, width, height) = point.to_area(line_height, char_width);
|
let (x, y, width, height) = point.to_area(line_height, char_width);
|
||||||
|
|
||||||
self.popup_menu.show(self.nvim.as_ref().unwrap(),
|
self.popup_menu.borrow_mut().show(&self,
|
||||||
&self.font_desc,
|
|
||||||
menu,
|
menu,
|
||||||
selected,
|
selected,
|
||||||
x,
|
x,
|
||||||
@ -841,12 +856,12 @@ impl RedrawEvents for State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn popupmenu_hide(&mut self) -> RepaintMode {
|
fn popupmenu_hide(&mut self) -> RepaintMode {
|
||||||
self.popup_menu.hide();
|
self.popup_menu.borrow_mut().hide();
|
||||||
RepaintMode::Nothing
|
RepaintMode::Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
fn popupmenu_select(&mut self, selected: i64) -> RepaintMode {
|
fn popupmenu_select(&mut self, selected: i64) -> RepaintMode {
|
||||||
self.popup_menu.select(selected);
|
self.popup_menu.borrow().select(selected);
|
||||||
RepaintMode::Nothing
|
RepaintMode::Nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
use std::slice::Iter;
|
use std::slice::Iter;
|
||||||
|
|
||||||
|
use gdk;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct Color(pub f64, pub f64, pub f64);
|
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_WHITE: Color = Color(1.0, 1.0, 1.0);
|
||||||
pub const COLOR_RED: Color = Color(1.0, 0.0, 0.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)]
|
#[derive(Clone)]
|
||||||
pub struct Attrs {
|
pub struct Attrs {
|
||||||
pub italic: bool,
|
pub italic: bool,
|
||||||
|
Loading…
Reference in New Issue
Block a user