mirror of
https://github.com/13hannes11/focus_annotator.git
synced 2024-09-03 23:21:01 +02:00
refactor split off application state file
This commit is contained in:
11
src/constants.rs
Normal file
11
src/constants.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
pub const MARGIN_TOP: i32 = 32;
|
||||||
|
pub const MARGIN_BOTTOM: i32 = 32;
|
||||||
|
pub const MARGIN_LEFT: i32 = 16;
|
||||||
|
pub const MARGIN_RIGHT_SCALE_ADDITIONAL: i32 = 38;
|
||||||
|
|
||||||
|
pub const NONE_STRING_OPTION: Option<String> = None;
|
||||||
|
|
||||||
|
pub const TOGGLE_NEIGHBOURS_TEXT_TOGGLED: &str = "Hide Neighbours";
|
||||||
|
pub const TOGGLE_NEIGHBOURS_TEXT: &str = "Show Neighbours";
|
||||||
|
|
||||||
|
pub const SCALE_STEP: f64 = 1.0;
|
||||||
65
src/main.rs
65
src/main.rs
@@ -1,10 +1,16 @@
|
|||||||
|
mod state;
|
||||||
|
mod constants;
|
||||||
|
|
||||||
|
pub use crate::state::AnnotationImage;
|
||||||
|
pub use crate::constants::MARGIN_BOTTOM;
|
||||||
|
|
||||||
|
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::sync::{Arc};
|
use std::sync::{Arc};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use adw::{prelude::*, ApplicationWindow, HeaderBar, SplitButton};
|
use adw::{prelude::*, ApplicationWindow, HeaderBar, SplitButton};
|
||||||
|
use constants::{MARGIN_TOP, MARGIN_LEFT, MARGIN_RIGHT_SCALE_ADDITIONAL, TOGGLE_NEIGHBOURS_TEXT, TOGGLE_NEIGHBOURS_TEXT_TOGGLED, SCALE_STEP};
|
||||||
use gio::SimpleAction;
|
use gio::SimpleAction;
|
||||||
use glib::clone;
|
use glib::clone;
|
||||||
use gtk::{gio, glib, FileChooserAction, FileChooserDialog, ResponseType};
|
use gtk::{gio, glib, FileChooserAction, FileChooserDialog, ResponseType};
|
||||||
@@ -12,60 +18,7 @@ use gtk::{
|
|||||||
ActionBar, Application, AspectFrame, Box, Button, FileFilter, Grid, Image, Orientation,
|
ActionBar, Application, AspectFrame, Box, Button, FileFilter, Grid, Image, Orientation,
|
||||||
PositionType, Scale, Separator, ToggleButton,
|
PositionType, Scale, Separator, ToggleButton,
|
||||||
};
|
};
|
||||||
|
use state::AnnotationZStack;
|
||||||
const MARGIN_TOP: i32 = 32;
|
|
||||||
const MARGIN_BOTTOM: i32 = 32;
|
|
||||||
const MARGIN_LEFT: i32 = 16;
|
|
||||||
const MARGIN_RIGHT_SCALE_ADDITIONAL: i32 = 38;
|
|
||||||
|
|
||||||
const NONE_STRING_OPTION: Option<String> = None;
|
|
||||||
|
|
||||||
const TOGGLE_NEIGHBOURS_TEXT_TOGGLED: &str = "Hide Neighbours";
|
|
||||||
const TOGGLE_NEIGHBOURS_TEXT: &str = "Show Neighbours";
|
|
||||||
|
|
||||||
const SCALE_STEP: f64 = 1.0;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
struct AnnotationZStack {
|
|
||||||
images: Vec<AnnotationImage>,
|
|
||||||
best_index: Option<usize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AnnotationZStack {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
AnnotationZStack {
|
|
||||||
images: Vec::<AnnotationImage>::new(),
|
|
||||||
best_index: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn push(&mut self, image: AnnotationImage) -> &mut Self {
|
|
||||||
self.images.push(image);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
pub fn first(self) -> Option<AnnotationImage> {
|
|
||||||
self.images.first().map(|x| x.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
struct AnnotationImage {
|
|
||||||
image_path: String,
|
|
||||||
neighbours: [Option<String>; 8],
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AnnotationImage {
|
|
||||||
pub fn from_vec(image_path: String, neighbours: Vec<Option<String>>) -> Self {
|
|
||||||
let mut _neighbours = [NONE_STRING_OPTION; 8];
|
|
||||||
for (index, element) in (0..8).zip(neighbours.iter()) {
|
|
||||||
_neighbours[index] = element.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
AnnotationImage {
|
|
||||||
image_path,
|
|
||||||
neighbours: _neighbours,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct ImageUI {
|
struct ImageUI {
|
||||||
|
|||||||
45
src/state/mod.rs
Normal file
45
src/state/mod.rs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
|
use crate::constants::NONE_STRING_OPTION;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct AnnotationZStack {
|
||||||
|
pub images: Vec<AnnotationImage>,
|
||||||
|
pub best_index: Option<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AnnotationZStack {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
AnnotationZStack {
|
||||||
|
images: Vec::<AnnotationImage>::new(),
|
||||||
|
best_index: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn push(&mut self, image: AnnotationImage) -> &mut Self {
|
||||||
|
self.images.push(image);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
pub fn first(self) -> Option<AnnotationImage> {
|
||||||
|
self.images.first().map(|x| x.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct AnnotationImage {
|
||||||
|
pub image_path: String,
|
||||||
|
pub neighbours: [Option<String>; 8],
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AnnotationImage {
|
||||||
|
pub fn from_vec(image_path: String, neighbours: Vec<Option<String>>) -> Self {
|
||||||
|
let mut _neighbours = [NONE_STRING_OPTION; 8];
|
||||||
|
for (index, element) in (0..8).zip(neighbours.iter()) {
|
||||||
|
_neighbours[index] = element.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
AnnotationImage {
|
||||||
|
image_path,
|
||||||
|
neighbours: _neighbours,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user