cleanup: Remove Size::Hardcoded from applet size variants
The most adequate replacement for applets that want to be custom-sized is to use PanelSize::Custom(n). This does lose the granularity between width and height though Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
This commit is contained in:
parent
6fb4a4a43e
commit
516624b20e
1 changed files with 24 additions and 43 deletions
|
|
@ -37,7 +37,7 @@ static TOOLTIP_WINDOW_ID: LazyLock<window::Id> = LazyLock::new(window::Id::uniqu
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
pub size: Size,
|
pub size: PanelSize,
|
||||||
pub anchor: PanelAnchor,
|
pub anchor: PanelAnchor,
|
||||||
pub background: CosmicPanelBackground,
|
pub background: CosmicPanelBackground,
|
||||||
pub output_name: String,
|
pub output_name: String,
|
||||||
|
|
@ -47,12 +47,6 @@ pub struct Context {
|
||||||
pub suggested_bounds: Option<iced::Size>,
|
pub suggested_bounds: Option<iced::Size>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub enum Size {
|
|
||||||
// (width, height)
|
|
||||||
Hardcoded((u16, u16)),
|
|
||||||
PanelSize(PanelSize),
|
|
||||||
}
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum PanelType {
|
pub enum PanelType {
|
||||||
Panel,
|
Panel,
|
||||||
|
|
@ -83,12 +77,10 @@ impl From<String> for PanelType {
|
||||||
impl Default for Context {
|
impl Default for Context {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
size: Size::PanelSize(
|
size: std::env::var("COSMIC_PANEL_SIZE")
|
||||||
std::env::var("COSMIC_PANEL_SIZE")
|
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|size| ron::from_str(size.as_str()).ok())
|
.and_then(|size| ron::from_str(size.as_str()).ok())
|
||||||
.unwrap_or(PanelSize::S),
|
.unwrap_or(PanelSize::S),
|
||||||
),
|
|
||||||
anchor: std::env::var("COSMIC_PANEL_ANCHOR")
|
anchor: std::env::var("COSMIC_PANEL_ANCHOR")
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|size| ron::from_str(size.as_str()).ok())
|
.and_then(|size| ron::from_str(size.as_str()).ok())
|
||||||
|
|
@ -107,14 +99,9 @@ impl Default for Context {
|
||||||
impl Context {
|
impl Context {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn suggested_size(&self, is_symbolic: bool) -> (u16, u16) {
|
pub fn suggested_size(&self, is_symbolic: bool) -> (u16, u16) {
|
||||||
match &self.size {
|
let s = self.size.get_applet_icon_size(is_symbolic) as u16;
|
||||||
Size::PanelSize(size) => {
|
|
||||||
let s = size.get_applet_icon_size(is_symbolic) as u16;
|
|
||||||
(s, s)
|
(s, s)
|
||||||
}
|
}
|
||||||
Size::Hardcoded((width, height)) => (*width, *height),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn suggested_window_size(&self) -> (NonZeroU32, NonZeroU32) {
|
pub fn suggested_window_size(&self) -> (NonZeroU32, NonZeroU32) {
|
||||||
|
|
@ -141,15 +128,12 @@ impl Context {
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn suggested_padding(&self, is_symbolic: bool) -> u16 {
|
pub fn suggested_padding(&self, is_symbolic: bool) -> u16 {
|
||||||
match &self.size {
|
self.size.get_applet_padding(is_symbolic)
|
||||||
Size::PanelSize(size) => size.get_applet_padding(is_symbolic),
|
|
||||||
Size::Hardcoded(_) => 8,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the default window size. Helper for application init with hardcoded size.
|
// Set the default window size. Helper for application init with hardcoded size.
|
||||||
pub fn window_size(&mut self, width: u16, height: u16) {
|
pub fn window_size(&mut self, width: u32) {
|
||||||
self.size = Size::Hardcoded((width, height));
|
self.size = PanelSize::Custom(width);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::cast_precision_loss)]
|
#[allow(clippy::cast_precision_loss)]
|
||||||
|
|
@ -425,16 +409,14 @@ impl Context {
|
||||||
|
|
||||||
pub fn text<'a>(&self, msg: impl Into<Cow<'a, str>>) -> crate::widget::Text<'a, crate::Theme> {
|
pub fn text<'a>(&self, msg: impl Into<Cow<'a, str>>) -> crate::widget::Text<'a, crate::Theme> {
|
||||||
let msg = msg.into();
|
let msg = msg.into();
|
||||||
let t = match self.size {
|
|
||||||
Size::Hardcoded(_) => crate::widget::text,
|
let size = self.size.get_applet_icon_size_with_padding(false);
|
||||||
Size::PanelSize(ref s) => {
|
|
||||||
let size = s.get_applet_icon_size_with_padding(false);
|
|
||||||
|
|
||||||
let size_threshold_small = PanelSize::S.get_applet_icon_size_with_padding(false);
|
let size_threshold_small = PanelSize::S.get_applet_icon_size_with_padding(false);
|
||||||
let size_threshold_medium = PanelSize::M.get_applet_icon_size_with_padding(false);
|
let size_threshold_medium = PanelSize::M.get_applet_icon_size_with_padding(false);
|
||||||
let size_threshold_large = PanelSize::L.get_applet_icon_size_with_padding(false);
|
let size_threshold_large = PanelSize::L.get_applet_icon_size_with_padding(false);
|
||||||
|
|
||||||
if size <= size_threshold_small {
|
let t = if size <= size_threshold_small {
|
||||||
crate::widget::text::body
|
crate::widget::text::body
|
||||||
} else if size <= size_threshold_medium {
|
} else if size <= size_threshold_medium {
|
||||||
crate::widget::text::title4
|
crate::widget::text::title4
|
||||||
|
|
@ -442,9 +424,8 @@ impl Context {
|
||||||
crate::widget::text::title3
|
crate::widget::text::title3
|
||||||
} else {
|
} else {
|
||||||
crate::widget::text::title2
|
crate::widget::text::title2
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
t(msg).font(crate::font::default())
|
t(msg).font(crate::font::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue