Update cosmic-text
This commit is contained in:
parent
4e0e84a4b1
commit
d656254282
4 changed files with 117 additions and 121 deletions
|
|
@ -114,25 +114,6 @@ fn convert_color(colors: &Colors, color: Color) -> cosmic_text::Color {
|
|||
cosmic_text::Color::rgb(rgb.r, rgb.g, rgb.b)
|
||||
}
|
||||
|
||||
fn linear_color(color: cosmic_text::Color) -> cosmic_text::Color {
|
||||
// As described in: https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation
|
||||
fn linear_component(byte: u8) -> u8 {
|
||||
let float = byte as f32 / 255.0;
|
||||
let linear = if float < 0.04045 {
|
||||
float / 12.92
|
||||
} else {
|
||||
((float + 0.055) / 1.055).powf(2.4)
|
||||
};
|
||||
(linear * 255.0).round() as u8
|
||||
}
|
||||
cosmic_text::Color::rgba(
|
||||
linear_component(color.r()),
|
||||
linear_component(color.g()),
|
||||
linear_component(color.b()),
|
||||
color.a(),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||
pub struct Metadata {
|
||||
pub bg: cosmic_text::Color,
|
||||
|
|
@ -143,11 +124,18 @@ pub struct Metadata {
|
|||
impl Metadata {
|
||||
fn new(bg: cosmic_text::Color, underline_color: cosmic_text::Color) -> Self {
|
||||
let flags = Flags::empty();
|
||||
Self { bg, underline_color, flags }
|
||||
Self {
|
||||
bg,
|
||||
underline_color,
|
||||
flags,
|
||||
}
|
||||
}
|
||||
|
||||
fn with_underline_color(self, underline_color: cosmic_text::Color) -> Self {
|
||||
Self { underline_color, ..self }
|
||||
Self {
|
||||
underline_color,
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
fn with_flags(self, flags: Flags) -> Self {
|
||||
|
|
@ -682,9 +670,11 @@ impl Terminal {
|
|||
}
|
||||
|
||||
// Convert foreground to linear
|
||||
attrs = attrs.color(linear_color(fg));
|
||||
attrs = attrs.color(fg);
|
||||
|
||||
let underline_color = indexed.cell.underline_color()
|
||||
let underline_color = indexed
|
||||
.cell
|
||||
.underline_color()
|
||||
.map(|c| convert_color(&self.colors, c))
|
||||
.unwrap_or(fg);
|
||||
let metadata = Metadata::new(bg, fg)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ use std::{
|
|||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use crate::{Terminal, TerminalScroll, terminal::Metadata};
|
||||
use crate::{terminal::Metadata, Terminal, TerminalScroll};
|
||||
|
||||
pub struct TerminalBox<'a, Message> {
|
||||
terminal: &'a Mutex<Terminal>,
|
||||
|
|
@ -321,7 +321,10 @@ where
|
|||
|
||||
macro_rules! mk_pos_offset {
|
||||
($x_offset:expr, $bottom_offset:expr) => {
|
||||
Vector::new(self.start_x + $x_offset, self.line_top + self.line_height - $bottom_offset)
|
||||
Vector::new(
|
||||
self.start_x + $x_offset,
|
||||
self.line_top + self.line_height - $bottom_offset,
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -329,14 +332,13 @@ where
|
|||
($pos_offset:expr, $style_line_height:expr, $width:expr) => {
|
||||
Quad {
|
||||
bounds: Rectangle::new(
|
||||
self.view_position + $pos_offset,
|
||||
Size::new($width, $style_line_height),
|
||||
),
|
||||
border_radius: 0.0.into(),
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
self.view_position + $pos_offset,
|
||||
Size::new($width, $style_line_height),
|
||||
),
|
||||
border_radius: 0.0.into(),
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
}
|
||||
|
||||
};
|
||||
($pos_offset:expr, $style_line_height:expr) => {
|
||||
mk_quad!($pos_offset, $style_line_height, self.end_x - self.start_x)
|
||||
|
|
@ -351,7 +353,8 @@ where
|
|||
);
|
||||
|
||||
if !metadata.flags.is_empty() {
|
||||
let style_line_height = (self.glyph_font_size / 10.0).max(2.0).min(16.0);
|
||||
let style_line_height =
|
||||
(self.glyph_font_size / 10.0).max(2.0).min(16.0);
|
||||
|
||||
let line_color = cosmic_text_to_iced_color(metadata.underline_color);
|
||||
|
||||
|
|
@ -377,7 +380,7 @@ where
|
|||
let pos_offset1 = mk_pos_offset!(0.0, bottom_offset);
|
||||
let underline1_quad = mk_quad!(pos_offset1, style_line_height);
|
||||
|
||||
let pos_offset2 = mk_pos_offset!(0.0, bottom_offset/2.0);
|
||||
let pos_offset2 = mk_pos_offset!(0.0, bottom_offset / 2.0);
|
||||
let underline2_quad = mk_quad!(pos_offset2, style_line_height);
|
||||
|
||||
renderer.fill_quad(underline1_quad, line_color);
|
||||
|
|
@ -394,9 +397,10 @@ where
|
|||
while accu_width < full_width {
|
||||
dot_width = dot_width.min(full_width - accu_width);
|
||||
let pos_offset = mk_pos_offset!(accu_width, bottom_offset);
|
||||
let underline_quad = mk_quad!(pos_offset, style_line_height, dot_width);
|
||||
let underline_quad =
|
||||
mk_quad!(pos_offset, style_line_height, dot_width);
|
||||
renderer.fill_quad(underline_quad, line_color);
|
||||
accu_width += 2.0 * dot_width;
|
||||
accu_width += 2.0 * dot_width;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -410,16 +414,18 @@ where
|
|||
|
||||
// gap-width dash first
|
||||
let pos_offset = mk_pos_offset!(accu_width, bottom_offset);
|
||||
let underline_quad = mk_quad!(pos_offset, style_line_height, gap_width);
|
||||
let underline_quad =
|
||||
mk_quad!(pos_offset, style_line_height, gap_width);
|
||||
renderer.fill_quad(underline_quad, line_color);
|
||||
accu_width += gap_width * 2.0;
|
||||
|
||||
while accu_width < full_width {
|
||||
dash_width = dash_width.min(full_width - accu_width);
|
||||
let pos_offset = mk_pos_offset!(accu_width, bottom_offset);
|
||||
let underline_quad = mk_quad!(pos_offset, style_line_height, dash_width);
|
||||
let underline_quad =
|
||||
mk_quad!(pos_offset, style_line_height, dash_width);
|
||||
renderer.fill_quad(underline_quad, line_color);
|
||||
accu_width += dash_width + gap_width;
|
||||
accu_width += dash_width + gap_width;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -442,7 +448,8 @@ where
|
|||
};
|
||||
|
||||
let pos_offset = mk_pos_offset!(accu_width, dot_bottom_offset);
|
||||
let underline_quad = mk_quad!(pos_offset, style_line_height, dot_width);
|
||||
let underline_quad =
|
||||
mk_quad!(pos_offset, style_line_height, dot_width);
|
||||
renderer.fill_quad(underline_quad, line_color);
|
||||
accu_width += dot_width;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue