outline font cheat sheet no longer draws out of bounds. - icy_draw - icy_draw is the successor to mystic draw. fork / mirror
 (HTM) git clone https://git.drkhsh.at/icy_draw.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 2ec02f9657d8628da64ad832ac8b39059b904977
 (DIR) parent 7bd19d285c06acf91f2c41c268e1cd4c2ba5d232
 (HTM) Author: Mike Krüger <mkrueger@posteo.de>
       Date:   Fri, 22 Sep 2023 09:27:20 +0200
       
       outline font cheat sheet no longer draws out of bounds.
       
       Happened on small widget sizes.
       
       Diffstat:
         M src/ui/editor/charfont/mod.rs       |      40 ++++++++++++++++++++++++++-----
       
       1 file changed, 34 insertions(+), 6 deletions(-)
       ---
 (DIR) diff --git a/src/ui/editor/charfont/mod.rs b/src/ui/editor/charfont/mod.rs
       @@ -31,6 +31,7 @@ pub struct CharFontEditor {
            fonts: Vec<TheDrawFont>,
            undostack_len: usize,
            last_update_preview: usize,
       +    last_update_preview_attr: TextAttribute,
            outline_selection: crate::SelectOutlineDialog,
            draw_outline_bg: bool,
            opt_cheat_sheet: Option<RetainedImage>,
       @@ -276,7 +277,7 @@ impl Document for CharFontEditor {
        
                        let mut is_outline = false;
                        for layer in &mut self
       -                    .ansi_editor
       +                .ansi_editor
                            .buffer_view
                            .lock()
                            .get_edit_state_mut()
       @@ -285,14 +286,13 @@ impl Document for CharFontEditor {
                        {
                            match self.fonts[self.selected_font].font_type {
                                icy_engine::FontType::Outline => {
       -                            layer.forced_output_attribute = Some(attr);
                                    is_outline = true;
       +                            set_attribute(layer, attr);
                                }
                                icy_engine::FontType::Block => {
       -                            layer.forced_output_attribute = Some(attr);
       +                            set_attribute(layer, attr);
                                }
                                icy_engine::FontType::Color => {
       -                            layer.forced_output_attribute = None;
                                }
                            }
                        }
       @@ -392,7 +392,13 @@ impl Document for CharFontEditor {
        
                                if let Some(cheat_sheet) = & self.opt_cheat_sheet {
                                    ui.vertical_centered(|ui| {
       -                            cheat_sheet.show(ui);
       +                                let width = ui.available_width();
       +                                let mut size = Vec2::new(cheat_sheet.width() as f32, cheat_sheet.height() as f32);
       +                                if width < size.x {
       +                                    size.y *= width / size.x;
       +                                    size.x = width;
       +                                }
       +                                cheat_sheet.show_size(ui, size);
                                    });
                                }
                            });
       @@ -413,8 +419,16 @@ impl Document for CharFontEditor {
                    .lock()
                    .get_edit_state()
                    .undo_stack_len();
       -        if self.last_update_preview != u {
       +        let attr = self
       +            .ansi_editor
       +            .buffer_view
       +            .lock()
       +            .get_edit_state()
       +            .get_caret()
       +            .get_attribute();
       +        if self.last_update_preview != u || self.last_update_preview_attr != attr {
                    self.last_update_preview = u;
       +            self.last_update_preview_attr = attr;
                    self.save_old_selected_char();
                    self.render_outline_preview();
                }
       @@ -436,6 +450,19 @@ impl Document for CharFontEditor {
            }
        }
        
       +fn set_attribute(layer: &mut Layer, attr: TextAttribute) {
       +    for y in 0..layer.get_size().height {
       +        for x in 0..layer.get_size().width {
       +            let mut c = layer.get_char((x, y));
       +            if !c.is_visible() {
       +                continue;
       +            }
       +            c.attribute = attr;
       +            layer.set_char((x, y), c);
       +        }
       +    }
       +}
       +
        impl CharFontEditor {
            pub fn new(gl: &Arc<glow::Context>, id: usize, fonts: Vec<TheDrawFont>) -> Self {
                let mut buffer = Buffer::new(Size::new(30, 12));
       @@ -462,6 +489,7 @@ impl CharFontEditor {
                    last_update_preview: 0,
                    opt_cheat_sheet: None,
                    draw_outline_bg: true,
       +            last_update_preview_attr: TextAttribute::default(),
                };
                res.show_selected_char();
                res