Просмотр исходного кода

wallet/text: make emojis larger by adding EMOJI_SCALE_FACT const

darkfi 1 год назад
Родитель
Сommit
7251272ac4
2 измененных файлов с 20 добавлено и 15 удалено
  1. 11 11
      bin/darkwallet/src/text/mod.rs
  2. 9 4
      bin/darkwallet/src/ui/chatedit.rs

+ 11 - 11
bin/darkwallet/src/text/mod.rs

@@ -41,6 +41,11 @@ pub use atlas::{make_texture_atlas, Atlas, RenderedAtlas};
 mod wrap;
 pub use wrap::{glyph_str, wrap};
 
+// Upscale emoji relative to font size
+pub const EMOJI_SCALE_FACT: f32 = 1.5;
+// How much of the emoji is above baseline?
+pub const EMOJI_PROP_ABOVE_BASELINE: f32 = 0.75;
+
 // From https://sourceforge.net/projects/freetype/files/freetype2/2.6/
 //
 // * An `FT_Face' object can only be safely used from one thread at
@@ -77,14 +82,8 @@ pub struct GlyphPositionIter<'a> {
 
 impl<'a> GlyphPositionIter<'a> {
     pub fn new(font_size: f32, window_scale: f32, glyphs: &'a Vec<Glyph>, baseline_y: f32) -> Self {
-        Self {
-            font_size,
-            window_scale,
-            glyphs,
-            current_x: 0.,
-            current_y: baseline_y * window_scale,
-            i: 0,
-        }
+        let start_y = baseline_y * window_scale;
+        Self { font_size, window_scale, glyphs, current_x: 0., current_y: start_y, i: 0 }
     }
 }
 
@@ -102,11 +101,12 @@ impl<'a> Iterator for GlyphPositionIter<'a> {
 
         let rect = if sprite.has_fixed_sizes {
             // Downscale by height
-            let w = (sprite.bmp_width as f32 * self.font_size) / sprite.bmp_height as f32;
-            let h = self.font_size;
+            let w = (sprite.bmp_width as f32 * EMOJI_SCALE_FACT * self.font_size) /
+                sprite.bmp_height as f32;
+            let h = EMOJI_SCALE_FACT * self.font_size;
 
             let x = self.current_x;
-            let y = self.current_y - h;
+            let y = self.current_y - EMOJI_PROP_ABOVE_BASELINE * h;
 
             self.current_x += w;
 

+ 9 - 4
bin/darkwallet/src/ui/chatedit.rs

@@ -620,10 +620,15 @@ impl ChatEdit {
             is_mouse_hover: AtomicBool::new(false),
         });
 
-        self_.text_wrap.lock().editable.set_text(
-            "".to_string(),
-            "A berry is a small, pulpy, and often edible fruit. Typically, berries are juicy, rounded, brightly colored, sweet, sour or tart, and do not have a stone or pit, although many pips or seeds may be present. Common examples of berries in the culinary sense are strawberries, raspberries, blueberries, blackberries, white currants, blackcurrants, and redcurrants. In Britain, soft fruit is a horticultural term for such fruits.".to_string()
-        );
+        //self_
+        //    .text_wrap
+        //    .lock()
+        //    .editable
+        //    .set_text("".to_string(), "king!😁🍆jelly 🍆1234".to_string());
+        //self_.text_wrap.lock().editable.set_text(
+        //    "".to_string(),
+        //    "A berry is a small, pulpy, and often edible fruit. Typically, berries are juicy, rounded, brightly colored, sweet, sour or tart, and do not have a stone or pit, although many pips or seeds may be present. Common examples of berries in the culinary sense are strawberries, raspberries, blueberries, blackberries, white currants, blackcurrants, and redcurrants. In Britain, soft fruit is a horticultural term for such fruits.".to_string()
+        //);
         //self_
         //    .text_wrap
         //    .lock()