Add an option to set selected text color
This commit is contained in:
parent
3c94352f3f
commit
10ae9a9b16
4 changed files with 22 additions and 2 deletions
|
|
@ -17,6 +17,7 @@ fn redraw(
|
|||
let font_color = Color::rgb(0xFF, 0xFF, 0xFF);
|
||||
let cursor_color = Color::rgb(0xFF, 0xFF, 0xFF);
|
||||
let selection_color = Color::rgba(0xFF, 0xFF, 0xFF, 0x33);
|
||||
let selected_text_color = Color::rgb(0xF0, 0xF0, 0xFF);
|
||||
|
||||
editor.shape_as_needed(true);
|
||||
if editor.redraw() {
|
||||
|
|
@ -29,6 +30,7 @@ fn redraw(
|
|||
font_color,
|
||||
cursor_color,
|
||||
selection_color,
|
||||
selected_text_color,
|
||||
|x, y, w, h, color| {
|
||||
window.rect(x, y, w, h, orbclient::Color { data: color.0 });
|
||||
},
|
||||
|
|
|
|||
|
|
@ -138,6 +138,7 @@ fn main() {
|
|||
let font_color = Color::rgb(0xFF, 0xFF, 0xFF);
|
||||
let cursor_color = Color::rgb(0xFF, 0xFF, 0xFF);
|
||||
let selection_color = Color::rgba(0xFF, 0xFF, 0xFF, 0x33);
|
||||
let selected_text_color = Color::rgb(0xA0, 0xA0, 0xFF);
|
||||
|
||||
event_loop
|
||||
.run(|event, elwt| {
|
||||
|
|
@ -193,6 +194,7 @@ fn main() {
|
|||
font_color,
|
||||
cursor_color,
|
||||
selection_color,
|
||||
selected_text_color,
|
||||
|x, y, w, h, color| {
|
||||
// Note: due to softbuffer and tiny_skia having incompatible internal color representations we swap
|
||||
// the red and blue channels here
|
||||
|
|
|
|||
|
|
@ -50,10 +50,12 @@ impl<'buffer> Editor<'buffer> {
|
|||
text_color: Color,
|
||||
cursor_color: Color,
|
||||
selection_color: Color,
|
||||
selected_text_color: Color,
|
||||
mut f: F,
|
||||
) where
|
||||
F: FnMut(i32, i32, u32, u32, Color),
|
||||
{
|
||||
let selection_bounds = self.selection_bounds();
|
||||
self.with_buffer(|buffer| {
|
||||
for run in buffer.layout_runs() {
|
||||
let line_i = run.line_i;
|
||||
|
|
@ -98,7 +100,7 @@ impl<'buffer> Editor<'buffer> {
|
|||
};
|
||||
|
||||
// Highlight selection
|
||||
if let Some((start, end)) = self.selection_bounds() {
|
||||
if let Some((start, end)) = selection_bounds {
|
||||
if line_i >= start.line && line_i <= end.line {
|
||||
let mut range_opt = None;
|
||||
for glyph in run.glyphs.iter() {
|
||||
|
|
@ -191,10 +193,21 @@ impl<'buffer> Editor<'buffer> {
|
|||
for glyph in run.glyphs.iter() {
|
||||
let physical_glyph = glyph.physical((0., 0.), 1.0);
|
||||
|
||||
let glyph_color = match glyph.color_opt {
|
||||
let mut glyph_color = match glyph.color_opt {
|
||||
Some(some) => some,
|
||||
None => text_color,
|
||||
};
|
||||
if text_color != selected_text_color {
|
||||
if let Some((start, end)) = selection_bounds {
|
||||
if line_i >= start.line
|
||||
&& line_i <= end.line
|
||||
&& (start.line != line_i || glyph.end > start.index)
|
||||
&& (end.line != line_i || glyph.start < end.index)
|
||||
{
|
||||
glyph_color = selected_text_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cache.with_pixels(
|
||||
font_system,
|
||||
|
|
@ -880,6 +893,7 @@ impl<'font_system, 'buffer> BorrowedWithFontSystem<'font_system, Editor<'buffer>
|
|||
text_color: Color,
|
||||
cursor_color: Color,
|
||||
selection_color: Color,
|
||||
selected_text_color: Color,
|
||||
f: F,
|
||||
) where
|
||||
F: FnMut(i32, i32, u32, u32, Color),
|
||||
|
|
@ -890,6 +904,7 @@ impl<'font_system, 'buffer> BorrowedWithFontSystem<'font_system, Editor<'buffer>
|
|||
text_color,
|
||||
cursor_color,
|
||||
selection_color,
|
||||
selected_text_color,
|
||||
f,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -208,6 +208,7 @@ impl<'syntax_system, 'buffer> SyntaxEditor<'syntax_system, 'buffer> {
|
|||
self.foreground_color(),
|
||||
self.cursor_color(),
|
||||
self.selection_color(),
|
||||
self.foreground_color(),
|
||||
f,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue