Skip to content

Commit

Permalink
Format code (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
AldaronLau authored Feb 17, 2024
1 parent 496b73c commit d21a4f3
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 113 deletions.
44 changes: 34 additions & 10 deletions src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
use std::{collections::BTreeMap, fs, path::PathBuf};

use directories::ProjectDirs;
use serde::{Deserialize, Serialize};
use std::{collections::BTreeMap, fs, path::PathBuf};

/// Application name for project directories
const APPLICATION: &str = "Alloy";

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
#[derive(
Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize,
)]
pub enum WindowMode {
#[default]
Normal,
Maximized,
Fullscreen,
}

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
#[derive(
Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize,
)]
pub enum Theme {
#[default]
Light,
Expand All @@ -29,15 +34,19 @@ impl Theme {
}
}

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
#[derive(
Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize,
)]
pub enum ScalingMode {
#[default]
Fixed,
FitStretch,
FitMin,
}

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
#[derive(
Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize,
)]
pub enum Antialias {
#[default]
Auto,
Expand Down Expand Up @@ -101,7 +110,10 @@ impl Configuration {
}

pub fn scaling(&self) -> ScalingMode {
self.image.as_ref().and_then(|i| i.scaling).unwrap_or_default()
self.image
.as_ref()
.and_then(|i| i.scaling)
.unwrap_or_default()
}

pub fn set_scaling(&mut self, scaling: ScalingMode) {
Expand All @@ -114,7 +126,10 @@ impl Configuration {
}

pub fn antialiasing(&self) -> Antialias {
self.image.as_ref().and_then(|i| i.antialiasing).unwrap_or_default()
self.image
.as_ref()
.and_then(|i| i.antialiasing)
.unwrap_or_default()
}

pub fn set_antialiasing(&mut self, antialias: Antialias) {
Expand All @@ -127,15 +142,24 @@ impl Configuration {
}

pub fn title_folders(&self) -> u32 {
self.window.as_ref().and_then(|w| w.title_folders).unwrap_or_default()
self.window
.as_ref()
.and_then(|w| w.title_folders)
.unwrap_or_default()
}

pub fn window_mode(&self) -> WindowMode {
self.window.as_ref().and_then(|w| w.mode).unwrap_or_default()
self.window
.as_ref()
.and_then(|w| w.mode)
.unwrap_or_default()
}

pub fn theme(&self) -> Theme {
self.window.as_ref().and_then(|w| w.theme).unwrap_or_default()
self.window
.as_ref()
.and_then(|w| w.theme)
.unwrap_or_default()
}

pub fn set_theme(&mut self, theme: Theme) {
Expand Down
17 changes: 11 additions & 6 deletions src/gelatin/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ use glium::{
uniform, Frame, Surface,
};

use crate::add_common_widget_functions;
use crate::gelatin::{
misc::{Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement},
picture::Picture,
window::RenderValidity,
DrawContext, Event, EventKind, NextUpdate, Widget, WidgetData, WidgetError,
use crate::{
add_common_widget_functions,
gelatin::{
misc::{
Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement,
},
picture::Picture,
window::RenderValidity,
DrawContext, Event, EventKind, NextUpdate, Widget, WidgetData,
WidgetError,
},
};

struct ButtonData {
Expand Down
16 changes: 10 additions & 6 deletions src/gelatin/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ use std::{cell::RefCell, rc::Rc};
use cgmath::{Matrix4, Vector3};
use glium::{uniform, Frame, Surface};

use crate::add_common_widget_functions;
use crate::gelatin::{
misc::{Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement},
picture::Picture,
window::RenderValidity,
DrawContext, Event, NextUpdate, Widget, WidgetData, WidgetError,
use crate::{
add_common_widget_functions,
gelatin::{
misc::{
Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement,
},
picture::Picture,
window::RenderValidity,
DrawContext, Event, NextUpdate, Widget, WidgetData, WidgetError,
},
};

struct LabelData {
Expand Down
18 changes: 10 additions & 8 deletions src/gelatin/line_layout_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ use std::{cell::RefCell, rc::Rc};

use glium::Frame;

use crate::add_common_widget_functions;
use crate::gelatin::{
misc::{
Alignment, HorDim, Length, LogicalRect, LogicalVector, PickDimension,
VerDim, WidgetPlacement,
use crate::{
add_common_widget_functions,
gelatin::{
misc::{
Alignment, HorDim, Length, LogicalRect, LogicalVector,
PickDimension, VerDim, WidgetPlacement,
},
widget_data_ptr,
window::{RenderValidity, Window},
DrawContext, Event, NextUpdate, Widget, WidgetData, WidgetError,
},
widget_data_ptr,
window::{RenderValidity, Window},
DrawContext, Event, NextUpdate, Widget, WidgetData, WidgetError,
};

pub type HorizontalLayoutContainer = LineLayoutContainer<HorDim>;
Expand Down
3 changes: 1 addition & 2 deletions src/gelatin/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Idk man
use std::{
any::Any, error::Error, fmt, path::PathBuf, rc::Rc,
time::Instant, vec::Vec,
any::Any, error::Error, fmt, path::PathBuf, rc::Rc, time::Instant, vec::Vec,
};

pub use cgmath;
Expand Down
16 changes: 6 additions & 10 deletions src/gelatin/picture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use std::{
path,
};

use glium::texture::{MipmapsOption, RawImage2d, SrgbTexture2d};
use glium::Display;
use glium::{
texture::{MipmapsOption, RawImage2d, SrgbTexture2d},
Display,
};
use image::{error::ImageError, RgbaImage};

pub struct PictureTextureRef<'a> {
Expand Down Expand Up @@ -109,10 +111,7 @@ impl Picture {
}
}

fn upload_to_texture(
&self,
display: &Display,
) -> Result<(), ImageError> {
fn upload_to_texture(&self, display: &Display) -> Result<(), ImageError> {
let mut borrowed = self.data.borrow_mut();
let mut tmp_picture = PictureData::Path("".into());
std::mem::swap(&mut *borrowed, &mut tmp_picture);
Expand Down Expand Up @@ -142,10 +141,7 @@ impl Picture {
Ok(())
}

fn cpu_to_texture(
img: RgbaImage,
display: &Display,
) -> SrgbTexture2d {
fn cpu_to_texture(img: RgbaImage, display: &Display) -> SrgbTexture2d {
let image_dimensions = img.dimensions();
let image = RawImage2d::from_raw_rgba(img.into_raw(), image_dimensions);
SrgbTexture2d::with_mipmaps(
Expand Down
23 changes: 14 additions & 9 deletions src/gelatin/slider.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
use std::{cell::RefCell, rc::Rc};

use cgmath::{Matrix4, Vector3};
use crate::add_common_widget_functions;
use crate::gelatin::{
misc::{Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement},
window::RenderValidity,
DrawContext, Event, EventKind, NextUpdate, Widget, WidgetData, WidgetError,
};
use glium::{
glutin::event::{ElementState, MouseButton},
DrawParameters,
Blend, BlendingFunction, LinearBlendingFactor,
uniform, Frame, Surface,
uniform, Blend, BlendingFunction, DrawParameters, Frame,
LinearBlendingFactor, Surface,
};

use crate::{
add_common_widget_functions,
gelatin::{
misc::{
Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement,
},
window::RenderValidity,
DrawContext, Event, EventKind, NextUpdate, Widget, WidgetData,
WidgetError,
},
};

struct SliderData {
Expand Down
25 changes: 12 additions & 13 deletions src/gelatin/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@ use std::{

use cgmath::{ortho, Matrix4, Vector3};
use glium::{
index::PrimitiveType,
glutin::{
self,
dpi::{PhysicalPosition, PhysicalSize},
event::WindowEvent,
window::{CursorIcon, Icon, WindowId},
},
program, uniform, Blend, BlendingFunction, Display, DrawParameters, Frame, IndexBuffer,
Program, Rect, Surface, VertexBuffer,
index::PrimitiveType,
program, uniform, Blend, BlendingFunction, Display, DrawParameters, Frame,
IndexBuffer, Program, Rect, Surface, VertexBuffer,
};
use typed_builder::TypedBuilder;

use crate::VerticalLayoutContainer;
use crate::gelatin::{
application::Application,
misc::{FromPhysical, LogicalRect, LogicalVector},
shaders, DrawContext, Event, EventKind, NextUpdate, Vertex, Widget,
use crate::{
gelatin::{
application::Application,
misc::{FromPhysical, LogicalRect, LogicalVector},
shaders, DrawContext, Event, EventKind, NextUpdate, Vertex, Widget,
},
VerticalLayoutContainer,
};

const EVENT_UPDATE_DELTA: std::time::Duration =
Expand Down Expand Up @@ -146,8 +148,7 @@ impl Window {
.with_gl_profile(glutin::GlProfile::Core)
.with_vsync(true);
let display =
Display::new(window, context, &application.event_loop)
.unwrap();
Display::new(window, context, &application.event_loop).unwrap();

if let Some(pos) = desc.position {
display.gl_window().window().set_outer_position(pos);
Expand Down Expand Up @@ -243,9 +244,7 @@ impl Window {
render_validity: RenderValidity {
validity: Rc::new(Cell::new(false)),
},
root_widget: Rc::new(
VerticalLayoutContainer::new(),
),
root_widget: Rc::new(VerticalLayoutContainer::new()),
bg_color: [0.85, 0.85, 0.85, 1.0],

global_event_handlers: Vec::new(),
Expand Down
4 changes: 3 additions & 1 deletion src/image_cache/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ impl Directory {
}

fn set_image_index_from_file_index(&mut self) {
if let Some(Some(img_idx)) = self.file_i_to_img_i.get(self.curr_file_idx) {
if let Some(Some(img_idx)) =
self.file_i_to_img_i.get(self.curr_file_idx)
{
self.curr_image_idx = *img_idx;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/image_cache/image_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use resvg::{

pub mod errors {
use std::io;

use glium::texture;

pub type Result<T = (), E = Error> = std::result::Result<T, E>;
Expand Down
2 changes: 2 additions & 0 deletions src/image_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ use self::{

pub mod errors {
use std::io;

use glium::texture;

use crate::image_cache::image_loader;

pub type Result<T = (), E = Error> = std::result::Result<T, E>;
Expand Down
7 changes: 5 additions & 2 deletions src/input_handling.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::{collections::HashMap, process::Command};
use std::sync::{Arc, Mutex};
use std::{
collections::HashMap,
process::Command,
sync::{Arc, Mutex},
};

use glium::glutin::event::ModifiersState;
use lazy_static::lazy_static;
Expand Down
7 changes: 3 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
configuration::{Configuration, Theme, WindowMode},
gelatin::{
application::*,
glium::glutin::{window::Icon},
glium::glutin::window::Icon,
image,
label::*,
line_layout_container::*,
Expand Down Expand Up @@ -61,9 +61,8 @@ fn main() {
let mut application = Application::new();
let window: Rc<Window> = {
let cfg = &mut config.lock().unwrap();
let window_desc = WindowDescriptor::builder()
.icon(Some(make_icon()))
.build();
let window_desc =
WindowDescriptor::builder().icon(Some(make_icon())).build();
let window = Window::new(&mut application, window_desc);

match cfg.window_mode() {
Expand Down
Loading

0 comments on commit d21a4f3

Please sign in to comment.