Davejkane / riv

Riv - The Rust Image Viewer
MIT License
99 stars 10 forks source link

Panning when no images crashes program #71

Closed Davejkane closed 5 years ago

gurgalex commented 5 years ago

Complicating the codebase, but more correct. Use lots of options is what the tests made during the refactor I'm working on for paths and screen led to.

Thank you compiler for all 33 places where I need to consider the possibility the index could be empty. private functions or inner functions per file are great for when I've already garenteed the option is always some at this point.

#[derive(Debug)]
pub struct PathsBuilder {
    /// images is the paths of all the images currently in the program.
    images: Vec<PathBuf>,
    /// dest_folder is the path of the destination folder for moving and copying images.
    dest_folder: PathBuf,
    /// current_dir is the path of the current directory where the program was launched from
    base_dir: PathBuf,
    /// index is the index of the images vector of the current image to be displayed.
    index: Option<usize>,
    /// Artificial user facing length of images limited by max cli argument. None if unlimited
    max_viewable: Option<usize>,
    /// Actual length the user said was maximum for images
    actual_max_viewable: Option<usize>,
}
pub struct Screen<'a> {
    /// sdl_context is required for running SDL
    pub sdl_context: Sdl,
    /// canvas is where images and text will be rendered
    pub canvas: WindowCanvas,
    /// texture_creator is used for loading images
    pub texture_creator: &'a TextureCreator<WindowContext>,
    /// font is used for printing text
    pub font: Font<'a, 'static>,
    /// mono_font is used for printing mono spaced text
    pub mono_font: Font<'a, 'static>,
    /// last_index is the index of the last texture rendered
    pub last_index: Option<usize>,
    /// last_texture is the last image texture rendered
    pub last_texture: Option<sdl2::render::Texture<'a>>,
    /// dirty, if true indicates that last texture must be discarded
    pub dirty: bool,
}