From 2f9c529716f758ec5c45fa6adf531c321220f6ed Mon Sep 17 00:00:00 2001 From: Eguo Wang Date: Tue, 27 Feb 2024 09:57:28 +0800 Subject: [PATCH] refactor: Move `src/widgets/*_switcher.*` to `src/widgets/switchers/`, Close #54 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/views/body.rs | 3 ++- src/views/sidebar.rs | 2 ++ src/widgets/mod.rs | 7 +------ .../{ => switchers}/character_switcher.rs | 4 +--- src/widgets/{ => switchers}/context_switcher.rs | 4 +--- src/widgets/switchers/mod.rs | 16 ++++++++++++++++ 8 files changed, 25 insertions(+), 15 deletions(-) rename src/widgets/{ => switchers}/character_switcher.rs (98%) rename src/widgets/{ => switchers}/context_switcher.rs (98%) create mode 100644 src/widgets/switchers/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 4908071..da20a6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -805,7 +805,7 @@ dependencies = [ [[package]] name = "desktop" -version = "0.6.3" +version = "0.6.4" dependencies = [ "amp-client", "amp-common", diff --git a/Cargo.toml b/Cargo.toml index 2252153..16cf127 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "desktop" -version = "0.6.3" +version = "0.6.4" edition = "2021" [[bin]] diff --git a/src/views/body.rs b/src/views/body.rs index 803cba5..f9e15a7 100644 --- a/src/views/body.rs +++ b/src/views/body.rs @@ -25,8 +25,9 @@ use crate::styles::constants::{FONT_SIZE_SMALLER, ICON_FONT_SIZE_TOOLBAR, SPACIN use crate::views::detail::inspect::{self, Information}; use crate::views::detail::logs::{self, Logs}; use crate::views::detail::stats::{self, Stats}; +use crate::widgets::switchers::CharacterSwitcher; use crate::widgets::tabs::Tab; -use crate::widgets::{Button, CharacterSwitcher, Column, Container, Element, Row, Tabs, Text}; +use crate::widgets::{Button, Column, Container, Element, Row, Tabs, Text}; // #[derive(Default)] pub struct Body { diff --git a/src/views/sidebar.rs b/src/views/sidebar.rs index 3248110..a8a7d2b 100644 --- a/src/views/sidebar.rs +++ b/src/views/sidebar.rs @@ -32,6 +32,8 @@ use crate::utils::connection_status::ConnectionStatus; use crate::widgets::lists::PlaybookItem; use crate::widgets::*; +use crate::widgets::switchers::ContextSwitcher; + use super::compose::{self, Compose}; pub struct Sidebar { diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index c757d34..d33eb59 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -14,14 +14,9 @@ pub mod empty; pub mod lists; +pub mod switchers; pub mod tabs; -mod context_switcher; -pub use context_switcher::ContextSwitcher; - -mod character_switcher; -pub use character_switcher::CharacterSwitcher; - use crate::styles::Theme; pub type Element<'a, Message> = iced::Element<'a, Message, Theme>; diff --git a/src/widgets/character_switcher.rs b/src/widgets/switchers/character_switcher.rs similarity index 98% rename from src/widgets/character_switcher.rs rename to src/widgets/switchers/character_switcher.rs index 00ac5a2..a0fed48 100644 --- a/src/widgets/character_switcher.rs +++ b/src/widgets/switchers/character_switcher.rs @@ -11,7 +11,7 @@ use crate::{ styles::{self, constants::ICON_FONT_SIZE_TOOLBAR, Theme}, - widgets::Button, + widgets::{Button, Container, Element, Text}, }; use amp_common::resource::CharacterSpec; use iced::{widget::Component, Length}; @@ -21,8 +21,6 @@ use iced_aw::{ }; use tracing::debug; -use super::{Container, Element, Text}; - #[derive(Default)] pub struct CharacterSwitcher { current: CharacterSpec, diff --git a/src/widgets/context_switcher.rs b/src/widgets/switchers/context_switcher.rs similarity index 98% rename from src/widgets/context_switcher.rs rename to src/widgets/switchers/context_switcher.rs index 12dabb0..df762e1 100644 --- a/src/widgets/context_switcher.rs +++ b/src/widgets/switchers/context_switcher.rs @@ -13,7 +13,7 @@ use std::collections::HashMap; use crate::{ styles::{self, Theme}, - widgets::Button, + widgets::{Button, Column, Container, Element, Row, Text}, }; use amp_common::config::Cluster; use iced::{widget::Component, Alignment, Length}; @@ -25,8 +25,6 @@ use tracing::debug; use crate::utils::connection_status::ConnectionStatus; -use super::{Column, Container, Element, Row, Text}; - #[derive(Default)] pub struct ContextSwitcher { name: String, diff --git a/src/widgets/switchers/mod.rs b/src/widgets/switchers/mod.rs new file mode 100644 index 0000000..6a290fe --- /dev/null +++ b/src/widgets/switchers/mod.rs @@ -0,0 +1,16 @@ +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +mod context_switcher; +pub use context_switcher::ContextSwitcher; + +mod character_switcher; +pub use character_switcher::CharacterSwitcher;