libcosmic-yoda/src/app/settings.rs

100 lines
3 KiB
Rust
Raw Normal View History

2023-08-02 11:54:07 +02:00
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
2023-08-15 10:51:59 +02:00
//! Configure a new COSMIC application.
2023-08-02 11:54:07 +02:00
use crate::{font, Theme};
2023-11-30 14:01:42 -05:00
use iced_core::layout::Limits;
2023-08-02 11:54:07 +02:00
use iced_core::Font;
2023-08-15 10:51:59 +02:00
/// Configure a new COSMIC application.
2023-08-02 11:54:07 +02:00
#[allow(clippy::struct_excessive_bools)]
#[must_use]
2023-08-02 11:54:07 +02:00
#[derive(derive_setters::Setters)]
pub struct Settings {
/// Produces a smoother result in some widgets, at a performance cost.
pub(crate) antialiasing: bool,
/// Autosize the window to fit its contents
#[cfg(feature = "wayland")]
pub(crate) autosize: bool,
/// Set the application to not create a main window
#[cfg(feature = "wayland")]
pub(crate) no_main_window: bool,
2023-08-02 11:54:07 +02:00
/// Whether the window should have a border, a title bar, etc. or not.
pub(crate) client_decorations: bool,
/// Enables debug features in cosmic/iced.
pub(crate) debug: bool,
/// The default [`Font`] to be used.
pub(crate) default_font: Font,
/// Name of the icon theme to search by default.
#[setters(skip)]
2023-08-02 11:54:07 +02:00
pub(crate) default_icon_theme: Option<String>,
/// Default size of fonts.
pub(crate) default_text_size: f32,
/// Whether the window should be resizable or not.
/// and the size of the window border which can be dragged for a resize
pub(crate) resizable: Option<f64>,
/// Scale factor to use by default.
pub(crate) scale_factor: f32,
/// Initial size of the window.
2023-12-07 15:27:52 -05:00
pub(crate) size: iced::Size,
2023-08-02 11:54:07 +02:00
/// Limitations of the window size
pub(crate) size_limits: Limits,
/// The theme to apply to the application.
pub(crate) theme: Theme,
/// Whether the window should be transparent.
pub(crate) transparent: bool,
2023-10-09 10:30:10 -04:00
/// Whether the application should exit when there are no open windows
pub(crate) exit_on_close: bool,
2023-08-02 11:54:07 +02:00
}
impl Settings {
/// Sets the default icon theme, passing an empty string will unset the theme.
pub fn default_icon_theme(mut self, value: impl Into<String>) -> Self {
let value: String = value.into();
self.default_icon_theme = if value.is_empty() { None } else { Some(value) };
self
}
}
2023-08-02 11:54:07 +02:00
impl Default for Settings {
fn default() -> Self {
Self {
antialiasing: true,
#[cfg(feature = "wayland")]
autosize: false,
#[cfg(feature = "wayland")]
no_main_window: false,
2023-08-02 11:54:07 +02:00
client_decorations: true,
debug: false,
default_font: font::FONT,
default_icon_theme: None,
2023-08-02 11:54:07 +02:00
default_text_size: 14.0,
resizable: Some(8.0),
scale_factor: std::env::var("COSMIC_SCALE")
.ok()
.and_then(|scale| scale.parse::<f32>().ok())
.unwrap_or(1.0),
2023-12-07 15:27:52 -05:00
size: iced::Size::new(1024.0, 768.0),
2023-08-02 11:54:07 +02:00
size_limits: Limits::NONE.min_height(1.0).min_width(1.0),
theme: crate::theme::system_preference(),
transparent: true,
2023-10-09 10:30:10 -04:00
exit_on_close: true,
2023-08-02 11:54:07 +02:00
}
}
}