URI: 
       Added outline switch buttons. - icy_draw - icy_draw is the successor to mystic draw. fork / mirror
  HTML git clone https://git.drkhsh.at/icy_draw.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit bc6ca95451bfa24abb0767194d82a3ca34856e1e
   DIR parent f74759aab4f5af9eaf482a8ef6e90f69da423e9c
  HTML Author: Mike Krüger <mkrueger@posteo.de>
       Date:   Thu, 27 Jul 2023 19:06:39 +0200
       
       Added outline switch buttons.
       
       Diffstat:
         M src/model/editor/mod.rs             |      14 +++++++-------
         M src/model/tool/line_imp.rs          |      24 ++++++++++++------------
         M src/model/tool/mod.rs               |       2 +-
         M src/ui/ansi_editor/mod.rs           |      25 +++++++++++++++++++------
       
       4 files changed, 39 insertions(+), 26 deletions(-)
       ---
   DIR diff --git a/src/model/editor/mod.rs b/src/model/editor/mod.rs
       @@ -55,7 +55,7 @@ pub struct Editor {
            pub caret: Caret,
            pub cur_selection: Option<Selection>,
        
       -    cur_outline: i32,
       +    pub cur_outline: usize,
            pub is_inactive: bool,
            pub cur_font_page: usize,
        
       @@ -200,11 +200,11 @@ impl Editor {
                Event::CursorPositionChange(old, self.caret.get_position())
            }
        
       -    pub fn get_cur_outline(&self) -> i32 {
       +    pub fn get_cur_outline(&self) -> usize {
                self.cur_outline
            }
        
       -    pub fn set_cur_outline(&mut self, outline: i32) {
       +    pub fn set_cur_outline(&mut self, outline: usize) {
                self.cur_outline = outline;
                //(self.outline_changed)(self);
            }
       @@ -222,8 +222,8 @@ impl Editor {
                Ok(true)
            }
        
       -    pub fn get_outline_char_code(&self, i: i32) -> Result<u16, &str> {
       -        if self.cur_outline < 0 || self.cur_outline >= DEFAULT_OUTLINE_TABLE.len() as i32 {
       +    pub fn get_outline_char_code(&self, i: usize) -> Result<u16, &str> {
       +        if self.cur_outline >= DEFAULT_OUTLINE_TABLE.len() {
                    return Err("current outline out of range.");
                }
                if !(0..=10).contains(&i) {
       @@ -233,8 +233,8 @@ impl Editor {
                Ok(DEFAULT_OUTLINE_TABLE[self.cur_outline as usize][i as usize] as u16)
            }
        
       -    pub fn get_outline_char_code_from(outline: i32, i: i32) -> Result<u16, &'static str> {
       -        if outline < 0 || outline >= DEFAULT_OUTLINE_TABLE.len() as i32 {
       +    pub fn get_outline_char_code_from(outline: usize, i: usize) -> Result<u16, &'static str> {
       +        if  outline >= DEFAULT_OUTLINE_TABLE.len() {
                    return Err("current outline out of range.");
                }
                if !(0..=10).contains(&i) {
   DIR diff --git a/src/model/tool/line_imp.rs b/src/model/tool/line_imp.rs
       @@ -38,22 +38,22 @@ impl Plottable for LineTool {
            }
        }
        
       -const CORNER_UPPER_LEFT: i32 = 0;
       -const CORNER_UPPER_RIGHT: i32 = 1;
       -const CORNER_LOWER_LEFT: i32 = 2;
       -const CORNER_LOWER_RIGHT: i32 = 3;
       +const CORNER_UPPER_LEFT: usize = 0;
       +const CORNER_UPPER_RIGHT: usize = 1;
       +const CORNER_LOWER_LEFT: usize = 2;
       +const CORNER_LOWER_RIGHT: usize = 3;
        
       -const HORIZONTAL_CHAR: i32 = 4;
       -const VERTICAL_CHAR: i32 = 5;
       +const HORIZONTAL_CHAR: usize = 4;
       +const VERTICAL_CHAR: usize = 5;
        
       -const VERT_RIGHT_CHAR: i32 = 6;
       -const VERT_LEFT_CHAR: i32 = 7;
       +const VERT_RIGHT_CHAR: usize = 6;
       +const VERT_LEFT_CHAR: usize = 7;
        
       -const HORIZ_UP_CHAR: i32 = 8;
       -const HORIZ_DOWN_CHAR: i32 = 9;
       +const HORIZ_UP_CHAR: usize = 8;
       +const HORIZ_DOWN_CHAR: usize = 9;
        
        impl LineTool {
       -    pub fn get_new_horiz_char(editor: &mut Editor, new_char: u16, to_left: bool) -> i32 {
       +    pub fn get_new_horiz_char(editor: &mut Editor, new_char: u16, to_left: bool) -> usize {
                if new_char == editor.get_outline_char_code(VERTICAL_CHAR).unwrap() {
                    if to_left {
                        VERT_RIGHT_CHAR
       @@ -117,7 +117,7 @@ impl LineTool {
                }
            }
        
       -    pub fn get_new_vert_char(editor: &mut Editor, new_char: u16, to_left: bool) -> i32 {
       +    pub fn get_new_vert_char(editor: &mut Editor, new_char: u16, to_left: bool) -> usize {
                if new_char == editor.get_outline_char_code(HORIZONTAL_CHAR).unwrap() {
                    if to_left {
                        HORIZ_DOWN_CHAR
   DIR diff --git a/src/model/tool/mod.rs b/src/model/tool/mod.rs
       @@ -338,7 +338,7 @@ pub trait Tool {
            }
        }
        
       -fn handle_outline_insertion(editor: &mut Editor, modifier: MModifiers, outline: i32) {
       +fn handle_outline_insertion(editor: &mut Editor, modifier: MModifiers, outline: usize) {
            if let MModifiers::Control = modifier {
                editor.set_cur_outline(outline);
                return;
   DIR diff --git a/src/ui/ansi_editor/mod.rs b/src/ui/ansi_editor/mod.rs
       @@ -1,5 +1,5 @@
        use eframe::{
       -    egui::{self, CursorIcon, PointerButton, ScrollArea},
       +    egui::{self, CursorIcon, PointerButton, ScrollArea, Button},
            epaint::{Pos2, Rect, Vec2},
        };
        use i18n_embed_fl::fl;
       @@ -25,7 +25,7 @@ pub mod key_maps;
        pub use key_maps::*;
        
        use crate::{
       -    model::{brush_imp::draw_glyph, MKey, MModifiers, Tool},
       +    model::{brush_imp::draw_glyph, MKey, MModifiers, Tool, DEFAULT_OUTLINE_TABLE},
            Document, TerminalResult,
        };
        
       @@ -420,30 +420,43 @@ impl Document for AnsiEditor {
                        ));
        
                        ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
       +                    let cur_outline = self.buffer_view.lock().unwrap().editor.cur_outline;
       +                    let cur_font_page = self.buffer_view.lock().unwrap().editor.cur_font_page;
       +
                            ui.horizontal(|ui| {
       +                        if ui.add(Button::new("▶").frame(false)).clicked() {
       +                            self.buffer_view.lock().unwrap().editor.cur_outline = (cur_outline + 1) % DEFAULT_OUTLINE_TABLE.len();
       +                        }
       +                        ui.label(cur_outline.to_string());
       +                        if ui.add(Button::new("◀").frame(false)).clicked() {
       +                            self.buffer_view.lock().unwrap().editor.cur_outline = (cur_outline + DEFAULT_OUTLINE_TABLE.len() - 1) % DEFAULT_OUTLINE_TABLE.len();
       +                        }
       +
                                for i in (0..10).into_iter().rev() {
                                    let ch = self
                                        .buffer_view
                                        .lock()
                                        .unwrap()
                                        .editor
       -                                .get_outline_char_code(i as i32)
       +                                .get_outline_char_code(i)
                                        .unwrap();
       -                            let cur_page = self.buffer_view.lock().unwrap().editor.cur_font_page;
                                    ui.add(crate::model::pencil_imp::draw_glyph_plain(
                                        self.buffer_view.clone(),
                                        unsafe { char::from_u32_unchecked(ch as u32) },
       -                                cur_page,
       +                                cur_font_page,
                                    ));
                                    ui.label(format!("F{}", i + 1));
                                }
       -
       +                        
                                ui.label(fl!(
                                    crate::LANGUAGE_LOADER,
                                    "toolbar-size",
                                    colums = width,
                                    rows = height
                                ));
       +
       +                        
       +                        
                            });
                        });
                    });