More services now require &mut self.

This commit is contained in:
Filipe Rodrigues 2022-11-27 16:59:24 +00:00
parent 0eb94cc19d
commit 606b2ac402
4 changed files with 31 additions and 31 deletions

View File

@ -29,56 +29,56 @@ pub struct PanelsEditor {}
#[allow(clippy::unused_self)] // For accessing resources, we should require the service
impl PanelsEditor {
/// Adds a new panel
pub fn add_panel(&self, resource: &mut PanelsResource, panel: Panel) {
pub fn add_panel(&mut self, resource: &mut PanelsResource, panel: Panel) {
resource.panels.push(PanelState::new(panel));
}
/// Returns all panels
#[must_use]
pub fn panels<'a>(&self, resource: &'a PanelsResource) -> &'a [PanelState] {
pub fn panels<'a>(&mut self, resource: &'a PanelsResource) -> &'a [PanelState] {
&resource.panels
}
/// Returns all panels, mutably
#[must_use]
pub fn panels_mut<'a>(&self, resource: &'a mut PanelsResource) -> &'a mut [PanelState] {
pub fn panels_mut<'a>(&mut self, resource: &'a mut PanelsResource) -> &'a mut [PanelState] {
&mut resource.panels
}
/// Replaces all panels
pub fn replace_panels(&self, resource: &mut PanelsResource, panels: impl IntoIterator<Item = Panel>) {
pub fn replace_panels(&mut self, resource: &mut PanelsResource, panels: impl IntoIterator<Item = Panel>) {
resource.panels = panels.into_iter().map(PanelState::new).collect();
}
/// Returns the max image size
#[must_use]
pub fn max_image_size(&self, resource: &PanelsResource) -> Option<u32> {
pub fn max_image_size(&mut self, resource: &PanelsResource) -> Option<u32> {
resource.max_image_size
}
/// Sets the max image size
pub fn set_max_image_size(&self, resource: &mut PanelsResource, max_image_size: Option<u32>) {
pub fn set_max_image_size(&mut self, resource: &mut PanelsResource, max_image_size: Option<u32>) {
resource.max_image_size = max_image_size;
}
/// Returns the max image size mutably
pub fn max_image_size_mut<'a>(&self, resource: &'a mut PanelsResource) -> Option<&'a mut u32> {
pub fn max_image_size_mut<'a>(&mut self, resource: &'a mut PanelsResource) -> Option<&'a mut u32> {
resource.max_image_size.as_mut()
}
/// Returns the shader
#[must_use]
pub fn shader(&self, resource: &PanelsResource) -> PanelsShader {
pub fn shader(&mut self, resource: &PanelsResource) -> PanelsShader {
resource.shader
}
/// Sets the shader
pub fn set_shader(&self, resource: &mut PanelsResource, shader: PanelsShader) {
pub fn set_shader(&mut self, resource: &mut PanelsResource, shader: PanelsShader) {
resource.shader = shader;
}
/// Returns the shader mutably
pub fn shader_mut<'a>(&self, resource: &'a mut PanelsResource) -> &'a mut PanelsShader {
pub fn shader_mut<'a>(&mut self, resource: &'a mut PanelsResource) -> &'a mut PanelsShader {
&mut resource.shader
}
}

View File

@ -83,26 +83,26 @@ pub struct PlaylistManager {
impl PlaylistManager {
/// Removes an image
pub fn remove_image(&self, image: Arc<PlaylistImage>) {
pub fn remove_image(&mut self, image: Arc<PlaylistImage>) {
// TODO: Care about this?
let _res = self.event_tx.send(Event::RemoveImg(image));
}
/// Sets the root path
pub fn set_root_path(&self, root_path: impl Into<PathBuf>) {
pub fn set_root_path(&mut self, root_path: impl Into<PathBuf>) {
// TODO: Care about this?
let _res = self.event_tx.send(Event::ChangeRoot(root_path.into()));
}
/// Returns the root path
#[must_use]
pub fn root_path(&self) -> Option<PathBuf> {
pub fn root_path(&mut self) -> Option<PathBuf> {
self.inner.read().root_path.clone()
}
/// Returns the remaining images in the current shuffle
#[must_use]
pub fn peek_next(&self) -> Vec<Arc<PlaylistImage>> {
pub fn peek_next(&mut self) -> Vec<Arc<PlaylistImage>> {
self.inner.read().cur_images.clone()
}
}

View File

@ -39,7 +39,7 @@ pub struct ProfilesManager {
impl ProfilesManager {
/// Returns the first profile
#[must_use]
pub fn first_profile(&self) -> Option<(Arc<PathBuf>, Arc<Profile>)> {
pub fn first_profile(&mut self) -> Option<(Arc<PathBuf>, Arc<Profile>)> {
self.inner
.read()
.profiles
@ -49,7 +49,7 @@ impl ProfilesManager {
/// Returns all profiles by their path
#[must_use]
pub fn profiles(&self) -> Vec<(Arc<PathBuf>, Arc<Profile>)> {
pub fn profiles(&mut self) -> Vec<(Arc<PathBuf>, Arc<Profile>)> {
self.inner
.read()
.profiles
@ -59,7 +59,7 @@ impl ProfilesManager {
}
/// Adds a a new profiles
fn create_new(&self, path: PathBuf, profile: Profile) -> Arc<Profile> {
fn create_new(&mut self, path: PathBuf, profile: Profile) -> Arc<Profile> {
let path = Arc::new(path);
let profile = Arc::new(profile);
@ -76,7 +76,7 @@ impl ProfilesManager {
}
/// Loads a profile
pub fn load(&self, path: PathBuf) -> Result<Arc<Profile>, anyhow::Error> {
pub fn load(&mut self, path: PathBuf) -> Result<Arc<Profile>, anyhow::Error> {
// Load the profile
let profile = zsw_util::parse_json_from_file(&path).context("Unable to load profile")?;
@ -85,7 +85,7 @@ impl ProfilesManager {
}
/// Adds and saves a profile
pub fn save(&self, path: PathBuf, profile: Profile) -> Result<Arc<Profile>, anyhow::Error> {
pub fn save(&mut self, path: PathBuf, profile: Profile) -> Result<Arc<Profile>, anyhow::Error> {
// Try to save it
zsw_util::serialize_json_to_file(&path, &profile).context("Unable to save profile")?;

View File

@ -118,9 +118,9 @@ impl<P> SettingsWindow<P> {
&mut self.state,
&mut self.input_receiver,
&mut self.profile_applier,
&self.playlist_manager,
&self.profiles_manager,
&self.panels_editor,
&mut self.playlist_manager,
&mut self.profiles_manager,
&mut self.panels_editor,
&self.window,
ctx,
frame,
@ -144,9 +144,9 @@ impl<P> SettingsWindow<P> {
state: &mut SettingsWindowState,
input_receiver: &mut InputReceiver,
profile_applier: &mut P,
playlist_manager: &PlaylistManager,
profiles_manager: &ProfilesManager,
panels_editor: &PanelsEditor,
playlist_manager: &mut PlaylistManager,
profiles_manager: &mut ProfilesManager,
panels_editor: &mut PanelsEditor,
window: &Window,
ctx: &egui::Context,
_frame: &epi::Frame,
@ -194,9 +194,9 @@ fn draw_settings_window(
surface_size: PhysicalSize<u32>,
panels_resource: &mut PanelsResource,
profile_applier: &mut impl ProfileApplier,
playlist_manager: &PlaylistManager,
profiles_manager: &ProfilesManager,
panels_editor: &PanelsEditor,
playlist_manager: &mut PlaylistManager,
profiles_manager: &mut ProfilesManager,
panels_editor: &mut PanelsEditor,
) {
// Draw the panels header
ui.collapsing("Panels", |ui| {
@ -215,7 +215,7 @@ fn draw_profile(
ui: &mut egui::Ui,
panels_resource: &mut PanelsResource,
profile_applier: &mut impl ProfileApplier,
profiles_manager: &ProfilesManager,
profiles_manager: &mut ProfilesManager,
) {
// Draw all profiles
for (path, profile) in profiles_manager.profiles() {
@ -265,7 +265,7 @@ fn draw_profile(
}
/// Draws the playlist settings
fn draw_playlist(ui: &mut egui::Ui, playlist_manager: &PlaylistManager) {
fn draw_playlist(ui: &mut egui::Ui, playlist_manager: &mut PlaylistManager) {
// Draw the root path
ui.horizontal(|ui| {
// Show the current root path
@ -315,7 +315,7 @@ fn draw_panels(
new_panel_state: &mut NewPanelState,
surface_size: PhysicalSize<u32>,
panels_resource: &mut PanelsResource,
panels_editor: &PanelsEditor,
panels_editor: &mut PanelsEditor,
) {
// TODO: Decide on number to put here?
match panels_editor.max_image_size_mut(panels_resource) {