Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some more refactoring #236

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cosmic-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl Config {
}

// Start a transaction (to set multiple configs at the same time)
pub fn transaction<'a>(&'a self) -> ConfigTransaction<'a> {
pub fn transaction(&self) -> ConfigTransaction<'_> {
ConfigTransaction {
config: self,
updates: Mutex::new(Vec::new()),
Expand Down
3 changes: 1 addition & 2 deletions cosmic-theme/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//!

pub use model::*;
pub use output::*;

mod model;
mod output;
Expand All @@ -20,6 +19,6 @@ pub mod steps;
pub mod util;

/// name of cosmic theme
pub const NAME: &'static str = "com.system76.CosmicTheme";
pub const NAME: &str = "com.system76.CosmicTheme";

pub use palette;
14 changes: 7 additions & 7 deletions cosmic-theme/src/model/derivation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where
let mut divider_c: Srgba = on_bg.clone().into();
divider_c.alpha = 0.2;

let divider = over(divider_c.clone(), bg.clone());
let divider = over(divider_c, bg.clone());
Self {
base: bg,
component,
Expand Down Expand Up @@ -121,15 +121,15 @@ where
/// helper for producing a component from a base color a neutral and an accent
pub fn colored_component(base: C, neutral: C, accent: C, hovered: C, pressed: C) -> Self {
let base: Srgba = base.into();
let mut base_50 = base.clone();
let mut base_50 = base;
base_50.alpha *= 0.5;

let on_20 = neutral.clone();
let mut on_50: Srgba = on_20.clone().into();
on_50.alpha = 0.5;

Component {
base: base.clone().into(),
base: base.into(),
hover: over(hovered.clone(), base).into(),
pressed: over(pressed, base).into(),
selected: over(hovered, base).into(),
Expand Down Expand Up @@ -174,11 +174,11 @@ where
border: C,
) -> Self {
let base = base.into();
let mut base_50 = base.clone();
let mut base_50 = base;
base_50.alpha *= 0.5;

let mut on_20 = on_component.clone().into();
let mut on_50 = on_20.clone();
let mut on_50 = on_20;

on_20.alpha = 0.2;
on_50.alpha = 0.5;
Expand All @@ -188,7 +188,7 @@ where
disabled_border.alpha *= 0.5;

Component {
base: base.clone().into(),
base: base.into(),
hover: if base.alpha < 0.001 {
hovered.clone()
} else {
Expand All @@ -207,7 +207,7 @@ where
selected_text: accent.clone(),
focus: accent.clone(),
divider: if is_high_contrast {
on_50.clone().into()
on_50.into()
} else {
on_20.into()
},
Expand Down
76 changes: 38 additions & 38 deletions cosmic-theme/src/model/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,142 +291,142 @@ impl Theme<Srgba> {
// TODO convenient getter functions for each named color variable
/// get @accent_color
pub fn accent_color(&self) -> Srgba {
self.accent.base.clone()
self.accent.base
}
/// get @success_color
pub fn success_color(&self) -> Srgba {
self.success.base.clone()
self.success.base
}
/// get @destructive_color
pub fn destructive_color(&self) -> Srgba {
self.destructive.base.clone()
self.destructive.base
}
/// get @warning_color
pub fn warning_color(&self) -> Srgba {
self.warning.base.clone()
self.warning.base
}

// Containers
/// get @bg_color
pub fn bg_color(&self) -> Srgba {
self.background.base.clone()
self.background.base
}
/// get @bg_component_color
pub fn bg_component_color(&self) -> Srgba {
self.background.component.base.clone()
self.background.component.base
}
/// get @primary_container_color
pub fn primary_container_color(&self) -> Srgba {
self.primary.base.clone()
self.primary.base
}
/// get @primary_component_color
pub fn primary_component_color(&self) -> Srgba {
self.primary.component.base.clone()
self.primary.component.base
}
/// get @secondary_container_color
pub fn secondary_container_color(&self) -> Srgba {
self.secondary.base.clone()
self.secondary.base
}
/// get @secondary_component_color
pub fn secondary_component_color(&self) -> Srgba {
self.secondary.component.base.clone()
self.secondary.component.base
}
/// get @button_bg_color
pub fn button_bg_color(&self) -> Srgba {
self.button.base.clone()
self.button.base
}

// Text
/// get @on_bg_color
pub fn on_bg_color(&self) -> Srgba {
self.background.on.clone()
self.background.on
}
/// get @on_bg_component_color
pub fn on_bg_component_color(&self) -> Srgba {
self.background.component.on.clone()
self.background.component.on
}
/// get @on_primary_color
pub fn on_primary_container_color(&self) -> Srgba {
self.primary.on.clone()
self.primary.on
}
/// get @on_primary_component_color
pub fn on_primary_component_color(&self) -> Srgba {
self.primary.component.on.clone()
self.primary.component.on
}
/// get @on_secondary_color
pub fn on_secondary_container_color(&self) -> Srgba {
self.secondary.on.clone()
self.secondary.on
}
/// get @on_secondary_component_color
pub fn on_secondary_component_color(&self) -> Srgba {
self.secondary.component.on.clone()
self.secondary.component.on
}
/// get @accent_text_color
pub fn accent_text_color(&self) -> Srgba {
self.accent.base.clone()
self.accent.base
}
/// get @success_text_color
pub fn success_text_color(&self) -> Srgba {
self.success.base.clone()
self.success.base
}
/// get @warning_text_color
pub fn warning_text_color(&self) -> Srgba {
self.warning.base.clone()
self.warning.base
}
/// get @destructive_text_color
pub fn destructive_text_color(&self) -> Srgba {
self.destructive.base.clone()
self.destructive.base
}
/// get @on_accent_color
pub fn on_accent_color(&self) -> Srgba {
self.accent.on.clone()
self.accent.on
}
/// get @on_success_color
pub fn on_success_color(&self) -> Srgba {
self.success.on.clone()
self.success.on
}
/// get @oon_warning_color
pub fn on_warning_color(&self) -> Srgba {
self.warning.on.clone()
self.warning.on
}
/// get @on_destructive_color
pub fn on_destructive_color(&self) -> Srgba {
self.destructive.on.clone()
self.destructive.on
}
/// get @button_color
pub fn button_color(&self) -> Srgba {
self.button.on.clone()
self.button.on
}

// Borders and Dividers
/// get @bg_divider
pub fn bg_divider(&self) -> Srgba {
self.background.divider.clone()
self.background.divider
}
/// get @bg_component_divider
pub fn bg_component_divider(&self) -> Srgba {
self.background.component.divider.clone()
self.background.component.divider
}
/// get @primary_container_divider
pub fn primary_container_divider(&self) -> Srgba {
self.primary.divider.clone()
self.primary.divider
}
/// get @primary_component_divider
pub fn primary_component_divider(&self) -> Srgba {
self.primary.component.divider.clone()
self.primary.component.divider
}
/// get @secondary_container_divider
pub fn secondary_container_divider(&self) -> Srgba {
self.secondary.divider.clone()
self.secondary.divider
}
/// get @button_divider
pub fn button_divider(&self) -> Srgba {
self.button.divider.clone()
self.button.divider
}

/// get @window_header_bg
pub fn window_header_bg(&self) -> Srgba {
self.background.base.clone()
self.background.base
}

/// get @space_none
Expand Down Expand Up @@ -765,7 +765,7 @@ impl ThemeBuilder {
let bg = if let Some(bg_color) = bg_color {
bg_color
} else {
p_ref.gray_1.clone()
p_ref.gray_1
};

let step_array = steps(bg, NonZeroUsize::new(100).unwrap());
Expand All @@ -792,10 +792,10 @@ impl ThemeBuilder {
text_steps_array.as_ref(),
);

let mut component_hovered_overlay = p_ref.neutral_0.clone();
let mut component_hovered_overlay = p_ref.neutral_0;
component_hovered_overlay.alpha = 0.1;

let mut component_pressed_overlay = p_ref.neutral_0.clone();
let mut component_pressed_overlay = p_ref.neutral_0;
component_pressed_overlay.alpha = 0.2;

let bg_component = Component::component(
Expand Down Expand Up @@ -851,7 +851,7 @@ impl ThemeBuilder {

// Standard button background is neutral 7 with 25% opacity
let button_bg = {
let mut color = neutral_7.clone();
let mut color = neutral_7;
color.alpha = 0.25;
color
};
Expand Down Expand Up @@ -955,7 +955,7 @@ impl ThemeBuilder {
p_ref.neutral_8,
);

let mut on_50 = component.on.clone();
let mut on_50 = component.on;
on_50.alpha = 0.5;

component.on_disabled = over(on_50, component.base);
Expand Down
10 changes: 5 additions & 5 deletions examples/application/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub enum Page {
impl Page {
const fn as_str(self) -> &'static str {
match self {
Page::Page1 => "Page 1",
Page::Page2 => "Page 2",
Page::Page3 => "Page 3",
Page::Page4 => "Page 4",
Self::Page1 => "Page 1",
Self::Page2 => "Page 2",
Self::Page3 => "Page 3",
Self::Page4 => "Page 4",
}
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ impl cosmic::Application for App {

nav_model.activate_position(0);

let mut app = App { core, nav_model };
let mut app = Self { core, nav_model };

let command = app.update_title();

Expand Down
4 changes: 2 additions & 2 deletions examples/config/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
use cosmic_config::{Config, ConfigGet, ConfigSet};

fn test_config(config: Config) {
let watcher = config
let _watcher = config
.watch(|config, keys| {
println!("Changed: {:?}", keys);
println!("Changed: {keys:?}");
for key in keys.iter() {
println!(" - {} = {:?}", key, config.get::<ron::Value>(key));
}
Expand Down
19 changes: 9 additions & 10 deletions examples/cosmic/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use cosmic::{
font::load_fonts,
iced::{self, Application, Command, Length, Subscription},
iced::{
subscription,
widget::{self, column, container, horizontal_space, row, text},
window::{self, close, drag, minimize, toggle_maximize},
},
Expand Down Expand Up @@ -136,9 +135,9 @@ impl Page {
}

impl Default for Page {
fn default() -> Page {
fn default() -> Self {
//TODO: what should the default page be?
Page::Desktop(None)
Self::Desktop(None)
}
}

Expand Down Expand Up @@ -215,8 +214,8 @@ pub enum Message {
}

impl From<Page> for Message {
fn from(page: Page) -> Message {
Message::Page(page)
fn from(page: Page) -> Self {
Self::Page(page)
}
}

Expand Down Expand Up @@ -264,7 +263,7 @@ impl Window {

fn set_scale_factor(&mut self, factor: f32) {
self.scale_factor = factor as f64;
self.scale_factor_string = format!("{:.2}", factor);
self.scale_factor_string = format!("{factor:.2}");
}

fn sub_page_button<Message: Clone + From<Page> + 'static>(
Expand Down Expand Up @@ -306,10 +305,10 @@ impl Window {
]).into()
}

fn view_unimplemented_sub_page<'a, Message: Clone + From<Page> + 'static>(
&'a self,
fn view_unimplemented_sub_page<Message: Clone + From<Page> + 'static>(
&self,
sub_page: impl SubPage,
) -> Element<'a, Message> {
) -> Element<'_, Message> {
settings::view_column(vec![
self.parent_page_button(sub_page),
text("We haven't created that panel yet, and/or it is using a similar idea as current Pop! designs.").into(),
Expand All @@ -324,7 +323,7 @@ impl Application for Window {
type Theme = Theme;

fn new(_flags: ()) -> (Self, Command<Self::Message>) {
let mut window = Window::default()
let mut window = Self::default()
.nav_bar_toggled(true)
.show_maximize(true)
.show_minimize(true);
Expand Down
Loading
Loading