refactor: pedantic cargo clippy, do not use Results for always-succeeding functions
This commit is contained in:
@@ -3,7 +3,7 @@ use super::{WidgetObj, WidgetState};
|
||||
pub struct WidgetDiv {}
|
||||
|
||||
impl WidgetDiv {
|
||||
pub fn create() -> anyhow::Result<WidgetState> {
|
||||
pub fn create() -> WidgetState {
|
||||
WidgetState::new(Box::new(Self {}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ pub struct WidgetLabel {
|
||||
}
|
||||
|
||||
impl WidgetLabel {
|
||||
pub fn create(i18n: &mut I18n, params: WidgetLabelParams) -> anyhow::Result<WidgetState> {
|
||||
pub fn create(i18n: &mut I18n, params: WidgetLabelParams) -> WidgetState {
|
||||
let metrics = Metrics::from(¶ms.style);
|
||||
let attrs = Attrs::from(¶ms.style);
|
||||
let wrap = Wrap::from(¶ms.style);
|
||||
@@ -39,7 +39,7 @@ impl WidgetLabel {
|
||||
[(params.content.generate(i18n).as_ref(), attrs)],
|
||||
&Attrs::new(),
|
||||
Shaping::Advanced,
|
||||
params.style.align.map(|a| a.into()),
|
||||
params.style.align.map(Into::into),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ impl WidgetLabel {
|
||||
[(self.params.content.generate(i18n).as_ref(), attrs)],
|
||||
&Attrs::new(),
|
||||
Shaping::Advanced,
|
||||
self.params.style.align.map(|a| a.into()),
|
||||
self.params.style.align.map(Into::into),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ pub struct WidgetData {
|
||||
}
|
||||
|
||||
impl WidgetData {
|
||||
pub fn set_device_pressed(&mut self, device: usize, pressed: bool) -> bool {
|
||||
pub const fn set_device_pressed(&mut self, device: usize, pressed: bool) -> bool {
|
||||
let bit = 1 << device;
|
||||
let state_changed;
|
||||
if pressed {
|
||||
@@ -40,7 +40,7 @@ impl WidgetData {
|
||||
state_changed
|
||||
}
|
||||
|
||||
pub fn set_device_hovered(&mut self, device: usize, hovered: bool) -> bool {
|
||||
pub const fn set_device_hovered(&mut self, device: usize, hovered: bool) -> bool {
|
||||
let bit = 1 << device;
|
||||
let state_changed;
|
||||
if hovered {
|
||||
@@ -53,19 +53,19 @@ impl WidgetData {
|
||||
state_changed
|
||||
}
|
||||
|
||||
pub fn get_pressed(&self, device: usize) -> bool {
|
||||
pub const fn get_pressed(&self, device: usize) -> bool {
|
||||
self.pressed & (1 << device) != 0
|
||||
}
|
||||
|
||||
pub fn get_hovered(&self, device: usize) -> bool {
|
||||
pub const fn get_hovered(&self, device: usize) -> bool {
|
||||
self.hovered & (1 << device) != 0
|
||||
}
|
||||
|
||||
pub fn is_pressed(&self) -> bool {
|
||||
pub const fn is_pressed(&self) -> bool {
|
||||
self.pressed != 0
|
||||
}
|
||||
|
||||
pub fn is_hovered(&self) -> bool {
|
||||
pub const fn is_hovered(&self) -> bool {
|
||||
self.hovered != 0
|
||||
}
|
||||
}
|
||||
@@ -82,8 +82,8 @@ impl WidgetState {
|
||||
(data, obj)
|
||||
}
|
||||
|
||||
fn new(obj: Box<dyn WidgetObj>) -> anyhow::Result<Self> {
|
||||
Ok(Self {
|
||||
fn new(obj: Box<dyn WidgetObj>) -> Self {
|
||||
Self {
|
||||
data: WidgetData {
|
||||
hovered: 0,
|
||||
pressed: 0,
|
||||
@@ -91,7 +91,7 @@ impl WidgetState {
|
||||
transform: glam::Mat4::IDENTITY,
|
||||
},
|
||||
obj,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ pub struct EventParams<'a> {
|
||||
}
|
||||
|
||||
impl EventParams<'_> {
|
||||
pub fn mark_redraw(&mut self) {
|
||||
pub const fn mark_redraw(&mut self) {
|
||||
self.alterables.needs_redraw = true;
|
||||
}
|
||||
}
|
||||
@@ -321,6 +321,8 @@ impl WidgetState {
|
||||
true
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
pub fn process_event<'a, U1, U2>(
|
||||
&mut self,
|
||||
widget_id: WidgetID,
|
||||
|
||||
@@ -22,8 +22,8 @@ pub struct WidgetRectangle {
|
||||
}
|
||||
|
||||
impl WidgetRectangle {
|
||||
pub fn create(params: WidgetRectangleParams) -> anyhow::Result<WidgetState> {
|
||||
WidgetState::new(Box::new(WidgetRectangle { params }))
|
||||
pub fn create(params: WidgetRectangleParams) -> WidgetState {
|
||||
WidgetState::new(Box::new(Self { params }))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ pub struct WidgetSprite {
|
||||
}
|
||||
|
||||
impl WidgetSprite {
|
||||
pub fn create(params: WidgetSpriteParams) -> anyhow::Result<WidgetState> {
|
||||
pub fn create(params: WidgetSpriteParams) -> WidgetState {
|
||||
WidgetState::new(Box::new(Self { params }))
|
||||
}
|
||||
}
|
||||
@@ -44,8 +44,7 @@ impl WidgetObj for WidgetSprite {
|
||||
self
|
||||
.params
|
||||
.color
|
||||
.map(|c| c.into())
|
||||
.unwrap_or(cosmic_text::Color::rgb(255, 255, 255)),
|
||||
.map_or(cosmic_text::Color::rgb(255, 255, 255), Into::into),
|
||||
),
|
||||
snap_to_physical_pixel: true,
|
||||
};
|
||||
@@ -76,7 +75,7 @@ impl WidgetObj for WidgetSprite {
|
||||
payload: drawing::PrimitivePayload::Text(Rc::new(RefCell::new(buffer))),
|
||||
transform: state.transform_stack.get().transform,
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn measure(
|
||||
|
||||
Reference in New Issue
Block a user