feat: add support for blend=100 (#1195)

* feat: add support for blend=100

* feat: add support for blend between 0 and 100 for cursor

* fix: cursor not updating on window switch

* fix: crash on set cursor group

* chore: formatting

* chore: curr -> current
macos-click-through
Natasha England-Elbro 3 years ago committed by GitHub
parent 6b45dca453
commit 92bc1725f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -80,6 +80,14 @@ impl Cursor {
.unwrap_or_else(|| default_colors.foreground.unwrap()) .unwrap_or_else(|| default_colors.foreground.unwrap())
} }
pub fn alpha(&self) -> u8 {
return self
.style
.as_ref()
.map(|s| (255 as f32 * ((100 - s.blend) as f32 / (100.0 as f32))) as u8)
.unwrap_or(255);
}
pub fn change_mode(&mut self, cursor_mode: &CursorMode, styles: &HashMap<u64, Arc<Style>>) { pub fn change_mode(&mut self, cursor_mode: &CursorMode, styles: &HashMap<u64, Arc<Style>>) {
let CursorMode { let CursorMode {
shape, shape,

@ -60,6 +60,7 @@ pub struct Editor {
pub defined_styles: HashMap<u64, Arc<Style>>, pub defined_styles: HashMap<u64, Arc<Style>>,
pub mode_list: Vec<CursorMode>, pub mode_list: Vec<CursorMode>,
pub draw_command_batcher: Arc<DrawCommandBatcher>, pub draw_command_batcher: Arc<DrawCommandBatcher>,
pub current_mode_index: Option<u64>,
} }
impl Editor { impl Editor {
@ -70,6 +71,7 @@ impl Editor {
defined_styles: HashMap::new(), defined_styles: HashMap::new(),
mode_list: Vec::new(), mode_list: Vec::new(),
draw_command_batcher: Arc::new(DrawCommandBatcher::new()), draw_command_batcher: Arc::new(DrawCommandBatcher::new()),
current_mode_index: None,
} }
} }
@ -79,11 +81,21 @@ impl Editor {
RedrawEvent::SetTitle { title } => { RedrawEvent::SetTitle { title } => {
EVENT_AGGREGATOR.send(WindowCommand::TitleChanged(title)); EVENT_AGGREGATOR.send(WindowCommand::TitleChanged(title));
} }
RedrawEvent::ModeInfoSet { cursor_modes } => self.mode_list = cursor_modes, RedrawEvent::ModeInfoSet { cursor_modes } => {
self.mode_list = cursor_modes;
if let Some(current_mode_i) = self.current_mode_index.clone() {
if let Some(current_mode) = self.mode_list.get(current_mode_i as usize) {
self.cursor.change_mode(current_mode, &self.defined_styles)
}
}
}
RedrawEvent::OptionSet { gui_option } => self.set_option(gui_option), RedrawEvent::OptionSet { gui_option } => self.set_option(gui_option),
RedrawEvent::ModeChange { mode, mode_index } => { RedrawEvent::ModeChange { mode, mode_index } => {
if let Some(cursor_mode) = self.mode_list.get(mode_index as usize) { if let Some(cursor_mode) = self.mode_list.get(mode_index as usize) {
self.cursor.change_mode(cursor_mode, &self.defined_styles); self.cursor.change_mode(cursor_mode, &self.defined_styles);
self.current_mode_index = Some(mode_index)
} else {
self.current_mode_index = None
} }
self.draw_command_batcher self.draw_command_batcher
.queue(DrawCommand::ModeChanged(mode)) .queue(DrawCommand::ModeChanged(mode))

@ -340,7 +340,6 @@ impl CursorRenderer {
} else { } else {
self.previous_editor_mode = current_mode.clone(); self.previous_editor_mode = current_mode.clone();
} }
if !(self.cursor.enabled && render) { if !(self.cursor.enabled && render) {
return; return;
} }
@ -348,7 +347,8 @@ impl CursorRenderer {
let background_color = self let background_color = self
.cursor .cursor
.background(&grid_renderer.default_style.colors) .background(&grid_renderer.default_style.colors)
.to_color(); .to_color()
.with_a(self.cursor.alpha());
paint.set_color(background_color); paint.set_color(background_color);
// The cursor is made up of four points, so I create a path with each of the four // The cursor is made up of four points, so I create a path with each of the four
@ -367,7 +367,8 @@ impl CursorRenderer {
let foreground_color = self let foreground_color = self
.cursor .cursor
.foreground(&grid_renderer.default_style.colors) .foreground(&grid_renderer.default_style.colors)
.to_color(); .to_color()
.with_a(self.cursor.alpha());
paint.set_color(foreground_color); paint.set_color(foreground_color);
canvas.save(); canvas.save();

Loading…
Cancel
Save