Skip to content

Commit

Permalink
Rename "highlight" to "dilate"
Browse files Browse the repository at this point in the history
  • Loading branch information
farmaazon committed Apr 12, 2022
1 parent 5bb9fe7 commit 79258c9
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 54 deletions.
6 changes: 3 additions & 3 deletions lib/rust/ensogl/component/text/src/buffer/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def_style_property!(Size(f32));
def_style_property!(Bold(bool));
def_style_property!(Italic(bool));
def_style_property!(Underline(bool));
def_style_property!(Highlight(f32));
def_style_property!(Dilate(f32));

impl Default for Size {
fn default() -> Self {
Expand All @@ -248,7 +248,7 @@ impl Default for Underline {
}
}

impl Default for Highlight {
impl Default for Dilate {
fn default() -> Self {
Self::new(0.0)
}
Expand All @@ -260,7 +260,7 @@ define_styles! {
bold : Bold,
italics : Italic,
underline : Underline,
highlight : Highlight,
dilate : Dilate,
}


Expand Down
4 changes: 2 additions & 2 deletions lib/rust/ensogl/component/text/src/buffer/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ ensogl_core::define_endpoints! {
set_default_color (color::Rgba),
set_default_text_size (style::Size),
set_color_bytes (buffer::Range<Bytes>, color::Rgba),
set_highlight_bytes (buffer::Range<Bytes>, style::Highlight),
set_dilate_bytes (buffer::Range<Bytes>, style::Dilate),
}

Output {
Expand Down Expand Up @@ -450,7 +450,7 @@ impl View {
eval input.set_default_color ((t) m.set_default(*t));
eval input.set_default_text_size ((t) m.set_default(*t));
eval input.set_color_bytes (((range,color)) m.replace(range,*color));
eval input.set_highlight_bytes (((range,value)) m.replace(range,*value));
eval input.set_dilate_bytes (((range,value)) m.replace(range,*value));
eval input.set_default_color ((color) m.set_default(*color));

output.source.selection_edit_mode <+ sel_on_modification;
Expand Down
8 changes: 4 additions & 4 deletions lib/rust/ensogl/component/text/src/component/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ ensogl_core::define_endpoints! {
insert (String),
set_color_bytes (buffer::Range<Bytes>,color::Rgba),
set_color_all (color::Rgba),
set_highlight_bytes (buffer::Range<Bytes>,style::Highlight),
set_dilate_bytes (buffer::Range<Bytes>,style::Dilate),
set_default_color (color::Rgba),
set_selection_color (color::Rgb),
set_default_text_size (style::Size),
Expand Down Expand Up @@ -510,8 +510,8 @@ impl Area {

// === Style ===

m.buffer.frp.set_highlight_bytes <+ input.set_highlight_bytes;
eval_ input.set_highlight_bytes (m.redraw(false));
m.buffer.frp.set_dilate_bytes <+ input.set_dilate_bytes;
eval_ input.set_dilate_bytes (m.redraw(false));


// === Changes ===
Expand Down Expand Up @@ -849,7 +849,7 @@ impl AreaModel {
glyph.set_char(chr);
glyph.set_color(style.color);
glyph.set_bold(style.bold.raw);
glyph.set_highlight(style.highlight.raw);
glyph.set_dilate(style.dilate.raw);
glyph.set_font_size(chr_size);
match &last_cursor {
None => line_object.add_child(glyph),
Expand Down
12 changes: 6 additions & 6 deletions lib/rust/ensogl/component/text/src/typeface/glsl/glyph.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// A factor describing much the bold letters will be fattened, expressed as the fraction of font size.
const float BOLD_FATTING = 0.04;
// A factor describing much the bold letters will be dilated, expressed as the fraction of font size.
const float BOLD_DILATE = 0.04;

highp float median(highp vec3 v) {
return max(min(v.x, v.y), min(max(v.x, v.y), v.z));
Expand All @@ -22,12 +22,12 @@ highp vec2 get_texture_coord() {
return offset + msdf_fragment_uv() * msdf_fragment_size;
}

highp float get_fatting() {
highp float get_dilate() {
bool glyph_is_bold = (input_style & STYLE_BOLD_FLAG) != 0;
highp vec2 local_to_px_ratio = 1.0 / fwidth(input_local.xy);
highp float font_size_px = input_font_size * (local_to_px_ratio.x + local_to_px_ratio.y) / 2.0;
highp float fatting = (glyph_is_bold ? BOLD_FATTING : 0.0) + input_highlight;
return font_size_px * fatting;
highp float relative_dilate = (glyph_is_bold ? BOLD_DILATE : 0.0) + input_dilate;
return font_size_px * relative_dilate;
}

highp float msdf_alpha() {
Expand All @@ -41,7 +41,7 @@ highp float msdf_alpha() {
highp float dpi_dilate = avg_msdf_unit_px < input_msdf_range*0.49 ? 1.0 : 0.0;
highp vec3 msdf_sample = texture(input_atlas,tex_coord).rgb;
highp float sig_dist = median(msdf_sample) - 0.5;
highp float sig_dist_px = sig_dist * avg_msdf_unit_px + get_fatting();
highp float sig_dist_px = sig_dist * avg_msdf_unit_px + get_dilate();
highp float opacity = 0.5 + sig_dist_px + dpi_dilate * 0.08;
opacity = clamp(opacity, 0.0, 1.0);
return opacity;
Expand Down
12 changes: 6 additions & 6 deletions lib/rust/ensogl/component/text/src/typeface/glsl/glyph_mac.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// A factor describing much the bold letters will be fattened, expressed as the fraction of font size.
const float BOLD_FATTING = 0.04;
// A factor describing much the bold letters will be dilated, expressed as the fraction of font size.
const float BOLD_DILATE = 0.04;

highp float median(highp vec3 v) {
return max(min(v.x, v.y), min(max(v.x, v.y), v.z));
Expand All @@ -23,12 +23,12 @@ highp vec2 get_texture_coord() {
return offset + get_scaled_uv() * msdf_fragment_size;
}

highp float get_fatting() {
highp float get_dilate() {
bool glyph_is_bold = (input_style & STYLE_BOLD_FLAG) != 0;
highp vec2 local_to_px_ratio = 1.0 / fwidth(input_local.xy);
highp float font_size_px = input_font_size * (local_to_px_ratio.x + local_to_px_ratio.y) / 2.0;
highp float fatting = (glyph_is_bold ? BOLD_FATTING : 0.0) + input_highlight;
return font_size_px * fatting;
highp float relative_dilate = (glyph_is_bold ? BOLD_DILATE : 0.0) + input_dilate;
return font_size_px * relative_dilate;
}

// FIXME
Expand All @@ -47,7 +47,7 @@ highp float msdf_alpha() {
highp float dpi_dilate = avg_msdf_unit_px < input_msdf_range*0.49 ? 1.0 : 0.0;
highp vec3 msdf_sample = texture(input_atlas,tex_coord).rgb;
highp float sig_dist = median(msdf_sample) - 0.5;
highp float sig_dist_px = sig_dist * avg_msdf_unit_px + get_fatting();
highp float sig_dist_px = sig_dist * avg_msdf_unit_px + get_dilate();
highp float opacity = 0.5 + sig_dist_px + dpi_dilate * 0.08;
opacity += 0.6; // FIXME: Widen + sharpen
opacity = clamp(opacity, 0.0, 1.0);
Expand Down
31 changes: 10 additions & 21 deletions lib/rust/ensogl/component/text/src/typeface/glyph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct Glyph {
font_size: Attribute<f32>,
color: Attribute<Vector4<f32>>,
style: Attribute<i32>,
highlight: Attribute<f32>,
dilate: Attribute<f32>,
atlas_index: Attribute<f32>,
atlas: Uniform<Texture>,
char: Rc<Cell<char>>,
Expand All @@ -75,12 +75,12 @@ impl Glyph {
self.style.modify(|v| if value { *v |= style_flag::BOLD } else { *v &= !style_flag::BOLD });
}

pub fn highlight(&self) -> f32 {
self.highlight.get()
pub fn dilate(&self) -> f32 {
self.dilate.get()
}

pub fn set_highlight(&self, value: f32) {
self.highlight.set(value);
pub fn set_dilate(&self, value: f32) {
self.dilate.set(value);
}

pub fn font_size(&self) -> f32 {
Expand Down Expand Up @@ -141,7 +141,7 @@ pub struct System {
font_size: Buffer<f32>,
color: Buffer<Vector4<f32>>,
style: Buffer<i32>,
highlight: Buffer<f32>,
dilate: Buffer<f32>,
atlas_index: Buffer<f32>,
atlas: Uniform<Texture>,
}
Expand Down Expand Up @@ -173,7 +173,7 @@ impl System {
font_size: mesh.instance_scope().add_buffer("font_size"),
color: mesh.instance_scope().add_buffer("color"),
style: mesh.instance_scope().add_buffer("style"),
highlight: mesh.instance_scope().add_buffer("highlight"),
dilate: mesh.instance_scope().add_buffer("dilate"),
atlas_index: mesh.instance_scope().add_buffer("atlas_index"),
}
}
Expand All @@ -187,25 +187,14 @@ impl System {
let font_size = self.font_size.at(instance_id);
let color = self.color.at(instance_id);
let style = self.style.at(instance_id);
let highlight = self.highlight.at(instance_id);
let dilate = self.dilate.at(instance_id);
let atlas_index = self.atlas_index.at(instance_id);
let font = self.font.clone_ref();
let atlas = self.atlas.clone();
let char = default();
color.set(Vector4::new(0.0, 0.0, 0.0, 0.0));
atlas_index.set(0.0);
Glyph {
sprite,
context,
font,
font_size,
color,
style,
highlight,
atlas_index,
atlas,
char,
}
Glyph { sprite, context, font, font_size, color, style, dilate, atlas_index, atlas, char }
}

/// Get underlying sprite system.
Expand Down Expand Up @@ -243,7 +232,7 @@ impl System {
material.add_input("font_size", 10.0);
material.add_input("color", Vector4::new(0.0, 0.0, 0.0, 1.0));
material.add_input("style", 0);
material.add_input("highlight", 0.0);
material.add_input("dilate", 0.0);
// FIXME We need to use this output, as we need to declare the same amount of shader
// FIXME outputs as the number of attachments to framebuffer. We should manage this more
// FIXME intelligent. For example, we could allow defining output shader fragments,
Expand Down
15 changes: 3 additions & 12 deletions lib/rust/ensogl/example/text-area/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,9 @@ fn init(app: Application) {
area.hover();
area.set_cursor_at_end();

area.set_highlight_bytes(
ensogl_text::Range::new(7.bytes(), 15.bytes()),
style::Highlight(0.04),
);
area.set_highlight_bytes(
ensogl_text::Range::new(37.bytes(), 41.bytes()),
style::Highlight(0.05),
);
area.set_highlight_bytes(
ensogl_text::Range::new(55.bytes(), 56.bytes()),
style::Highlight(0.03),
);
area.set_dilate_bytes(ensogl_text::Range::new(7.bytes(), 15.bytes()), style::Dilate(0.04));
area.set_dilate_bytes(ensogl_text::Range::new(37.bytes(), 41.bytes()), style::Dilate(0.05));
area.set_dilate_bytes(ensogl_text::Range::new(55.bytes(), 56.bytes()), style::Dilate(0.03));

let scene = &app.display.default_scene;
let navigator = Navigator::new(scene, &scene.camera());
Expand Down

0 comments on commit 79258c9

Please sign in to comment.