yoda: warning cleanup sweep (dead code + clippy --fix) (squashed)
Squash of 4 yoda commits: -84437e21yoda: libcosmic-yoda dead-code purge (14->0 warnings) -999db0a4yoda: cosmic-theme cleanup (4->0 warnings) — workspace at 0 warnings total -4743bb8eyoda: cargo clippy --fix on libcosmic-yoda (115->33 warnings) -675f3b59chore: reduce local stack warnings
This commit is contained in:
parent
c85efc6180
commit
4e1080108c
35 changed files with 173 additions and 210 deletions
|
|
@ -270,5 +270,13 @@ tracing = "0.1"
|
||||||
tokio = "1.52"
|
tokio = "1.52"
|
||||||
zbus = { version = "5.15", default-features = false }
|
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]
|
[dev-dependencies]
|
||||||
tempfile = "3.27.0"
|
tempfile = "3.27.0"
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,3 @@ thiserror.workspace = true
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
insta = "1.47.2"
|
insta = "1.47.2"
|
||||||
|
|
||||||
[profile.dev.package]
|
|
||||||
insta.opt-level = 3
|
|
||||||
similar.opt-level = 3
|
|
||||||
|
|
|
||||||
|
|
@ -1062,6 +1062,12 @@ impl ThemeBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_lines)]
|
#[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
|
/// build the theme
|
||||||
pub fn build(self) -> Theme {
|
pub fn build(self) -> Theme {
|
||||||
let Self {
|
let Self {
|
||||||
|
|
|
||||||
|
|
@ -266,6 +266,14 @@ impl From<Theme> for VsTheme {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Theme {
|
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]
|
#[cold]
|
||||||
pub fn apply_vs_code(self) -> Result<(), OutputError> {
|
pub fn apply_vs_code(self) -> Result<(), OutputError> {
|
||||||
let vs_theme = VsTheme::from(self);
|
let vs_theme = VsTheme::from(self);
|
||||||
|
|
@ -291,6 +299,13 @@ impl Theme {
|
||||||
Ok(())
|
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]
|
#[cold]
|
||||||
pub fn reset_vs_code() -> Result<(), OutputError> {
|
pub fn reset_vs_code() -> Result<(), OutputError> {
|
||||||
let mut config_dir = dirs::config_dir().ok_or(OutputError::MissingConfigDir)?;
|
let mut config_dir = dirs::config_dir().ok_or(OutputError::MissingConfigDir)?;
|
||||||
|
|
|
||||||
|
|
@ -284,7 +284,7 @@ where
|
||||||
// app = app.window(window_settings);
|
// app = app.window(window_settings);
|
||||||
core.main_window = Some(iced_core::window::Id::RESERVED);
|
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> {
|
BootData(Rc::new(RefCell::new(Some(BootDataInner::<App> {
|
||||||
flags,
|
flags,
|
||||||
core,
|
core,
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
//! Distribute content horizontally.
|
//! Distribute content horizontally.
|
||||||
use crate::iced;
|
use crate::iced;
|
||||||
use iced::core::alignment::{self, Alignment};
|
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::layout::{self, Layout};
|
||||||
use iced::core::widget::{Operation, Tree};
|
use iced::core::widget::{Operation, Tree};
|
||||||
use iced::core::{
|
use iced::core::{
|
||||||
Clipboard, Element, Length, Padding, Pixels, Rectangle, Shell, Size, Vector, Widget, mouse,
|
Clipboard, Element, Length, Padding, Pixels, Rectangle, Shell, Size, Vector, Widget, mouse,
|
||||||
overlay, renderer, widget,
|
overlay, renderer, widget,
|
||||||
};
|
};
|
||||||
use iced::touch;
|
|
||||||
|
|
||||||
/// A container that distributes its contents horizontally.
|
/// A container that distributes its contents horizontally.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,11 @@ pub static COSMIC_TK: LazyLock<RwLock<CosmicTk>> = LazyLock::new(|| {
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
CosmicTk::get_entry(&c).unwrap_or_else(|(errors, mode)| {
|
CosmicTk::get_entry(&c).unwrap_or_else(|(errors, mode)| {
|
||||||
for why in errors.into_iter().filter(cosmic_config::Error::is_err) {
|
for why in errors.into_iter().filter(cosmic_config::Error::is_err) {
|
||||||
if let cosmic_config::Error::GetKey(_, err) = &why {
|
if let cosmic_config::Error::GetKey(_, err) = &why
|
||||||
if err.kind() == std::io::ErrorKind::NotFound {
|
&& err.kind() == std::io::ErrorKind::NotFound {
|
||||||
// No system default config installed; don't error
|
// No system default config installed; don't error
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
tracing::error!(?why, "CosmicTk config entry error");
|
tracing::error!(?why, "CosmicTk config entry error");
|
||||||
}
|
}
|
||||||
mode
|
mode
|
||||||
|
|
|
||||||
|
|
@ -92,8 +92,6 @@ pub struct Core {
|
||||||
|
|
||||||
pub(super) portal_accent: Option<Srgba>,
|
pub(super) portal_accent: Option<Srgba>,
|
||||||
|
|
||||||
pub(super) portal_is_high_contrast: Option<bool>,
|
|
||||||
|
|
||||||
pub(super) title: HashMap<Id, String>,
|
pub(super) title: HashMap<Id, String>,
|
||||||
|
|
||||||
pub window: Window,
|
pub window: Window,
|
||||||
|
|
@ -183,7 +181,6 @@ impl Default for Core {
|
||||||
settings_daemon: None,
|
settings_daemon: None,
|
||||||
portal_is_dark: None,
|
portal_is_dark: None,
|
||||||
portal_accent: None,
|
portal_accent: None,
|
||||||
portal_is_high_contrast: None,
|
|
||||||
main_window: None,
|
main_window: None,
|
||||||
exit_on_main_window_closed: true,
|
exit_on_main_window_closed: true,
|
||||||
menu_bars: HashMap::new(),
|
menu_bars: HashMap::new(),
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ pub fn subscription<App: ApplicationExt>() -> Subscription<crate::Action<App::Me
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
output
|
let _ = output
|
||||||
.send(crate::Action::Cosmic(crate::app::Action::DbusConnection(
|
.send(crate::Action::Cosmic(crate::app::Action::DbusConnection(
|
||||||
conn.clone(),
|
conn.clone(),
|
||||||
)))
|
)))
|
||||||
|
|
|
||||||
|
|
@ -769,7 +769,7 @@ impl DesktopEntryData {
|
||||||
pub async fn spawn_desktop_exec<S, I, K, V>(
|
pub async fn spawn_desktop_exec<S, I, K, V>(
|
||||||
exec: S,
|
exec: S,
|
||||||
env_vars: I,
|
env_vars: I,
|
||||||
app_id: Option<&str>,
|
_app_id: Option<&str>,
|
||||||
terminal: bool,
|
terminal: bool,
|
||||||
) where
|
) where
|
||||||
S: AsRef<str>,
|
S: AsRef<str>,
|
||||||
|
|
@ -816,13 +816,17 @@ pub async fn spawn_desktop_exec<S, I, K, V>(
|
||||||
// https://systemd.io/DESKTOP_ENVIRONMENTS
|
// https://systemd.io/DESKTOP_ENVIRONMENTS
|
||||||
//
|
//
|
||||||
// Similar to what Gnome sets, for now.
|
// 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")]
|
#[cfg(feature = "desktop-systemd-scope")]
|
||||||
if let Ok(session) = zbus::Connection::session().await {
|
if let Ok(session) = zbus::Connection::session().await {
|
||||||
if let Ok(systemd_manager) = SystemdMangerProxy::new(&session).await {
|
if let Ok(systemd_manager) = SystemdMangerProxy::new(&session).await {
|
||||||
let _ = systemd_manager
|
let _ = systemd_manager
|
||||||
.start_transient_unit(
|
.start_transient_unit(
|
||||||
&format!("app-cosmic-{}-{}.scope", app_id.unwrap_or(&executable), pid),
|
&format!(
|
||||||
|
"app-cosmic-{}-{}.scope",
|
||||||
|
_app_id.unwrap_or(&executable),
|
||||||
|
_pid
|
||||||
|
),
|
||||||
"fail",
|
"fail",
|
||||||
&[
|
&[
|
||||||
(
|
(
|
||||||
|
|
@ -833,7 +837,7 @@ pub async fn spawn_desktop_exec<S, I, K, V>(
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"PIDs".to_string(),
|
"PIDs".to_string(),
|
||||||
zbus::zvariant::Value::from(vec![pid])
|
zbus::zvariant::Value::from(vec![_pid])
|
||||||
.try_to_owned()
|
.try_to_owned()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
11
src/lib.rs
11
src/lib.rs
|
|
@ -146,6 +146,17 @@ pub mod font;
|
||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use iced;
|
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 icon_theme;
|
||||||
pub mod keyboard_nav;
|
pub mod keyboard_nav;
|
||||||
|
|
|
||||||
|
|
@ -170,18 +170,15 @@ impl Button {
|
||||||
* TODO: Checkbox
|
* TODO: Checkbox
|
||||||
*/
|
*/
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[derive(Default)]
|
||||||
pub enum Checkbox {
|
pub enum Checkbox {
|
||||||
|
#[default]
|
||||||
Primary,
|
Primary,
|
||||||
Secondary,
|
Secondary,
|
||||||
Success,
|
Success,
|
||||||
Danger,
|
Danger,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Checkbox {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Primary
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl iced_checkbox::Catalog for Theme {
|
impl iced_checkbox::Catalog for Theme {
|
||||||
type Class<'a> = Checkbox;
|
type Class<'a> = Checkbox;
|
||||||
|
|
@ -1241,7 +1238,7 @@ impl scrollable::Catalog for Theme {
|
||||||
background: Color::TRANSPARENT.into(),
|
background: Color::TRANSPARENT.into(),
|
||||||
border: Border::default(),
|
border: Border::default(),
|
||||||
shadow: Shadow::default(),
|
shadow: Shadow::default(),
|
||||||
icon: Color::TRANSPARENT.into(),
|
icon: Color::TRANSPARENT,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let small_widget_container = self.current_container().small_widget.with_alpha(0.7);
|
let small_widget_container = self.current_container().small_widget.with_alpha(0.7);
|
||||||
|
|
@ -1309,7 +1306,7 @@ impl scrollable::Catalog for Theme {
|
||||||
background: Color::TRANSPARENT.into(),
|
background: Color::TRANSPARENT.into(),
|
||||||
border: Border::default(),
|
border: Border::default(),
|
||||||
shadow: Shadow::default(),
|
shadow: Shadow::default(),
|
||||||
icon: Color::TRANSPARENT.into(),
|
icon: Color::TRANSPARENT,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
crate::widget::column::with_children(content)
|
||||||
.padding(builder.padding)
|
.padding(builder.padding)
|
||||||
.spacing(builder.spacing)
|
.spacing(builder.spacing)
|
||||||
|
|
@ -173,9 +173,11 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "a11y")]
|
#[cfg(feature = "a11y")]
|
||||||
{
|
let button = {
|
||||||
|
let mut button = button;
|
||||||
button = button.name(builder.name).description(builder.description);
|
button = button.name(builder.name).description(builder.description);
|
||||||
}
|
button
|
||||||
|
};
|
||||||
|
|
||||||
let button = button
|
let button = button
|
||||||
.padding(0)
|
.padding(0)
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ where
|
||||||
.width(builder.width)
|
.width(builder.width)
|
||||||
.height(builder.height);
|
.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)
|
.padding(0)
|
||||||
.selected(builder.variant.selected)
|
.selected(builder.variant.selected)
|
||||||
.id(builder.id)
|
.id(builder.id)
|
||||||
|
|
@ -92,9 +92,11 @@ where
|
||||||
.class(builder.class);
|
.class(builder.class);
|
||||||
|
|
||||||
#[cfg(feature = "a11y")]
|
#[cfg(feature = "a11y")]
|
||||||
{
|
let button = {
|
||||||
|
let mut button = button;
|
||||||
button = button.name(builder.name).description(builder.description);
|
button = button.name(builder.name).description(builder.description);
|
||||||
}
|
button
|
||||||
|
};
|
||||||
|
|
||||||
button.into()
|
button.into()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ pub fn icon() -> Handle {
|
||||||
|
|
||||||
impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Message> {
|
impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Message> {
|
||||||
fn from(mut builder: Button<'a, Message>) -> 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({
|
.push({
|
||||||
// TODO: Avoid allocation
|
// TODO: Avoid allocation
|
||||||
crate::widget::text(builder.label.to_string())
|
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);
|
.class(builder.class);
|
||||||
|
|
||||||
#[cfg(feature = "a11y")]
|
#[cfg(feature = "a11y")]
|
||||||
{
|
let button = {
|
||||||
|
let mut button = button;
|
||||||
if !builder.label.is_empty() {
|
if !builder.label.is_empty() {
|
||||||
button = button.name(builder.label);
|
button = button.name(builder.label);
|
||||||
}
|
}
|
||||||
|
|
||||||
button = button.description(builder.description);
|
button = button.description(builder.description);
|
||||||
}
|
button
|
||||||
|
};
|
||||||
|
|
||||||
if builder.tooltip.is_empty() {
|
if builder.tooltip.is_empty() {
|
||||||
button.into()
|
button.into()
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
|
||||||
.into()
|
.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.
|
// Optional icon to place before label.
|
||||||
.push_maybe(leading_icon)
|
.push_maybe(leading_icon)
|
||||||
// Optional label between icons.
|
// Optional label between icons.
|
||||||
|
|
@ -141,13 +141,15 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
|
||||||
.class(builder.class);
|
.class(builder.class);
|
||||||
|
|
||||||
#[cfg(feature = "a11y")]
|
#[cfg(feature = "a11y")]
|
||||||
{
|
let button = {
|
||||||
|
let mut button = button;
|
||||||
if !builder.label.is_empty() {
|
if !builder.label.is_empty() {
|
||||||
button = button.name(builder.label)
|
button = button.name(builder.label)
|
||||||
}
|
}
|
||||||
|
|
||||||
button = button.description(builder.description);
|
button = button.description(builder.description);
|
||||||
}
|
button
|
||||||
|
};
|
||||||
|
|
||||||
if builder.tooltip.is_empty() {
|
if builder.tooltip.is_empty() {
|
||||||
button.into()
|
button.into()
|
||||||
|
|
|
||||||
|
|
@ -379,13 +379,12 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
match event {
|
match event {
|
||||||
Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left))
|
Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left))
|
||||||
| Event::Touch(touch::Event::FingerPressed { .. }) => {
|
| Event::Touch(touch::Event::FingerPressed { .. }) => {
|
||||||
if let Some(position) = cursor.position() {
|
if let Some(position) = cursor.position()
|
||||||
if removal_bounds(layout.bounds(), 4.0).contains(position) {
|
&& removal_bounds(layout.bounds(), 4.0).contains(position) {
|
||||||
shell.publish(on_remove.clone());
|
shell.publish(on_remove.clone());
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
@ -576,9 +575,9 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if on_remove.is_some() {
|
if on_remove.is_some()
|
||||||
if let Some(position) = cursor.position() {
|
&& let Some(position) = cursor.position()
|
||||||
if bounds.contains(position) {
|
&& bounds.contains(position) {
|
||||||
let bounds = removal_bounds(layout.bounds(), 4.0);
|
let bounds = removal_bounds(layout.bounds(), 4.0);
|
||||||
renderer.fill_quad(
|
renderer.fill_quad(
|
||||||
renderer::Quad {
|
renderer::Quad {
|
||||||
|
|
@ -610,8 +609,6 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -762,12 +759,6 @@ impl State {
|
||||||
self.is_focused
|
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`].
|
/// Focuses the [`Button`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn focus(&mut self) {
|
pub fn focus(&mut self) {
|
||||||
|
|
@ -813,7 +804,6 @@ pub fn update<'a, Message: Clone>(
|
||||||
}
|
}
|
||||||
|
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -833,7 +823,6 @@ pub fn update<'a, Message: Clone>(
|
||||||
}
|
}
|
||||||
|
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
} else if on_press_down.is_some() {
|
} else if on_press_down.is_some() {
|
||||||
let state = state();
|
let state = state();
|
||||||
|
|
@ -853,7 +842,6 @@ pub fn update<'a, Message: Clone>(
|
||||||
shell.publish(msg);
|
shell.publish(msg);
|
||||||
}
|
}
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
Event::Keyboard(keyboard::Event::KeyPressed { key, .. }) => {
|
Event::Keyboard(keyboard::Event::KeyPressed { key, .. }) => {
|
||||||
if let Some(on_press) = on_press {
|
if let Some(on_press) = on_press {
|
||||||
|
|
@ -864,7 +852,6 @@ pub fn update<'a, Message: Clone>(
|
||||||
|
|
||||||
shell.publish(msg);
|
shell.publish(msg);
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -525,7 +525,7 @@ where
|
||||||
let c_layout = layout.next().unwrap();
|
let c_layout = layout.next().unwrap();
|
||||||
let state = clear_all_state.unwrap();
|
let state = clear_all_state.unwrap();
|
||||||
self.clear_all_button.as_widget_mut().update(
|
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,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -535,7 +535,7 @@ where
|
||||||
|
|
||||||
for ((inner, layout), c_state) in self.elements.iter_mut().zip(layout).zip(tree_children) {
|
for ((inner, layout), c_state) in self.elements.iter_mut().zip(layout).zip(tree_children) {
|
||||||
inner.as_widget_mut().update(
|
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 {
|
if shell.is_event_captured() || fully_unexpanded {
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -723,7 +723,7 @@ where
|
||||||
let column_tree = &mut tree.children[0];
|
let column_tree = &mut tree.children[0];
|
||||||
self.inner.as_widget_mut().update(
|
self.inner.as_widget_mut().update(
|
||||||
column_tree,
|
column_tree,
|
||||||
&event,
|
event,
|
||||||
column_layout,
|
column_layout,
|
||||||
cursor,
|
cursor,
|
||||||
renderer,
|
renderer,
|
||||||
|
|
@ -736,22 +736,19 @@ where
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
match event {
|
if let Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) = event {
|
||||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
|
let bounds = column_layout.children().nth(1).unwrap().bounds();
|
||||||
let bounds = column_layout.children().nth(1).unwrap().bounds();
|
if let Some(point) = cursor.position_over(bounds) {
|
||||||
if let Some(point) = cursor.position_over(bounds) {
|
let relative_pos = point - bounds.position();
|
||||||
let relative_pos = point - bounds.position();
|
let (s, v) = (
|
||||||
let (s, v) = (
|
relative_pos.x / bounds.width,
|
||||||
relative_pos.x / bounds.width,
|
1.0 - relative_pos.y / bounds.height,
|
||||||
1.0 - relative_pos.y / bounds.height,
|
);
|
||||||
);
|
state.dragging = true;
|
||||||
state.dragging = true;
|
let hsv: palette::Hsv = palette::Hsv::new(self.active_color.hue, s, v);
|
||||||
let hsv: palette::Hsv = palette::Hsv::new(self.active_color.hue, s, v);
|
shell.publish((self.on_update)(ColorPickerUpdate::ActiveColor(hsv)));
|
||||||
shell.publish((self.on_update)(ColorPickerUpdate::ActiveColor(hsv)));
|
shell.capture_event();
|
||||||
shell.capture_event();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -357,7 +357,7 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
x, y, mime_types, ..
|
x, y, mime_types, ..
|
||||||
},
|
},
|
||||||
)) if *id == Some(my_id) => {
|
)) if *id == Some(my_id) => {
|
||||||
if !self.mime_matches(&mime_types) {
|
if !self.mime_matches(mime_types) {
|
||||||
log::trace!(
|
log::trace!(
|
||||||
target: DND_DEST_LOG_TARGET,
|
target: DND_DEST_LOG_TARGET,
|
||||||
"offer enter id={my_id:?} ignored (mimes={mime_types:?} not in {:?})",
|
"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();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
Event::Dnd(DndEvent::Offer(_, OfferEvent::Leave)) => {
|
Event::Dnd(DndEvent::Offer(_, OfferEvent::Leave)) => {
|
||||||
log::trace!(
|
log::trace!(
|
||||||
|
|
@ -424,7 +423,6 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
viewport,
|
viewport,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
Event::Dnd(DndEvent::Offer(id, OfferEvent::Motion { x, y })) if *id == Some(my_id) => {
|
Event::Dnd(DndEvent::Offer(id, OfferEvent::Motion { x, y })) if *id == Some(my_id) => {
|
||||||
log::trace!(
|
log::trace!(
|
||||||
|
|
@ -459,7 +457,6 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
Event::Dnd(DndEvent::Offer(_, OfferEvent::LeaveDestination)) => {
|
Event::Dnd(DndEvent::Offer(_, OfferEvent::LeaveDestination)) => {
|
||||||
log::trace!(
|
log::trace!(
|
||||||
|
|
@ -472,7 +469,6 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
{
|
{
|
||||||
shell.publish(msg);
|
shell.publish(msg);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
Event::Dnd(DndEvent::Offer(id, OfferEvent::Drop)) if *id == Some(my_id) => {
|
Event::Dnd(DndEvent::Offer(id, OfferEvent::Drop)) if *id == Some(my_id) => {
|
||||||
log::trace!(
|
log::trace!(
|
||||||
|
|
@ -485,7 +481,6 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
shell.publish(msg);
|
shell.publish(msg);
|
||||||
}
|
}
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
Event::Dnd(DndEvent::Offer(id, OfferEvent::SelectedAction(action)))
|
Event::Dnd(DndEvent::Offer(id, OfferEvent::SelectedAction(action)))
|
||||||
if *id == Some(my_id) =>
|
if *id == Some(my_id) =>
|
||||||
|
|
@ -503,7 +498,6 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
shell.publish(msg);
|
shell.publish(msg);
|
||||||
}
|
}
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
Event::Dnd(DndEvent::Offer(id, OfferEvent::Data { data, mime_type }))
|
Event::Dnd(DndEvent::Offer(id, OfferEvent::Data { data, mime_type }))
|
||||||
if *id == Some(my_id) =>
|
if *id == Some(my_id) =>
|
||||||
|
|
@ -543,7 +537,6 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -474,16 +474,14 @@ where
|
||||||
match event {
|
match event {
|
||||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
|
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
|
||||||
let hovered_guard = self.hovered_option.lock().unwrap();
|
let hovered_guard = self.hovered_option.lock().unwrap();
|
||||||
if cursor.is_over(layout.bounds()) {
|
if cursor.is_over(layout.bounds())
|
||||||
if let Some(index) = *hovered_guard {
|
&& let Some(index) = *hovered_guard {
|
||||||
shell.publish((self.on_selected)(index));
|
shell.publish((self.on_selected)(index));
|
||||||
if let Some(close_on_selected) = self.close_on_selected.as_ref() {
|
if let Some(close_on_selected) = self.close_on_selected.as_ref() {
|
||||||
shell.publish(close_on_selected.clone());
|
shell.publish(close_on_selected.clone());
|
||||||
}
|
}
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Event::Mouse(mouse::Event::CursorMoved { .. }) => {
|
Event::Mouse(mouse::Event::CursorMoved { .. }) => {
|
||||||
if let Some(cursor_position) = cursor.position_in(layout.bounds()) {
|
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 new_hovered_option = (cursor_position.y / option_height) as usize;
|
||||||
let mut hovered_guard = self.hovered_option.lock().unwrap();
|
let mut hovered_guard = self.hovered_option.lock().unwrap();
|
||||||
|
|
||||||
if let Some(on_option_hovered) = self.on_option_hovered {
|
if let Some(on_option_hovered) = self.on_option_hovered
|
||||||
if *hovered_guard != Some(new_hovered_option) {
|
&& *hovered_guard != Some(new_hovered_option) {
|
||||||
shell.publish(on_option_hovered(new_hovered_option));
|
shell.publish(on_option_hovered(new_hovered_option));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
*hovered_guard = Some(new_hovered_option);
|
*hovered_guard = Some(new_hovered_option);
|
||||||
}
|
}
|
||||||
|
|
@ -526,7 +523,6 @@ where
|
||||||
shell.publish(close_on_selected.clone());
|
shell.publish(close_on_selected.clone());
|
||||||
}
|
}
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -343,13 +343,11 @@ where
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
|
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
|
||||||
if cursor.is_over(bounds) {
|
if cursor.is_over(bounds)
|
||||||
if let Some(item) = self.hovered_option.as_ref() {
|
&& let Some(item) = self.hovered_option.as_ref() {
|
||||||
shell.publish((self.on_selected)(item.clone()));
|
shell.publish((self.on_selected)(item.clone()));
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Event::Mouse(mouse::Event::CursorMoved { .. }) => {
|
Event::Mouse(mouse::Event::CursorMoved { .. }) => {
|
||||||
if let Some(cursor_position) = cursor.position_in(bounds) {
|
if let Some(cursor_position) = cursor.position_in(bounds) {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use super::menu::{self, Menu};
|
||||||
use crate::widget::icon;
|
use crate::widget::icon;
|
||||||
use derive_setters::Setters;
|
use derive_setters::Setters;
|
||||||
use iced_core::event::Event;
|
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::widget::tree::{self, Tree};
|
||||||
use iced_core::{
|
use iced_core::{
|
||||||
Clipboard, Layout, Length, Padding, Pixels, Rectangle, Shadow, Shell, Size, Vector, Widget,
|
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,
|
_viewport: &Rectangle,
|
||||||
) {
|
) {
|
||||||
update(
|
update(
|
||||||
&event,
|
event,
|
||||||
layout,
|
layout,
|
||||||
cursor,
|
cursor,
|
||||||
shell,
|
shell,
|
||||||
|
|
|
||||||
|
|
@ -263,7 +263,7 @@ where
|
||||||
_viewport: &Rectangle,
|
_viewport: &Rectangle,
|
||||||
) {
|
) {
|
||||||
update::<S, Message, AppMessage>(
|
update::<S, Message, AppMessage>(
|
||||||
&event,
|
event,
|
||||||
layout,
|
layout,
|
||||||
cursor,
|
cursor,
|
||||||
shell,
|
shell,
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ impl Axis {
|
||||||
/// padding and alignment to the items as needed.
|
/// padding and alignment to the items as needed.
|
||||||
///
|
///
|
||||||
/// It returns a new layout [`Node`].
|
/// 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>(
|
pub fn resolve<'a, E, Message, Renderer>(
|
||||||
axis: &Axis,
|
axis: &Axis,
|
||||||
renderer: &Renderer,
|
renderer: &Renderer,
|
||||||
|
|
@ -246,7 +247,7 @@ pub fn resolve_wrapper<'a, Message>(
|
||||||
if align_items == Alignment::Center {
|
if align_items == Alignment::Center {
|
||||||
let mut fill_cross = axis.cross(limits.min());
|
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 c_size = child.size();
|
||||||
let cross_fill_factor = match axis {
|
let cross_fill_factor = match axis {
|
||||||
Axis::Horizontal => c_size.height,
|
Axis::Horizontal => c_size.height,
|
||||||
|
|
@ -269,7 +270,7 @@ pub fn resolve_wrapper<'a, Message>(
|
||||||
cross = fill_cross;
|
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 c_size = child.size();
|
||||||
let fill_factor = match axis {
|
let fill_factor = match axis {
|
||||||
Axis::Horizontal => c_size.width,
|
Axis::Horizontal => c_size.width,
|
||||||
|
|
@ -312,7 +313,7 @@ pub fn resolve_wrapper<'a, Message>(
|
||||||
|
|
||||||
let remaining = available.max(0.0);
|
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 c_size = child.size();
|
||||||
let fill_factor = match axis {
|
let fill_factor = match axis {
|
||||||
Axis::Horizontal => c_size.width,
|
Axis::Horizontal => c_size.width,
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,6 @@ pub(crate) struct MenuBarStateInner {
|
||||||
pub(crate) tree: Tree,
|
pub(crate) tree: Tree,
|
||||||
pub(crate) popup_id: HashMap<window::Id, window::Id>,
|
pub(crate) popup_id: HashMap<window::Id, window::Id>,
|
||||||
pub(crate) pressed: bool,
|
pub(crate) pressed: bool,
|
||||||
pub(crate) bar_pressed: bool,
|
|
||||||
pub(crate) view_cursor: Cursor,
|
pub(crate) view_cursor: Cursor,
|
||||||
pub(crate) open: bool,
|
pub(crate) open: bool,
|
||||||
pub(crate) active_root: Vec<usize>,
|
pub(crate) active_root: Vec<usize>,
|
||||||
|
|
@ -87,7 +86,6 @@ impl Default for MenuBarStateInner {
|
||||||
vertical_direction: Direction::Positive,
|
vertical_direction: Direction::Positive,
|
||||||
menu_states: Vec::new(),
|
menu_states: Vec::new(),
|
||||||
popup_id: HashMap::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.
|
/// A `MenuBar` collects `MenuTree`s and handles all the layout, event processing, and drawing.
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
|
|
@ -622,14 +612,12 @@ where
|
||||||
.with_data(|d| !d.open && !d.active_root.is_empty());
|
.with_data(|d| !d.open && !d.active_root.is_empty());
|
||||||
|
|
||||||
let open = my_state.inner.with_data_mut(|state| {
|
let open = my_state.inner.with_data_mut(|state| {
|
||||||
if reset {
|
if reset
|
||||||
if let Some(popup_id) = state.popup_id.get(&self.window_id).copied() {
|
&& let Some(popup_id) = state.popup_id.get(&self.window_id).copied()
|
||||||
if let Some(handler) = self.on_surface_action.as_ref() {
|
&& let Some(handler) = self.on_surface_action.as_ref() {
|
||||||
shell.publish((handler)(crate::surface::Action::DestroyPopup(popup_id)));
|
shell.publish((handler)(crate::surface::Action::DestroyPopup(popup_id)));
|
||||||
state.reset();
|
state.reset();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
state.open
|
state.open
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1569,14 +1569,13 @@ where
|
||||||
.is_some_and(|i| *i != new_index && !active_menu[*i].children.is_empty());
|
.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"))]
|
#[cfg(all(feature = "multi-window", feature = "wayland", target_os = "linux", feature = "surface-message"))]
|
||||||
if matches!(WINDOWING_SYSTEM.get(), Some(WindowingSystem::Wayland)) && remove {
|
if matches!(WINDOWING_SYSTEM.get(), Some(WindowingSystem::Wayland)) && remove
|
||||||
if let Some(id) = state.popup_id.remove(&menu.window_id) {
|
&& let Some(id) = state.popup_id.remove(&menu.window_id) {
|
||||||
state.active_root.truncate(menu.depth + 1);
|
state.active_root.truncate(menu.depth + 1);
|
||||||
shell.publish((menu.on_surface_action.as_ref().unwrap())({
|
shell.publish((menu.on_surface_action.as_ref().unwrap())({
|
||||||
crate::surface::action::destroy_popup(id)
|
crate::surface::action::destroy_popup(id)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
let item = &active_menu[new_index];
|
let item = &active_menu[new_index];
|
||||||
// set new index
|
// set new index
|
||||||
let old_index = last_menu_state.index.replace(new_index);
|
let old_index = last_menu_state.index.replace(new_index);
|
||||||
|
|
|
||||||
|
|
@ -160,8 +160,8 @@ where
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if let Some(on_close) = self.on_close.as_ref() {
|
} else if let Some(on_close) = self.on_close.as_ref()
|
||||||
if matches!(
|
&& matches!(
|
||||||
event,
|
event,
|
||||||
Event::Mouse(mouse::Event::ButtonPressed(_))
|
Event::Mouse(mouse::Event::ButtonPressed(_))
|
||||||
| Event::Touch(touch::Event::FingerPressed { .. })
|
| Event::Touch(touch::Event::FingerPressed { .. })
|
||||||
|
|
@ -169,7 +169,6 @@ where
|
||||||
{
|
{
|
||||||
shell.publish(on_close.clone());
|
shell.publish(on_close.clone());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide cursor from background content when modal popup is active
|
// Hide cursor from background content when modal popup is active
|
||||||
|
|
@ -492,12 +491,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.
|
/// The first child in [`Popover::children`] is always the wrapped content.
|
||||||
fn content_tree(tree: &Tree) -> &Tree {
|
fn content_tree(tree: &Tree) -> &Tree {
|
||||||
&tree.children[0]
|
&tree.children[0]
|
||||||
|
|
|
||||||
|
|
@ -262,7 +262,6 @@ where
|
||||||
if cursor.is_over(layout.bounds()) {
|
if cursor.is_over(layout.bounds()) {
|
||||||
shell.publish(self.on_click.clone());
|
shell.publish(self.on_click.clone());
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
||||||
|
|
@ -713,11 +713,10 @@ where
|
||||||
|
|
||||||
if let Some(icon) = self.model.icon(key) {
|
if let Some(icon) = self.model.icon(key) {
|
||||||
non_text_width += f32::from(icon.size) + f32::from(self.button_spacing);
|
non_text_width += f32::from(icon.size) + f32::from(self.button_spacing);
|
||||||
} else if self.model.is_active(key) {
|
} else if self.model.is_active(key)
|
||||||
if let crate::theme::SegmentedButton::Control = self.style {
|
&& let crate::theme::SegmentedButton::Control = self.style {
|
||||||
non_text_width += 16.0 + f32::from(self.button_spacing);
|
non_text_width += 16.0 + f32::from(self.button_spacing);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if self.model.is_closable(key) {
|
if self.model.is_closable(key) {
|
||||||
non_text_width +=
|
non_text_width +=
|
||||||
|
|
@ -1367,11 +1366,10 @@ where
|
||||||
{
|
{
|
||||||
state.drop_hint = None;
|
state.drop_hint = None;
|
||||||
self.emit_drop_hint(shell, state.drop_hint);
|
self.emit_drop_hint(shell, state.drop_hint);
|
||||||
if let Some(Some(entity)) = entity {
|
if let Some(Some(entity)) = entity
|
||||||
if let Some(on_dnd_leave) = self.on_dnd_leave.as_ref() {
|
&& let Some(on_dnd_leave) = self.on_dnd_leave.as_ref() {
|
||||||
shell.publish(on_dnd_leave(entity));
|
shell.publish(on_dnd_leave(entity));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
log::trace!(
|
log::trace!(
|
||||||
target: TAB_REORDER_LOG_TARGET,
|
target: TAB_REORDER_LOG_TARGET,
|
||||||
"offer leave id={my_id:?} entity={entity:?}"
|
"offer leave id={my_id:?} entity={entity:?}"
|
||||||
|
|
@ -1447,11 +1445,10 @@ where
|
||||||
None::<fn(_, _, _) -> Message>,
|
None::<fn(_, _, _) -> Message>,
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
if let Some(on_dnd_leave) = self.on_dnd_leave.as_ref() {
|
if let Some(on_dnd_leave) = self.on_dnd_leave.as_ref()
|
||||||
if let Some(Some(entity)) = entity {
|
&& let Some(Some(entity)) = entity {
|
||||||
shell.publish(on_dnd_leave(entity));
|
shell.publish(on_dnd_leave(entity));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DndEvent::Offer(id, OfferEvent::Drop) if Some(my_id) == *id => {
|
DndEvent::Offer(id, OfferEvent::Drop) if Some(my_id) == *id => {
|
||||||
|
|
@ -1624,8 +1621,8 @@ where
|
||||||
// Emit close message if the close button is pressed.
|
// Emit close message if the close button is pressed.
|
||||||
if let Some(on_close) = self.on_close.as_ref() {
|
if let Some(on_close) = self.on_close.as_ref() {
|
||||||
if over_close_button
|
if over_close_button
|
||||||
&& (left_button_released(&event)
|
&& (left_button_released(event)
|
||||||
|| (touch_lifted(&event) && fingers_pressed == 1))
|
|| (touch_lifted(event) && fingers_pressed == 1))
|
||||||
{
|
{
|
||||||
shell.publish(on_close(key));
|
shell.publish(on_close(key));
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
|
|
@ -1679,7 +1676,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_lifted(&event) {
|
if is_lifted(event) {
|
||||||
state.unfocus();
|
state.unfocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1723,7 +1720,7 @@ where
|
||||||
if let Some(on_activate) = self.on_activate.as_ref() {
|
if let Some(on_activate) = self.on_activate.as_ref() {
|
||||||
if is_pressed(event) {
|
if is_pressed(event) {
|
||||||
state.pressed_item = Some(Item::Tab(key));
|
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));
|
shell.publish(on_activate(key));
|
||||||
state.set_focused();
|
state.set_focused();
|
||||||
state.focused_item = Item::Tab(key);
|
state.focused_item = Item::Tab(key);
|
||||||
|
|
@ -1763,8 +1760,8 @@ where
|
||||||
// Present a context menu on a right click event.
|
// Present a context menu on a right click event.
|
||||||
if self.context_menu.is_some()
|
if self.context_menu.is_some()
|
||||||
&& let Some(on_context) = self.on_context.as_ref()
|
&& let Some(on_context) = self.on_context.as_ref()
|
||||||
&& (right_button_released(&event)
|
&& (right_button_released(event)
|
||||||
|| (touch_lifted(&event) && fingers_pressed == 2))
|
|| (touch_lifted(event) && fingers_pressed == 2))
|
||||||
{
|
{
|
||||||
state.show_context = Some(key);
|
state.show_context = Some(key);
|
||||||
state.context_cursor = cursor_position.position().unwrap_or_default();
|
state.context_cursor = cursor_position.position().unwrap_or_default();
|
||||||
|
|
@ -1882,12 +1879,12 @@ where
|
||||||
}
|
}
|
||||||
if state.is_focused() {
|
if state.is_focused() {
|
||||||
// Unfocus on clicks outside of the boundaries of the segmented button.
|
// Unfocus on clicks outside of the boundaries of the segmented button.
|
||||||
if is_pressed(&event) {
|
if is_pressed(event) {
|
||||||
state.unfocus();
|
state.unfocus();
|
||||||
state.pressed_item = None;
|
state.pressed_item = None;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if is_lifted(&event) {
|
} else if is_lifted(event) {
|
||||||
state.pressed_item = None;
|
state.pressed_item = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2534,8 +2531,8 @@ where
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if show_drop_hint_marker {
|
if show_drop_hint_marker
|
||||||
if matches!(
|
&& matches!(
|
||||||
drop_hint_marker,
|
drop_hint_marker,
|
||||||
Some(DropHint {
|
Some(DropHint {
|
||||||
entity,
|
entity,
|
||||||
|
|
@ -2550,7 +2547,6 @@ where
|
||||||
appearance.active.text_color,
|
appearance.active.text_color,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
nth += 1;
|
nth += 1;
|
||||||
});
|
});
|
||||||
|
|
@ -2760,7 +2756,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TabDragSource<Message> {
|
pub(super) struct TabDragSource<Message> {
|
||||||
mime: String,
|
mime: String,
|
||||||
threshold: f32,
|
threshold: f32,
|
||||||
_marker: PhantomData<Message>,
|
_marker: PhantomData<Message>,
|
||||||
|
|
@ -2811,7 +2807,6 @@ struct TabDragCandidate {
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
struct Focus {
|
struct Focus {
|
||||||
updated_at: Instant,
|
updated_at: Instant,
|
||||||
now: Instant,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// State that is maintained by each individual widget.
|
/// State that is maintained by each individual widget.
|
||||||
|
|
@ -2884,7 +2879,6 @@ impl LocalState {
|
||||||
|
|
||||||
self.focused = Some(Focus {
|
self.focused = Some(Focus {
|
||||||
updated_at: now,
|
updated_at: now,
|
||||||
now,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ pub fn spin_button<'a, T, M>(
|
||||||
where
|
where
|
||||||
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
|
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
|
||||||
{
|
{
|
||||||
let mut button = SpinButton::new(
|
let button = SpinButton::new(
|
||||||
label,
|
label,
|
||||||
value,
|
value,
|
||||||
step,
|
step,
|
||||||
|
|
@ -34,9 +34,11 @@ where
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "a11y")]
|
#[cfg(feature = "a11y")]
|
||||||
{
|
let button = {
|
||||||
|
let mut button = button;
|
||||||
button = button.name(name.into());
|
button = button.name(name.into());
|
||||||
}
|
button
|
||||||
|
};
|
||||||
|
|
||||||
button
|
button
|
||||||
}
|
}
|
||||||
|
|
@ -54,20 +56,22 @@ pub fn vertical<'a, T, M>(
|
||||||
where
|
where
|
||||||
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
|
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
|
||||||
{
|
{
|
||||||
let mut button = SpinButton::new(
|
let button = SpinButton::new(
|
||||||
label,
|
label,
|
||||||
value,
|
value,
|
||||||
step,
|
step,
|
||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
Orientation::Horizontal,
|
Orientation::Vertical,
|
||||||
on_press,
|
on_press,
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "a11y")]
|
#[cfg(feature = "a11y")]
|
||||||
{
|
let button = {
|
||||||
|
let mut button = button;
|
||||||
button = button.name(name.into());
|
button = button.name(name.into());
|
||||||
}
|
button
|
||||||
|
};
|
||||||
|
|
||||||
button
|
button
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,15 +84,14 @@ where
|
||||||
|
|
||||||
let mut sort_state = 0;
|
let mut sort_state = 0;
|
||||||
|
|
||||||
if let Some(sort) = val.model.sort {
|
if let Some(sort) = val.model.sort
|
||||||
if sort.0 == category {
|
&& sort.0 == category {
|
||||||
if sort.1 {
|
if sort.1 {
|
||||||
sort_state = 1;
|
sort_state = 1;
|
||||||
} else {
|
} else {
|
||||||
sort_state = 2;
|
sort_state = 2;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
// Build the category header
|
// Build the category header
|
||||||
widget::row::with_capacity(2)
|
widget::row::with_capacity(2)
|
||||||
|
|
|
||||||
|
|
@ -666,18 +666,15 @@ where
|
||||||
let old_value = Value::new(&old_value);
|
let old_value = Value::new(&old_value);
|
||||||
if state.is_focused()
|
if state.is_focused()
|
||||||
&& let cursor::State::Index(index) = state.cursor.state(&old_value)
|
&& let cursor::State::Index(index) = state.cursor.state(&old_value)
|
||||||
{
|
&& index == old_value.len() {
|
||||||
if index == old_value.len() {
|
|
||||||
state.cursor.move_to(self.value.len());
|
state.cursor.move_to(self.value.len());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(f) = state.is_focused.as_ref().filter(|f| f.focused) {
|
if let Some(f) = state.is_focused.as_ref().filter(|f| f.focused)
|
||||||
if f.updated_at != LAST_FOCUS_UPDATE.with(|f| f.get()) {
|
&& f.updated_at != LAST_FOCUS_UPDATE.with(|f| f.get()) {
|
||||||
state.unfocus();
|
state.unfocus();
|
||||||
state.emit_unfocus = true;
|
state.emit_unfocus = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if self.is_editable_variant {
|
if self.is_editable_variant {
|
||||||
if !state.is_focused() {
|
if !state.is_focused() {
|
||||||
|
|
@ -891,8 +888,8 @@ where
|
||||||
let line_height = self.line_height;
|
let line_height = self.line_height;
|
||||||
|
|
||||||
// Disables editing of the editable variant when clicking outside of, or for tab focus changes.
|
// Disables editing of the editable variant when clicking outside of, or for tab focus changes.
|
||||||
if self.is_editable_variant {
|
if self.is_editable_variant
|
||||||
if let Some(ref on_edit) = self.on_toggle_edit {
|
&& let Some(ref on_edit) = self.on_toggle_edit {
|
||||||
let state = tree.state.downcast_mut::<State>();
|
let state = tree.state.downcast_mut::<State>();
|
||||||
if !state.is_read_only && state.is_focused.is_some_and(|f| !f.focused) {
|
if !state.is_read_only && state.is_focused.is_some_and(|f| !f.focused) {
|
||||||
state.is_read_only = true;
|
state.is_read_only = true;
|
||||||
|
|
@ -904,7 +901,6 @@ where
|
||||||
shell.publish((on_edit)(f.focused));
|
shell.publish((on_edit)(f.focused));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Calculates the layout of the trailing icon button element.
|
// Calculates the layout of the trailing icon button element.
|
||||||
if !tree.children.is_empty() {
|
if !tree.children.is_empty() {
|
||||||
|
|
@ -915,9 +911,9 @@ where
|
||||||
trailing_icon_layout = Some(text_layout.children().last().unwrap());
|
trailing_icon_layout = Some(text_layout.children().last().unwrap());
|
||||||
|
|
||||||
// Enable custom buttons defined on the trailing icon position to be handled.
|
// Enable custom buttons defined on the trailing icon position to be handled.
|
||||||
if !self.is_editable_variant {
|
if !self.is_editable_variant
|
||||||
if let Some(trailing_layout) = trailing_icon_layout {
|
&& let Some(trailing_layout) = trailing_icon_layout {
|
||||||
let _res = trailing_icon.as_widget_mut().update(
|
trailing_icon.as_widget_mut().update(
|
||||||
tree,
|
tree,
|
||||||
event,
|
event,
|
||||||
trailing_layout,
|
trailing_layout,
|
||||||
|
|
@ -932,18 +928,16 @@ where
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let state = tree.state.downcast_mut::<State>();
|
let state = tree.state.downcast_mut::<State>();
|
||||||
|
|
||||||
if let Some(on_unfocus) = self.on_unfocus.as_ref() {
|
if let Some(on_unfocus) = self.on_unfocus.as_ref()
|
||||||
if state.emit_unfocus {
|
&& state.emit_unfocus {
|
||||||
state.emit_unfocus = false;
|
state.emit_unfocus = false;
|
||||||
shell.publish(on_unfocus.clone());
|
shell.publish(on_unfocus.clone());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let dnd_id = self.dnd_id();
|
let dnd_id = self.dnd_id();
|
||||||
let id = Widget::id(self);
|
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))
|
if matches!(state.dragging_state, None | Some(DraggingState::Selection))
|
||||||
&& (!state.is_focused() || (is_editable_variant && state.is_read_only))
|
&& (!state.is_focused() || (is_editable_variant && state.is_read_only))
|
||||||
{
|
{
|
||||||
if !state.is_focused() {
|
if !state.is_focused()
|
||||||
if let Some(on_focus) = on_focus {
|
&& let Some(on_focus) = on_focus {
|
||||||
shell.publish(on_focus.clone());
|
shell.publish(on_focus.clone());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if state.is_read_only {
|
if state.is_read_only {
|
||||||
state.is_read_only = false;
|
state.is_read_only = false;
|
||||||
|
|
@ -1681,7 +1674,6 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
state.last_click = Some(click);
|
state.last_click = Some(click);
|
||||||
|
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
state.unfocus();
|
state.unfocus();
|
||||||
|
|
||||||
|
|
@ -1717,7 +1709,6 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
if cursor.is_over(layout.bounds()) {
|
if cursor.is_over(layout.bounds()) {
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
Event::Mouse(mouse::Event::CursorMoved { position })
|
Event::Mouse(mouse::Event::CursorMoved { position })
|
||||||
| Event::Touch(touch::Event::FingerMoved { position, .. }) => {
|
| Event::Touch(touch::Event::FingerMoved { position, .. }) => {
|
||||||
|
|
@ -1800,7 +1791,6 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
}
|
}
|
||||||
|
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Keyboard(keyboard::Event::KeyPressed {
|
Event::Keyboard(keyboard::Event::KeyPressed {
|
||||||
|
|
@ -1838,14 +1828,13 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
{
|
{
|
||||||
match clip_key {
|
match clip_key {
|
||||||
Some('c') => {
|
Some('c') => {
|
||||||
if !is_secure {
|
if !is_secure
|
||||||
if let Some((start, end)) = state.cursor.selection(value) {
|
&& let Some((start, end)) = state.cursor.selection(value) {
|
||||||
clipboard.write(
|
clipboard.write(
|
||||||
iced_core::clipboard::Kind::Standard,
|
iced_core::clipboard::Kind::Standard,
|
||||||
value.select(start, end).to_string(),
|
value.select(start, end).to_string(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// XXX if we want to allow cutting of secure text, we need to
|
// XXX if we want to allow cutting of secure text, we need to
|
||||||
// update the cache and decide which value to cut
|
// update the cache and decide which value to cut
|
||||||
|
|
@ -2100,7 +2089,6 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
}
|
}
|
||||||
|
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Keyboard(keyboard::Event::KeyReleased { key, .. }) => {
|
Event::Keyboard(keyboard::Event::KeyReleased { key, .. }) => {
|
||||||
|
|
@ -2120,7 +2108,6 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
}
|
}
|
||||||
|
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) => {
|
Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) => {
|
||||||
|
|
@ -2136,7 +2123,6 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
state.preedit = matches!(event, input_method::Event::Opened)
|
state.preedit = matches!(event, input_method::Event::Opened)
|
||||||
.then(input_method::Preedit::new);
|
.then(input_method::Preedit::new);
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
input_method::Event::Preedit(content, selection) => {
|
input_method::Event::Preedit(content, selection) => {
|
||||||
if state.is_focused() {
|
if state.is_focused() {
|
||||||
|
|
@ -2146,7 +2132,6 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
text_size: Some(size.into()),
|
text_size: Some(size.into()),
|
||||||
});
|
});
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
input_method::Event::Commit(text) => {
|
input_method::Event::Commit(text) => {
|
||||||
|
|
@ -2164,7 +2149,7 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
LAST_FOCUS_UPDATE.with(|x| x.set(focus.updated_at));
|
LAST_FOCUS_UPDATE.with(|x| x.set(focus.updated_at));
|
||||||
|
|
||||||
let mut editor = Editor::new(unsecured_value, &mut state.cursor);
|
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 contents = editor.contents();
|
||||||
let unsecured_value = Value::new(&contents);
|
let unsecured_value = Value::new(&contents);
|
||||||
|
|
@ -2184,7 +2169,6 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
|
|
||||||
update_cache(state, &value);
|
update_cache(state, &value);
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2214,7 +2198,6 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
// TODO: restore value in text input
|
// TODO: restore value in text input
|
||||||
state.dragging_state = None;
|
state.dragging_state = None;
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||||
|
|
@ -2224,7 +2207,7 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
mime_types,
|
mime_types,
|
||||||
surface,
|
surface: _surface,
|
||||||
},
|
},
|
||||||
)) if *rectangle == Some(dnd_id) => {
|
)) if *rectangle == Some(dnd_id) => {
|
||||||
cold();
|
cold();
|
||||||
|
|
@ -2264,11 +2247,10 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
state.cursor.set_affinity(affinity);
|
state.cursor.set_affinity(affinity);
|
||||||
state.cursor.move_to(position);
|
state.cursor.move_to(position);
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
#[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) =>
|
if *rectangle == Some(dnd_id) =>
|
||||||
{
|
{
|
||||||
let state = state();
|
let state = state();
|
||||||
|
|
@ -2293,7 +2275,6 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
state.cursor.set_affinity(affinity);
|
state.cursor.set_affinity(affinity);
|
||||||
state.cursor.move_to(position);
|
state.cursor.move_to(position);
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||||
Event::Dnd(DndEvent::Offer(rectangle, OfferEvent::Drop)) if *rectangle == Some(dnd_id) => {
|
Event::Dnd(DndEvent::Offer(rectangle, OfferEvent::Drop)) if *rectangle == Some(dnd_id) => {
|
||||||
|
|
@ -2310,8 +2291,6 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
};
|
};
|
||||||
state.dnd_offer = DndOfferState::Dropped;
|
state.dnd_offer = DndOfferState::Dropped;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||||
Event::Dnd(DndEvent::Offer(id, OfferEvent::LeaveDestination)) if Some(dnd_id) != *id => {}
|
Event::Dnd(DndEvent::Offer(id, OfferEvent::LeaveDestination)) if Some(dnd_id) != *id => {}
|
||||||
|
|
@ -2331,7 +2310,6 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||||
Event::Dnd(DndEvent::Offer(rectangle, OfferEvent::Data { data, mime_type }))
|
Event::Dnd(DndEvent::Offer(rectangle, OfferEvent::Data { data, mime_type }))
|
||||||
|
|
@ -2368,9 +2346,7 @@ pub fn update<'a, Message: Clone + 'static>(
|
||||||
};
|
};
|
||||||
update_cache(state, &value);
|
update_cache(state, &value);
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
@ -2803,11 +2779,11 @@ pub fn draw<'a, Message>(
|
||||||
// draw the end icon in the text input
|
// draw the end icon in the text input
|
||||||
if let (Some(icon), Some(tree)) = (trailing_icon, trailing_icon_tree) {
|
if let (Some(icon), Some(tree)) = (trailing_icon, trailing_icon_tree) {
|
||||||
let mut children = text_layout.children();
|
let mut children = text_layout.children();
|
||||||
let mut icon_layout = children.next().unwrap();
|
children.next().unwrap(); // skip text layout
|
||||||
if has_start_icon {
|
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(
|
icon.as_widget().draw(
|
||||||
tree,
|
tree,
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,7 @@ impl Value {
|
||||||
pub fn previous_start_of_word(&self, index: usize) -> usize {
|
pub fn previous_start_of_word(&self, index: usize) -> usize {
|
||||||
let previous_string = &self.graphemes[..index.min(self.graphemes.len())].concat();
|
let previous_string = &self.graphemes[..index.min(self.graphemes.len())].concat();
|
||||||
|
|
||||||
UnicodeSegmentation::split_word_bound_indices(previous_string as &str)
|
UnicodeSegmentation::split_word_bound_indices(previous_string as &str).rfind(|(_, word)| !word.trim_start().is_empty())
|
||||||
.filter(|(_, word)| !word.trim_start().is_empty())
|
|
||||||
.next_back()
|
|
||||||
.map_or(0, |(i, previous_word)| {
|
.map_or(0, |(i, previous_word)| {
|
||||||
index
|
index
|
||||||
- UnicodeSegmentation::graphemes(previous_word, true).count()
|
- UnicodeSegmentation::graphemes(previous_word, true).count()
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,8 @@ impl<'a, Message> Widget<Message, crate::Theme, crate::Renderer> for Toggler<'a,
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
let limits = limits.width(self.width);
|
let limits = limits.width(self.width);
|
||||||
|
|
||||||
let res = next_to_each_other(
|
|
||||||
|
next_to_each_other(
|
||||||
&limits,
|
&limits,
|
||||||
self.spacing,
|
self.spacing,
|
||||||
|limits| {
|
|limits| {
|
||||||
|
|
@ -221,8 +222,7 @@ impl<'a, Message> Widget<Message, crate::Theme, crate::Renderer> for Toggler<'a,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|_| layout::Node::new(Size::new(48., 24.)),
|
|_| layout::Node::new(Size::new(48., 24.)),
|
||||||
);
|
)
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(
|
fn update(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue