yoda: warning cleanup sweep (dead code + clippy --fix) (squashed)

Squash of 4 yoda commits:
- 84437e21 yoda: libcosmic-yoda dead-code purge (14->0 warnings)
- 999db0a4 yoda: cosmic-theme cleanup (4->0 warnings) — workspace at 0 warnings total
- 4743bb8e yoda: cargo clippy --fix on libcosmic-yoda (115->33 warnings)
- 675f3b59 chore: reduce local stack warnings
This commit is contained in:
Lionel DARNIS 2026-05-25 13:02:38 +02:00
parent 38acba82b4
commit 7a191cf086
36 changed files with 181 additions and 219 deletions

View file

@ -269,5 +269,13 @@ tracing = "0.1"
tokio = "1.52"
zbus = {version = "5.15", default-features = false}
# Speed up snapshot diffing in cosmic-theme tests. Cargo silently ignores
# [profile.*] blocks in non-root manifests, so this lives at the
# workspace root.
[profile.dev.package.insta]
opt-level = 3
[profile.dev.package.similar]
opt-level = 3
[dev-dependencies]
tempfile = "3.27.0"

View file

@ -34,6 +34,3 @@ thiserror.workspace = true
[dev-dependencies]
insta = "1.47.2"
[profile.dev.package]
insta.opt-level = 3
similar.opt-level = 3

View file

@ -955,6 +955,12 @@ impl ThemeBuilder {
}
#[allow(clippy::too_many_lines)]
// The component_hovered/pressed_overlay vars are seeded once near the
// top of this fn and then reassigned inside each container block
// (primary, secondary, …) before being read again. The initial seed
// is therefore overwritten before any read, which is what the
// unused_assignments lint flags below.
#[allow(unused_assignments)]
/// build the theme
pub fn build(self) -> Theme {
let Self {

View file

@ -266,6 +266,14 @@ impl From<Theme> for VsTheme {
}
impl Theme {
/// Write this theme to VS Code's `settings.json` as a
/// `workbench.colorCustomizations` entry, and enable
/// `window.autoDetectColorScheme` so VS Code follows the system theme.
///
/// # Errors
///
/// Returns an `OutputError` if the user config dir is missing, the
/// settings file cannot be read/written, or its JSON is invalid.
#[cold]
pub fn apply_vs_code(self) -> Result<(), OutputError> {
let vs_theme = VsTheme::from(self);
@ -291,6 +299,13 @@ impl Theme {
Ok(())
}
/// Remove the `workbench.colorCustomizations` entry previously written
/// by [`Theme::apply_vs_code`] from VS Code's `settings.json`.
///
/// # Errors
///
/// Returns an `OutputError` if the user config dir is missing, the
/// settings file cannot be read/written, or its JSON is invalid.
#[cold]
pub fn reset_vs_code() -> Result<(), OutputError> {
let mut config_dir = dirs::config_dir().ok_or(OutputError::MissingConfigDir)?;

View file

@ -100,9 +100,10 @@ impl<T: Application> Cosmic<T>
where
T::Message: Send + 'static,
{
pub fn init(
(mut core, flags): (Core, T::Flags),
) -> (Self, iced::Task<crate::Action<T::Message>>) {
pub fn init((core, flags): (Core, T::Flags)) -> (Self, iced::Task<crate::Action<T::Message>>) {
#[cfg(all(feature = "dbus-config", target_os = "linux"))]
let mut core = core;
#[cfg(all(feature = "dbus-config", target_os = "linux"))]
{
use iced_futures::futures::executor::block_on;
@ -364,7 +365,6 @@ where
crate::surface::Action::Task(f) => {
f().map(|sm| crate::Action::Cosmic(Action::Surface(sm)))
}
_ => iced::Task::none(),
}
#[cfg(not(feature = "surface-message"))]
@ -480,12 +480,11 @@ where
.into_iter()
.filter(cosmic_config::Error::is_err)
{
if let cosmic_config::Error::GetKey(_, err) = &why {
if err.kind() == std::io::ErrorKind::NotFound {
if let cosmic_config::Error::GetKey(_, err) = &why
&& err.kind() == std::io::ErrorKind::NotFound {
// No system default config installed; don't error
continue;
}
}
tracing::error!(?why, "cosmic toolkit config update error");
}
@ -627,9 +626,9 @@ impl<T: Application> Cosmic<T> {
.app
.core()
.main_window_id()
.is_some_and(|main_id| main_id == id)
.is_some_and(|main_id| main_id == _id)
{
self.app.core_mut().window.sharp_corners = maximized;
self.app.core_mut().window.sharp_corners = _maximized;
}
}

View file

@ -284,7 +284,7 @@ where
// app = app.window(window_settings);
core.main_window = Some(iced_core::window::Id::RESERVED);
}
let mut app = iced::daemon(
let app = iced::daemon(
BootData(Rc::new(RefCell::new(Some(BootDataInner::<App> {
flags,
core,

View file

@ -1,14 +1,13 @@
//! Distribute content horizontally.
use crate::iced;
use iced::core::alignment::{self, Alignment};
use iced::core::event::{self, Event};
use iced::core::event::Event;
use iced::core::layout::{self, Layout};
use iced::core::widget::{Operation, Tree};
use iced::core::{
Clipboard, Element, Length, Padding, Pixels, Rectangle, Shell, Size, Vector, Widget, mouse,
overlay, renderer, widget,
};
use iced::touch;
/// A container that distributes its contents horizontally.
///

View file

@ -23,12 +23,11 @@ pub static COSMIC_TK: LazyLock<RwLock<CosmicTk>> = LazyLock::new(|| {
.map(|c| {
CosmicTk::get_entry(&c).unwrap_or_else(|(errors, mode)| {
for why in errors.into_iter().filter(cosmic_config::Error::is_err) {
if let cosmic_config::Error::GetKey(_, err) = &why {
if err.kind() == std::io::ErrorKind::NotFound {
if let cosmic_config::Error::GetKey(_, err) = &why
&& err.kind() == std::io::ErrorKind::NotFound {
// No system default config installed; don't error
continue;
}
}
tracing::error!(?why, "CosmicTk config entry error");
}
mode

View file

@ -78,8 +78,6 @@ pub struct Core {
pub(super) portal_accent: Option<Srgba>,
pub(super) portal_is_high_contrast: Option<bool>,
pub(super) title: HashMap<Id, String>,
pub window: Window,
@ -155,7 +153,6 @@ impl Default for Core {
settings_daemon: None,
portal_is_dark: None,
portal_accent: None,
portal_is_high_contrast: None,
main_window: None,
exit_on_main_window_closed: true,
menu_bars: HashMap::new(),

View file

@ -43,7 +43,7 @@ pub fn subscription<App: ApplicationExt>() -> Subscription<crate::Action<App::Me
std::process::exit(1);
}
output
let _ = output
.send(crate::Action::Cosmic(crate::app::Action::DbusConnection(
conn.clone(),
)))

View file

@ -769,7 +769,7 @@ impl DesktopEntryData {
pub async fn spawn_desktop_exec<S, I, K, V>(
exec: S,
env_vars: I,
app_id: Option<&str>,
_app_id: Option<&str>,
terminal: bool,
) where
S: AsRef<str>,
@ -816,13 +816,17 @@ pub async fn spawn_desktop_exec<S, I, K, V>(
// https://systemd.io/DESKTOP_ENVIRONMENTS
//
// Similar to what Gnome sets, for now.
if let Some(pid) = crate::process::spawn(cmd).await {
if let Some(_pid) = crate::process::spawn(cmd).await {
#[cfg(feature = "desktop-systemd-scope")]
if let Ok(session) = zbus::Connection::session().await {
if let Ok(systemd_manager) = SystemdMangerProxy::new(&session).await {
let _ = systemd_manager
.start_transient_unit(
&format!("app-cosmic-{}-{}.scope", app_id.unwrap_or(&executable), pid),
&format!(
"app-cosmic-{}-{}.scope",
_app_id.unwrap_or(&executable),
_pid
),
"fail",
&[
(
@ -833,7 +837,7 @@ pub async fn spawn_desktop_exec<S, I, K, V>(
),
(
"PIDs".to_string(),
zbus::zvariant::Value::from(vec![pid])
zbus::zvariant::Value::from(vec![_pid])
.try_to_owned()
.unwrap(),
),

View file

@ -63,6 +63,17 @@ pub mod font;
#[doc(inline)]
pub use iced;
#[doc(inline)]
pub use iced_core;
#[doc(inline)]
pub use iced_futures;
#[doc(inline)]
pub use iced_runtime;
#[doc(inline)]
pub use iced_widget;
#[doc(inline)]
#[cfg(feature = "wayland")]
pub use iced_winit;
pub mod icon_theme;
pub mod keyboard_nav;

View file

@ -170,18 +170,15 @@ impl Button {
* TODO: Checkbox
*/
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Default)]
pub enum Checkbox {
#[default]
Primary,
Secondary,
Success,
Danger,
}
impl Default for Checkbox {
fn default() -> Self {
Self::Primary
}
}
impl iced_checkbox::Catalog for Theme {
type Class<'a> = Checkbox;
@ -1192,7 +1189,7 @@ impl scrollable::Catalog for Theme {
background: Color::TRANSPARENT.into(),
border: Border::default(),
shadow: Shadow::default(),
icon: Color::TRANSPARENT.into(),
icon: Color::TRANSPARENT,
},
};
let small_widget_container = self.current_container().small_widget.with_alpha(0.7);
@ -1260,7 +1257,7 @@ impl scrollable::Catalog for Theme {
background: Color::TRANSPARENT.into(),
border: Border::default(),
shadow: Shadow::default(),
icon: Color::TRANSPARENT.into(),
icon: Color::TRANSPARENT,
},
};

View file

@ -156,7 +156,7 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
);
}
let mut button = if builder.variant.vertical {
let button = if builder.variant.vertical {
crate::widget::column::with_children(content)
.padding(builder.padding)
.spacing(builder.spacing)
@ -173,9 +173,11 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
};
#[cfg(feature = "a11y")]
{
let button = {
let mut button = button;
button = button.name(builder.name).description(builder.description);
}
button
};
let button = button
.padding(0)

View file

@ -84,7 +84,7 @@ where
.width(builder.width)
.height(builder.height);
let mut button = super::custom_image_button(content, builder.variant.on_remove)
let button = super::custom_image_button(content, builder.variant.on_remove)
.padding(0)
.selected(builder.variant.selected)
.id(builder.id)
@ -92,9 +92,11 @@ where
.class(builder.class);
#[cfg(feature = "a11y")]
{
let button = {
let mut button = button;
button = button.name(builder.name).description(builder.description);
}
button
};
button.into()
}

View file

@ -67,7 +67,7 @@ pub fn icon() -> Handle {
impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Message> {
fn from(mut builder: Button<'a, Message>) -> Element<'a, Message> {
let mut button: super::Button<'a, Message> = row::with_capacity(2)
let button: super::Button<'a, Message> = row::with_capacity(2)
.push({
// TODO: Avoid allocation
crate::widget::text(builder.label.to_string())
@ -95,13 +95,15 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
.class(builder.class);
#[cfg(feature = "a11y")]
{
let button = {
let mut button = button;
if !builder.label.is_empty() {
button = button.name(builder.label);
}
button = button.description(builder.description);
}
button
};
if builder.tooltip.is_empty() {
button.into()

View file

@ -122,7 +122,7 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
.into()
});
let mut button: super::Button<'a, Message> = row::with_capacity(3)
let button: super::Button<'a, Message> = row::with_capacity(3)
// Optional icon to place before label.
.push_maybe(leading_icon)
// Optional label between icons.
@ -141,13 +141,15 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
.class(builder.class);
#[cfg(feature = "a11y")]
{
let button = {
let mut button = button;
if !builder.label.is_empty() {
button = button.name(builder.label)
}
button = button.description(builder.description);
}
button
};
if builder.tooltip.is_empty() {
button.into()

View file

@ -378,13 +378,12 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
match event {
Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left))
| Event::Touch(touch::Event::FingerPressed { .. }) => {
if let Some(position) = cursor.position() {
if removal_bounds(layout.bounds(), 4.0).contains(position) {
if let Some(position) = cursor.position()
&& removal_bounds(layout.bounds(), 4.0).contains(position) {
shell.publish(on_remove.clone());
shell.capture_event();
return;
}
}
}
_ => (),
@ -557,9 +556,9 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
}
}
if on_remove.is_some() {
if let Some(position) = cursor.position() {
if bounds.contains(position) {
if on_remove.is_some()
&& let Some(position) = cursor.position()
&& bounds.contains(position) {
let bounds = removal_bounds(layout.bounds(), 4.0);
renderer.fill_quad(
renderer::Quad {
@ -591,8 +590,6 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
},
);
}
}
}
});
}
}
@ -743,12 +740,6 @@ impl State {
self.is_focused
}
/// Returns whether the [`Button`] is currently hovered or not.
#[inline]
pub fn is_hovered(self) -> bool {
self.is_hovered
}
/// Focuses the [`Button`].
#[inline]
pub fn focus(&mut self) {
@ -794,7 +785,6 @@ pub fn update<'a, Message: Clone>(
}
shell.capture_event();
return;
}
}
}
@ -814,7 +804,6 @@ pub fn update<'a, Message: Clone>(
}
shell.capture_event();
return;
}
} else if on_press_down.is_some() {
let state = state();
@ -834,7 +823,6 @@ pub fn update<'a, Message: Clone>(
shell.publish(msg);
}
shell.capture_event();
return;
}
Event::Keyboard(keyboard::Event::KeyPressed { key, .. }) => {
if let Some(on_press) = on_press {
@ -845,7 +833,6 @@ pub fn update<'a, Message: Clone>(
shell.publish(msg);
shell.capture_event();
return;
}
}
}

View file

@ -527,7 +527,7 @@ where
let c_layout = layout.next().unwrap();
let state = clear_all_state.unwrap();
self.clear_all_button.as_widget_mut().update(
state, &event, c_layout, cursor, renderer, clipboard, shell, viewport,
state, event, c_layout, cursor, renderer, clipboard, shell, viewport,
);
}
@ -537,7 +537,7 @@ where
for ((inner, layout), c_state) in self.elements.iter_mut().zip(layout).zip(tree_children) {
inner.as_widget_mut().update(
c_state, &event, layout, cursor, renderer, clipboard, shell, viewport,
c_state, event, layout, cursor, renderer, clipboard, shell, viewport,
);
if shell.is_event_captured() || fully_unexpanded {
break;

View file

@ -745,7 +745,7 @@ where
let column_tree = &mut tree.children[0];
self.inner.as_widget_mut().update(
column_tree,
&event,
event,
column_layout,
cursor,
renderer,
@ -758,22 +758,19 @@ where
return;
}
match event {
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
let bounds = column_layout.children().nth(1).unwrap().bounds();
if let Some(point) = cursor.position_over(bounds) {
let relative_pos = point - bounds.position();
let (s, v) = (
relative_pos.x / bounds.width,
1.0 - relative_pos.y / bounds.height,
);
state.dragging = true;
let hsv: palette::Hsv = palette::Hsv::new(self.active_color.hue, s, v);
shell.publish((self.on_update)(ColorPickerUpdate::ActiveColor(hsv)));
shell.capture_event();
}
if let Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) = event {
let bounds = column_layout.children().nth(1).unwrap().bounds();
if let Some(point) = cursor.position_over(bounds) {
let relative_pos = point - bounds.position();
let (s, v) = (
relative_pos.x / bounds.width,
1.0 - relative_pos.y / bounds.height,
);
state.dragging = true;
let hsv: palette::Hsv = palette::Hsv::new(self.active_color.hue, s, v);
shell.publish((self.on_update)(ColorPickerUpdate::ActiveColor(hsv)));
shell.capture_event();
}
_ => {}
}
}

View file

@ -357,7 +357,7 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
x, y, mime_types, ..
},
)) if *id == Some(my_id) => {
if !self.mime_matches(&mime_types) {
if !self.mime_matches(mime_types) {
log::trace!(
target: DND_DEST_LOG_TARGET,
"offer enter id={my_id:?} ignored (mimes={mime_types:?} not in {:?})",
@ -396,7 +396,6 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
);
}
shell.capture_event();
return;
}
Event::Dnd(DndEvent::Offer(_, OfferEvent::Leave)) => {
log::trace!(
@ -424,7 +423,6 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
viewport,
);
}
return;
}
Event::Dnd(DndEvent::Offer(id, OfferEvent::Motion { x, y })) if *id == Some(my_id) => {
log::trace!(
@ -459,7 +457,6 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
);
}
shell.capture_event();
return;
}
Event::Dnd(DndEvent::Offer(_, OfferEvent::LeaveDestination)) => {
log::trace!(
@ -472,7 +469,6 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
{
shell.publish(msg);
}
return;
}
Event::Dnd(DndEvent::Offer(id, OfferEvent::Drop)) if *id == Some(my_id) => {
log::trace!(
@ -485,7 +481,6 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
shell.publish(msg);
}
shell.capture_event();
return;
}
Event::Dnd(DndEvent::Offer(id, OfferEvent::SelectedAction(action)))
if *id == Some(my_id) =>
@ -503,7 +498,6 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
shell.publish(msg);
}
shell.capture_event();
return;
}
Event::Dnd(DndEvent::Offer(id, OfferEvent::Data { data, mime_type }))
if *id == Some(my_id) =>
@ -543,7 +537,6 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
return;
}
shell.capture_event();
return;
}
_ => {}
}

View file

@ -474,16 +474,14 @@ where
match event {
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
let hovered_guard = self.hovered_option.lock().unwrap();
if cursor.is_over(layout.bounds()) {
if let Some(index) = *hovered_guard {
if cursor.is_over(layout.bounds())
&& let Some(index) = *hovered_guard {
shell.publish((self.on_selected)(index));
if let Some(close_on_selected) = self.close_on_selected.as_ref() {
shell.publish(close_on_selected.clone());
}
shell.capture_event();
return;
}
}
}
Event::Mouse(mouse::Event::CursorMoved { .. }) => {
if let Some(cursor_position) = cursor.position_in(layout.bounds()) {
@ -498,11 +496,10 @@ where
let new_hovered_option = (cursor_position.y / option_height) as usize;
let mut hovered_guard = self.hovered_option.lock().unwrap();
if let Some(on_option_hovered) = self.on_option_hovered {
if *hovered_guard != Some(new_hovered_option) {
if let Some(on_option_hovered) = self.on_option_hovered
&& *hovered_guard != Some(new_hovered_option) {
shell.publish(on_option_hovered(new_hovered_option));
}
}
*hovered_guard = Some(new_hovered_option);
}
@ -526,7 +523,6 @@ where
shell.publish(close_on_selected.clone());
}
shell.capture_event();
return;
}
}
}

View file

@ -343,13 +343,11 @@ where
match event {
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
if cursor.is_over(bounds) {
if let Some(item) = self.hovered_option.as_ref() {
if cursor.is_over(bounds)
&& let Some(item) = self.hovered_option.as_ref() {
shell.publish((self.on_selected)(item.clone()));
shell.capture_event();
return;
}
}
}
Event::Mouse(mouse::Event::CursorMoved { .. }) => {
if let Some(cursor_position) = cursor.position_in(bounds) {

View file

@ -6,7 +6,7 @@ use super::menu::{self, Menu};
use crate::widget::icon;
use derive_setters::Setters;
use iced_core::event::Event;
use iced_core::text::{self, Paragraph, Text};
use iced_core::text::{self, Text};
use iced_core::widget::tree::{self, Tree};
use iced_core::{
Clipboard, Layout, Length, Padding, Pixels, Rectangle, Shadow, Shell, Size, Vector, Widget,
@ -127,7 +127,7 @@ impl<'a, S: AsRef<str>, Message: 'a, Item: Clone + PartialEq + 'static>
_viewport: &Rectangle,
) {
update(
&event,
event,
layout,
cursor,
shell,

View file

@ -263,7 +263,7 @@ where
_viewport: &Rectangle,
) {
update::<S, Message, AppMessage>(
&event,
event,
layout,
cursor,
shell,

View file

@ -48,6 +48,7 @@ impl Axis {
/// padding and alignment to the items as needed.
///
/// It returns a new layout [`Node`].
#[allow(dead_code)] // kept as public helper; not currently called by libcosmic
pub fn resolve<'a, E, Message, Renderer>(
axis: &Axis,
renderer: &Renderer,
@ -246,7 +247,7 @@ pub fn resolve_wrapper<'a, Message>(
if align_items == Alignment::Center {
let mut fill_cross = axis.cross(limits.min());
for (child, tree) in items.into_iter().zip(tree.iter_mut()) {
for (child, tree) in items.iter_mut().zip(tree.iter_mut()) {
let c_size = child.size();
let cross_fill_factor = match axis {
Axis::Horizontal => c_size.height,
@ -269,7 +270,7 @@ pub fn resolve_wrapper<'a, Message>(
cross = fill_cross;
}
for (i, (child, tree)) in items.into_iter().zip(tree.iter_mut()).enumerate() {
for (i, (child, tree)) in items.iter_mut().zip(tree.iter_mut()).enumerate() {
let c_size = child.size();
let fill_factor = match axis {
Axis::Horizontal => c_size.width,
@ -312,7 +313,7 @@ pub fn resolve_wrapper<'a, Message>(
let remaining = available.max(0.0);
for (i, (child, tree)) in items.into_iter().zip(tree.iter_mut()).enumerate() {
for (i, (child, tree)) in items.iter_mut().zip(tree.iter_mut()).enumerate() {
let c_size = child.size();
let fill_factor = match axis {
Axis::Horizontal => c_size.width,

View file

@ -50,7 +50,6 @@ pub(crate) struct MenuBarStateInner {
pub(crate) tree: Tree,
pub(crate) popup_id: HashMap<window::Id, window::Id>,
pub(crate) pressed: bool,
pub(crate) bar_pressed: bool,
pub(crate) view_cursor: Cursor,
pub(crate) open: bool,
pub(crate) active_root: Vec<usize>,
@ -87,7 +86,6 @@ impl Default for MenuBarStateInner {
vertical_direction: Direction::Positive,
menu_states: Vec::new(),
popup_id: HashMap::new(),
bar_pressed: false,
}
}
}
@ -164,14 +162,6 @@ where
}
}
pub fn get_mut_or_default<T: Default>(vec: &mut Vec<T>, index: usize) -> &mut T {
if index < vec.len() {
&mut vec[index]
} else {
vec.resize_with(index + 1, T::default);
&mut vec[index]
}
}
/// A `MenuBar` collects `MenuTree`s and handles all the layout, event processing, and drawing.
#[allow(missing_debug_implementations)]
@ -605,14 +595,12 @@ where
.with_data(|d| !d.open && !d.active_root.is_empty());
let open = my_state.inner.with_data_mut(|state| {
if reset {
if let Some(popup_id) = state.popup_id.get(&self.window_id).copied() {
if let Some(handler) = self.on_surface_action.as_ref() {
if reset
&& let Some(popup_id) = state.popup_id.get(&self.window_id).copied()
&& let Some(handler) = self.on_surface_action.as_ref() {
shell.publish((handler)(crate::surface::Action::DestroyPopup(popup_id)));
state.reset();
}
}
}
state.open
});

View file

@ -1522,14 +1522,13 @@ where
.is_some_and(|i| *i != new_index && !active_menu[*i].children.is_empty());
#[cfg(all(feature = "multi-window", feature = "wayland", target_os = "linux", feature = "surface-message"))]
if matches!(WINDOWING_SYSTEM.get(), Some(WindowingSystem::Wayland)) && remove {
if let Some(id) = state.popup_id.remove(&menu.window_id) {
if matches!(WINDOWING_SYSTEM.get(), Some(WindowingSystem::Wayland)) && remove
&& let Some(id) = state.popup_id.remove(&menu.window_id) {
state.active_root.truncate(menu.depth + 1);
shell.publish((menu.on_surface_action.as_ref().unwrap())({
crate::surface::action::destroy_popup(id)
}));
}
}
let item = &active_menu[new_index];
// set new index
let old_index = last_menu_state.index.replace(new_index);

View file

@ -160,8 +160,8 @@ where
shell.capture_event();
return;
}
} else if let Some(on_close) = self.on_close.as_ref() {
if matches!(
} else if let Some(on_close) = self.on_close.as_ref()
&& matches!(
event,
Event::Mouse(mouse::Event::ButtonPressed(_))
| Event::Touch(touch::Event::FingerPressed { .. })
@ -169,7 +169,6 @@ where
{
shell.publish(on_close.clone());
}
}
}
// Hide cursor from background content when modal popup is active
@ -472,12 +471,6 @@ where
}
}
/// The local state of a [`Popover`].
#[derive(Debug, Default)]
struct State {
is_open: bool,
}
/// The first child in [`Popover::children`] is always the wrapped content.
fn content_tree(tree: &Tree) -> &Tree {
&tree.children[0]

View file

@ -262,7 +262,6 @@ where
if cursor.is_over(layout.bounds()) {
shell.publish(self.on_click.clone());
shell.capture_event();
return;
}
}
_ => {}

View file

@ -694,11 +694,10 @@ where
if let Some(icon) = self.model.icon(key) {
non_text_width += f32::from(icon.size) + f32::from(self.button_spacing);
} else if self.model.is_active(key) {
if let crate::theme::SegmentedButton::Control = self.style {
} else if self.model.is_active(key)
&& let crate::theme::SegmentedButton::Control = self.style {
non_text_width += 16.0 + f32::from(self.button_spacing);
}
}
if self.model.is_closable(key) {
non_text_width +=
@ -1085,11 +1084,10 @@ where
{
state.drop_hint = None;
self.emit_drop_hint(shell, state.drop_hint);
if let Some(Some(entity)) = entity {
if let Some(on_dnd_leave) = self.on_dnd_leave.as_ref() {
if let Some(Some(entity)) = entity
&& let Some(on_dnd_leave) = self.on_dnd_leave.as_ref() {
shell.publish(on_dnd_leave(entity));
}
}
log::trace!(
target: TAB_REORDER_LOG_TARGET,
"offer leave id={my_id:?} entity={entity:?}"
@ -1165,11 +1163,10 @@ where
None::<fn(_, _, _) -> Message>,
None,
);
if let Some(on_dnd_leave) = self.on_dnd_leave.as_ref() {
if let Some(Some(entity)) = entity {
if let Some(on_dnd_leave) = self.on_dnd_leave.as_ref()
&& let Some(Some(entity)) = entity {
shell.publish(on_dnd_leave(entity));
}
}
}
}
DndEvent::Offer(id, OfferEvent::Drop) if Some(my_id) == *id => {
@ -1342,8 +1339,8 @@ where
// Emit close message if the close button is pressed.
if let Some(on_close) = self.on_close.as_ref() {
if over_close_button
&& (left_button_released(&event)
|| (touch_lifted(&event) && fingers_pressed == 1))
&& (left_button_released(event)
|| (touch_lifted(event) && fingers_pressed == 1))
{
shell.publish(on_close(key));
shell.capture_event();
@ -1397,14 +1394,14 @@ where
}
}
if is_lifted(&event) {
if is_lifted(event) {
state.unfocus();
}
if let Some(on_activate) = self.on_activate.as_ref() {
if is_pressed(event) {
state.pressed_item = Some(Item::Tab(key));
} else if is_lifted(&event) && self.button_is_pressed(state, key) {
} else if is_lifted(event) && self.button_is_pressed(state, key) {
shell.publish(on_activate(key));
state.set_focused();
state.focused_item = Item::Tab(key);
@ -1444,8 +1441,8 @@ where
// Present a context menu on a right click event.
if self.context_menu.is_some()
&& let Some(on_context) = self.on_context.as_ref()
&& (right_button_released(&event)
|| (touch_lifted(&event) && fingers_pressed == 2))
&& (right_button_released(event)
|| (touch_lifted(event) && fingers_pressed == 2))
{
state.show_context = Some(key);
state.context_cursor = cursor_position.position().unwrap_or_default();
@ -1543,12 +1540,12 @@ where
}
if state.is_focused() {
// Unfocus on clicks outside of the boundaries of the segmented button.
if is_pressed(&event) {
if is_pressed(event) {
state.unfocus();
state.pressed_item = None;
return;
}
} else if is_lifted(&event) {
} else if is_lifted(event) {
state.pressed_item = None;
}
}
@ -2167,8 +2164,8 @@ where
);
}
if show_drop_hint_marker {
if matches!(
if show_drop_hint_marker
&& matches!(
drop_hint_marker,
Some(DropHint {
entity,
@ -2183,7 +2180,6 @@ where
appearance.active.text_color,
);
}
}
nth += 1;
});
@ -2368,7 +2364,7 @@ where
}
}
struct TabDragSource<Message> {
pub(super) struct TabDragSource<Message> {
mime: String,
threshold: f32,
_marker: PhantomData<Message>,
@ -2419,7 +2415,6 @@ struct TabDragCandidate {
#[derive(Debug, Clone, Copy)]
struct Focus {
updated_at: Instant,
now: Instant,
}
/// State that is maintained by each individual widget.
@ -2492,7 +2487,6 @@ impl LocalState {
self.focused = Some(Focus {
updated_at: now,
now,
});
}
}

View file

@ -23,7 +23,7 @@ pub fn spin_button<'a, T, M>(
where
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
{
let mut button = SpinButton::new(
let button = SpinButton::new(
label,
value,
step,
@ -34,9 +34,11 @@ where
);
#[cfg(feature = "a11y")]
{
let button = {
let mut button = button;
button = button.name(name.into());
}
button
};
button
}
@ -54,20 +56,22 @@ pub fn vertical<'a, T, M>(
where
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
{
let mut button = SpinButton::new(
let button = SpinButton::new(
label,
value,
step,
min,
max,
Orientation::Horizontal,
Orientation::Vertical,
on_press,
);
#[cfg(feature = "a11y")]
{
let button = {
let mut button = button;
button = button.name(name.into());
}
button
};
button
}

View file

@ -84,15 +84,14 @@ where
let mut sort_state = 0;
if let Some(sort) = val.model.sort {
if sort.0 == category {
if let Some(sort) = val.model.sort
&& sort.0 == category {
if sort.1 {
sort_state = 1;
} else {
sort_state = 2;
}
}
};
};
// Build the category header
widget::row::with_capacity(2)

View file

@ -666,18 +666,15 @@ where
let old_value = Value::new(&old_value);
if state.is_focused()
&& let cursor::State::Index(index) = state.cursor.state(&old_value)
{
if index == old_value.len() {
&& index == old_value.len() {
state.cursor.move_to(self.value.len());
}
}
if let Some(f) = state.is_focused.as_ref().filter(|f| f.focused) {
if f.updated_at != LAST_FOCUS_UPDATE.with(|f| f.get()) {
if let Some(f) = state.is_focused.as_ref().filter(|f| f.focused)
&& f.updated_at != LAST_FOCUS_UPDATE.with(|f| f.get()) {
state.unfocus();
state.emit_unfocus = true;
}
}
if self.is_editable_variant {
if !state.is_focused() {
@ -891,8 +888,8 @@ where
let line_height = self.line_height;
// Disables editing of the editable variant when clicking outside of, or for tab focus changes.
if self.is_editable_variant {
if let Some(ref on_edit) = self.on_toggle_edit {
if self.is_editable_variant
&& let Some(ref on_edit) = self.on_toggle_edit {
let state = tree.state.downcast_mut::<State>();
if !state.is_read_only && state.is_focused.is_some_and(|f| !f.focused) {
state.is_read_only = true;
@ -904,7 +901,6 @@ where
shell.publish((on_edit)(f.focused));
}
}
}
// Calculates the layout of the trailing icon button element.
if !tree.children.is_empty() {
@ -915,9 +911,9 @@ where
trailing_icon_layout = Some(text_layout.children().last().unwrap());
// Enable custom buttons defined on the trailing icon position to be handled.
if !self.is_editable_variant {
if let Some(trailing_layout) = trailing_icon_layout {
let _res = trailing_icon.as_widget_mut().update(
if !self.is_editable_variant
&& let Some(trailing_layout) = trailing_icon_layout {
trailing_icon.as_widget_mut().update(
tree,
event,
trailing_layout,
@ -932,18 +928,16 @@ where
return;
}
}
}
}
}
let state = tree.state.downcast_mut::<State>();
if let Some(on_unfocus) = self.on_unfocus.as_ref() {
if state.emit_unfocus {
if let Some(on_unfocus) = self.on_unfocus.as_ref()
&& state.emit_unfocus {
state.emit_unfocus = false;
shell.publish(on_unfocus.clone());
}
}
let dnd_id = self.dnd_id();
let id = Widget::id(self);
@ -1652,11 +1646,10 @@ pub fn update<'a, Message: Clone + 'static>(
if matches!(state.dragging_state, None | Some(DraggingState::Selection))
&& (!state.is_focused() || (is_editable_variant && state.is_read_only))
{
if !state.is_focused() {
if let Some(on_focus) = on_focus {
if !state.is_focused()
&& let Some(on_focus) = on_focus {
shell.publish(on_focus.clone());
}
}
if state.is_read_only {
state.is_read_only = false;
@ -1681,7 +1674,6 @@ pub fn update<'a, Message: Clone + 'static>(
state.last_click = Some(click);
shell.capture_event();
return;
} else {
state.unfocus();
@ -1717,7 +1709,6 @@ pub fn update<'a, Message: Clone + 'static>(
if cursor.is_over(layout.bounds()) {
shell.capture_event();
}
return;
}
Event::Mouse(mouse::Event::CursorMoved { position })
| Event::Touch(touch::Event::FingerMoved { position, .. }) => {
@ -1800,7 +1791,6 @@ pub fn update<'a, Message: Clone + 'static>(
}
shell.capture_event();
return;
}
}
Event::Keyboard(keyboard::Event::KeyPressed {
@ -1825,14 +1815,13 @@ pub fn update<'a, Message: Clone + 'static>(
if state.keyboard_modifiers.command() {
match key.to_latin(*physical_key) {
Some('c') => {
if !is_secure {
if let Some((start, end)) = state.cursor.selection(value) {
if !is_secure
&& let Some((start, end)) = state.cursor.selection(value) {
clipboard.write(
iced_core::clipboard::Kind::Standard,
value.select(start, end).to_string(),
);
}
}
}
// XXX if we want to allow cutting of secure text, we need to
// update the cache and decide which value to cut
@ -2087,7 +2076,6 @@ pub fn update<'a, Message: Clone + 'static>(
}
shell.capture_event();
return;
}
}
Event::Keyboard(keyboard::Event::KeyReleased { key, .. }) => {
@ -2107,7 +2095,6 @@ pub fn update<'a, Message: Clone + 'static>(
}
shell.capture_event();
return;
}
}
Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) => {
@ -2123,7 +2110,6 @@ pub fn update<'a, Message: Clone + 'static>(
state.preedit = matches!(event, input_method::Event::Opened)
.then(input_method::Preedit::new);
shell.capture_event();
return;
}
input_method::Event::Preedit(content, selection) => {
if state.is_focused() {
@ -2133,7 +2119,6 @@ pub fn update<'a, Message: Clone + 'static>(
text_size: Some(size.into()),
});
shell.capture_event();
return;
}
}
input_method::Event::Commit(text) => {
@ -2151,7 +2136,7 @@ pub fn update<'a, Message: Clone + 'static>(
LAST_FOCUS_UPDATE.with(|x| x.set(focus.updated_at));
let mut editor = Editor::new(unsecured_value, &mut state.cursor);
editor.paste(Value::new(&text));
editor.paste(Value::new(text));
let contents = editor.contents();
let unsecured_value = Value::new(&contents);
@ -2171,7 +2156,6 @@ pub fn update<'a, Message: Clone + 'static>(
update_cache(state, &value);
shell.capture_event();
return;
}
}
}
@ -2201,7 +2185,6 @@ pub fn update<'a, Message: Clone + 'static>(
// TODO: restore value in text input
state.dragging_state = None;
shell.capture_event();
return;
}
}
#[cfg(all(feature = "wayland", target_os = "linux"))]
@ -2211,7 +2194,7 @@ pub fn update<'a, Message: Clone + 'static>(
x,
y,
mime_types,
surface,
surface: _surface,
},
)) if *rectangle == Some(dnd_id) => {
cold();
@ -2251,11 +2234,10 @@ pub fn update<'a, Message: Clone + 'static>(
state.cursor.set_affinity(affinity);
state.cursor.move_to(position);
shell.capture_event();
return;
}
}
#[cfg(all(feature = "wayland", target_os = "linux"))]
Event::Dnd(DndEvent::Offer(rectangle, OfferEvent::Motion { x, y }))
Event::Dnd(DndEvent::Offer(rectangle, OfferEvent::Motion { x, y: _ }))
if *rectangle == Some(dnd_id) =>
{
let state = state();
@ -2280,7 +2262,6 @@ pub fn update<'a, Message: Clone + 'static>(
state.cursor.set_affinity(affinity);
state.cursor.move_to(position);
shell.capture_event();
return;
}
#[cfg(all(feature = "wayland", target_os = "linux"))]
Event::Dnd(DndEvent::Offer(rectangle, OfferEvent::Drop)) if *rectangle == Some(dnd_id) => {
@ -2297,8 +2278,6 @@ pub fn update<'a, Message: Clone + 'static>(
};
state.dnd_offer = DndOfferState::Dropped;
}
return;
}
#[cfg(all(feature = "wayland", target_os = "linux"))]
Event::Dnd(DndEvent::Offer(id, OfferEvent::LeaveDestination)) if Some(dnd_id) != *id => {}
@ -2318,7 +2297,6 @@ pub fn update<'a, Message: Clone + 'static>(
}
};
shell.capture_event();
return;
}
#[cfg(all(feature = "wayland", target_os = "linux"))]
Event::Dnd(DndEvent::Offer(rectangle, OfferEvent::Data { data, mime_type }))
@ -2355,9 +2333,7 @@ pub fn update<'a, Message: Clone + 'static>(
};
update_cache(state, &value);
shell.capture_event();
return;
}
return;
}
_ => {}
}
@ -2790,11 +2766,11 @@ pub fn draw<'a, Message>(
// draw the end icon in the text input
if let (Some(icon), Some(tree)) = (trailing_icon, trailing_icon_tree) {
let mut children = text_layout.children();
let mut icon_layout = children.next().unwrap();
children.next().unwrap(); // skip text layout
if has_start_icon {
icon_layout = children.next().unwrap();
children.next().unwrap(); // skip start-icon layout
}
icon_layout = children.next().unwrap();
let icon_layout = children.next().unwrap(); // trailing-icon layout
icon.as_widget().draw(
tree,

View file

@ -45,9 +45,7 @@ impl Value {
pub fn previous_start_of_word(&self, index: usize) -> usize {
let previous_string = &self.graphemes[..index.min(self.graphemes.len())].concat();
UnicodeSegmentation::split_word_bound_indices(previous_string as &str)
.filter(|(_, word)| !word.trim_start().is_empty())
.next_back()
UnicodeSegmentation::split_word_bound_indices(previous_string as &str).rfind(|(_, word)| !word.trim_start().is_empty())
.map_or(0, |(i, previous_word)| {
index
- UnicodeSegmentation::graphemes(previous_word, true).count()

View file

@ -182,7 +182,8 @@ impl<'a, Message> Widget<Message, crate::Theme, crate::Renderer> for Toggler<'a,
) -> layout::Node {
let limits = limits.width(self.width);
let res = next_to_each_other(
next_to_each_other(
&limits,
self.spacing,
|limits| {
@ -221,8 +222,7 @@ impl<'a, Message> Widget<Message, crate::Theme, crate::Renderer> for Toggler<'a,
}
},
|_| layout::Node::new(Size::new(48., 24.)),
);
res
)
}
fn update(