Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ env:
# version like 1.70. Note that we only specify MAJOR.MINOR and not PATCH so that bugfixes still
# come automatically. If the version specified here is no longer the latest stable version,
# then please feel free to submit a PR that adjusts it along with the potential clippy fixes.
RUST_STABLE_VER: "1.82" # In quotes because otherwise 1.70 would be interpreted as 1.7
RUST_STABLE_VER: "1.92" # In quotes because otherwise 1.70 would be interpreted as 1.7

name: CI

Expand Down
6 changes: 3 additions & 3 deletions druid-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use syn::parse_macro_input;
///
/// - `#[data(ignore)]` makes the generated `Data::same` function skip comparing this field.
/// - `#[data(same_fn="foo")]` uses the function `foo` for comparing this field. `foo` should
/// be the name of a function with signature `fn(&T, &T) -> bool`, where `T` is the type of
/// the field.
/// be the name of a function with signature `fn(&T, &T) -> bool`, where `T` is the type of
/// the field.
/// - `#[data(eq)]` is shorthand for `#[data(same_fn = "PartialEq::eq")]`
///
/// # Example
Expand Down Expand Up @@ -61,7 +61,7 @@ pub fn derive_data(input: TokenStream) -> TokenStream {
///
/// - `#[lens(ignore)]` skips creating a lens for one field.
/// - `#[lens(name="foo")]` gives the lens the specified name (instead of the default, which is to
/// create a lens with the same name as the field).
/// create a lens with the same name as the field).
///
/// # Example
///
Expand Down
5 changes: 5 additions & 0 deletions druid-shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ tga = ["piet-common/tga"]
hdr = ["piet-common/hdr"]
serde = ["piet-common/serde"]

[lints]
# The 'objc' package is broken and abandoned, needs this hack.
# https://github.com/SSheldon/rust-objc/issues/125
rust.unexpected_cfgs = { level = "warn", check-cfg = ['cfg(feature, values("cargo-clippy"))'] }

[dependencies]
piet-common = { version = "=0.7.0-cairo18" }

Expand Down
2 changes: 1 addition & 1 deletion druid-shell/examples/edit_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl InputHandler for AppInputHandler {
doc.composition = None;
self.window_handle.request_anim_frame();
}
fn slice(&self, range: Range<usize>) -> Cow<str> {
fn slice(&self, range: Range<usize>) -> Cow<'_, str> {
self.state.borrow().text[range].to_string().into()
}
fn is_char_boundary(&self, i: usize) -> bool {
Expand Down
5 changes: 5 additions & 0 deletions druid-shell/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,8 @@ impl Application {
backend::Application::get_locale()
}
}

/// Perform any initialization needed for the testing harness.
pub fn init_harness() {
backend::init_harness();
}
2 changes: 2 additions & 0 deletions druid-shell/src/backend/gtk/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ impl crate::platform::linux::ApplicationExt for crate::Application {
})
}
}

pub fn init_harness() {}
8 changes: 8 additions & 0 deletions druid-shell/src/backend/mac/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use std::cell::RefCell;
use std::ffi::c_void;
use std::rc::Rc;
use std::sync::Once;

use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular};
use cocoa::base::{id, nil, NO, YES};
Expand Down Expand Up @@ -183,3 +184,10 @@ extern "C" fn handle_menu_item(this: &mut Object, _: Sel, item: id) {
(*inner).command(tag as u32);
}
}

pub fn init_harness() {
static INIT: Once = Once::new();
INIT.call_once(|| unsafe {
let _app: id = msg_send![class!(NSApplication), sharedApplication];
});
}
4 changes: 3 additions & 1 deletion druid-shell/src/backend/wayland/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl Application {
return;
}

if appdata.handles.borrow().len() == 0 {
if appdata.handles.borrow().is_empty() {
tracing::debug!("shutting down, no window remaining");
signal.stop();
return;
Expand Down Expand Up @@ -566,3 +566,5 @@ impl Seat {
}
}
}

pub fn init_harness() {}
1 change: 1 addition & 0 deletions druid-shell/src/backend/wayland/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ where

pub trait GlobalEventDispatch {
fn subscribe(&self, sub: impl Into<GlobalEventSubscription>) -> GlobalEventSubscription;
#[expect(dead_code)] // Until it's not dead
fn release(&self, s: &GlobalEventSubscription);
}

Expand Down
5 changes: 1 addition & 4 deletions druid-shell/src/backend/wayland/surfaces/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ impl Surface {
tracing::debug!("{:?} {:?}", obj, event);
});

let wl_xdg_popup = match parent.surface(&wl_xdg_surface, &wl_xdg_pos) {
Ok(p) => p,
Err(cause) => return Err(cause),
};
let wl_xdg_popup = parent.surface(&wl_xdg_surface, &wl_xdg_pos)?;
wl_xdg_popup.quick_assign({
let wl_surface = wl_surface.clone();
move |_xdg_popup, event, _| {
Expand Down
2 changes: 2 additions & 0 deletions druid-shell/src/backend/web/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ impl Application {
.unwrap_or_else(|| "en-US".into())
}
}

pub fn init_harness() {}
7 changes: 4 additions & 3 deletions druid-shell/src/backend/windows/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ impl Application {
}
let mut msg: MSG = msg.assume_init();
let accels = accels::find_accels(GetAncestor(msg.hwnd, GA_ROOT));
let translated = accels.map_or(false, |it| {
TranslateAcceleratorW(msg.hwnd, it.handle(), &mut msg) != 0
});
let translated = accels
.is_some_and(|it| TranslateAcceleratorW(msg.hwnd, it.handle(), &mut msg) != 0);
if !translated {
TranslateMessage(&msg);
DispatchMessageW(&msg);
Expand Down Expand Up @@ -198,3 +197,5 @@ impl Application {
})
}
}

pub fn init_harness() {}
1 change: 1 addition & 0 deletions druid-shell/src/backend/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl DxgiSurfaceRenderTarget {
}

// error handling
#[allow(dead_code)]
pub enum Error {
WinapiError(HRESULT),
}
Expand Down
1 change: 1 addition & 0 deletions druid-shell/src/backend/windows/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ type GetSystemMetricsForDpi =
// from shcore.dll
type GetDpiForMonitor = unsafe extern "system" fn(HMONITOR, MONITOR_DPI_TYPE, *mut UINT, *mut UINT);
type SetProcessDpiAwareness = unsafe extern "system" fn(PROCESS_DPI_AWARENESS) -> HRESULT;
#[allow(non_snake_case)]
type DCompositionCreateDevice = unsafe extern "system" fn(
dxgiDevice: *const IDXGIDevice,
iid: REFIID,
Expand Down
2 changes: 2 additions & 0 deletions druid-shell/src/backend/x11/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,3 +944,5 @@ fn poll_with_timeout(

Ok(())
}

pub fn init_harness() {}
2 changes: 1 addition & 1 deletion druid-shell/src/backend/x11/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl ClipboardState {
if owner.owner == contents.owner_window {
// We are the new selection owner! Remember our contents for later.
debug!("put_formats(): became selection owner");
if let Some(mut old_owner) = std::mem::replace(&mut self.contents, Some(contents)) {
if let Some(mut old_owner) = self.contents.replace(contents) {
// We already where the owner before. Destroy the old contents.
old_owner.destroy(conn)?;
}
Expand Down
4 changes: 2 additions & 2 deletions druid-shell/src/backend/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,8 @@ pub(crate) struct Window {
///
/// There are three ways that rendering can get triggered:
/// 1) We render a frame, and it signals to us that an animation is requested. In this case, we
/// will render the next frame as soon as we get a notification that the just-presented
/// frame completed. In other words, we use `CompleteNotifyEvent` to schedule rendering.
/// will render the next frame as soon as we get a notification that the just-presented
/// frame completed. In other words, we use `CompleteNotifyEvent` to schedule rendering.
/// 2) We get an expose event telling us that a region got invalidated. In
/// this case, we will render the next frame immediately unless we're already waiting for a
/// completion notification. (If we are waiting for a completion notification, we just make
Expand Down
2 changes: 1 addition & 1 deletion druid-shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ mod window;
pub mod platform;
pub mod text;

pub use application::{AppHandler, Application};
pub use application::{init_harness, AppHandler, Application};
pub use clipboard::{Clipboard, ClipboardFormat, FormatId};
pub use common_util::Counter;
pub use dialog::{FileDialogOptions, FileInfo, FileSpec};
Expand Down
8 changes: 2 additions & 6 deletions druid-shell/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,7 @@ impl Selection {
///
/// If the selection is a caret, this is `0`.
pub fn len(&self) -> usize {
if self.anchor > self.active {
self.anchor - self.active
} else {
self.active - self.anchor
}
self.anchor.abs_diff(self.active)
}

/// Returns `true` if the selection's length is `0`.
Expand Down Expand Up @@ -341,7 +337,7 @@ pub trait InputHandler {
///
/// Panics if the start or end of the range do not fall on a code point
/// boundary.
fn slice(&self, range: Range<usize>) -> Cow<str>;
fn slice(&self, range: Range<usize>) -> Cow<'_, str>;

/// Returns the number of UTF-16 code units in the provided UTF-8 range.
///
Expand Down
3 changes: 2 additions & 1 deletion druid-shell/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl WindowHandle {
/// only guaranteed to be valid for the current pass of the runloop.
// TODO: Can we get rid of the Result/Error for ergonomics?
pub fn get_scale(&self) -> Result<Scale, Error> {
self.0.get_scale().map_err(Into::into)
self.0.get_scale()
}
}

Expand Down Expand Up @@ -553,6 +553,7 @@ impl WindowBuilder {
///
/// If this fails, your application should exit.
pub fn build(self) -> Result<WindowHandle, Error> {
#[allow(clippy::useless_conversion)] // Platform-dependant
self.0.build().map(WindowHandle).map_err(Into::into)
}
}
Expand Down
4 changes: 2 additions & 2 deletions druid/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub trait ChangeCtx {
/// Returns the state of the widget.
///
/// This method should only be used by the framework to do mergeups.
fn state(&mut self) -> State;
fn state(&mut self) -> State<'_>;
}

/// Convenience trait for invalidation and request methods available on multiple contexts.
Expand Down Expand Up @@ -245,7 +245,7 @@ impl_context_trait!(
Self::request_timer(self, deadline)
}

fn state(&mut self) -> State {
fn state(&mut self) -> State<'_> {
State {
//state: &mut *self.state,
widget_state: &mut *self.widget_state,
Expand Down
6 changes: 3 additions & 3 deletions druid/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ mod test {
#[cfg(feature = "im")]
fn im_data() {
for len in 8..256 {
let input = std::iter::repeat(0_u8).take(len).collect::<im::Vector<_>>();
let input = std::iter::repeat_n(0_u8, len).collect::<im::Vector<_>>();
let mut inp2 = input.clone();
assert!(input.same(&inp2));
inp2.set(len - 1, 98);
Expand All @@ -633,8 +633,8 @@ mod test {
#[test]
#[cfg(feature = "im")]
fn im_vec_different_length() {
let one = std::iter::repeat(0_u8).take(9).collect::<im::Vector<_>>();
let two = std::iter::repeat(0_u8).take(10).collect::<im::Vector<_>>();
let one = std::iter::repeat_n(0_u8, 9).collect::<im::Vector<_>>();
let two = std::iter::repeat_n(0_u8, 10).collect::<im::Vector<_>>();
assert!(!one.same(&two));
}

Expand Down
2 changes: 1 addition & 1 deletion druid/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub enum Event {
/// - Widgets and other Druid components can send custom [`Command`]s at
/// runtime, via methods such as [`EventCtx::submit_command`].
///
/// [`Widget`]: Widget
/// [`Widget`]: crate::Widget
/// [`EventCtx::submit_command`]: crate::EventCtx::submit_command
/// [`ExtEventSink`]: crate::ExtEventSink
/// [`MenuItem`]: crate::MenuItem
Expand Down
2 changes: 1 addition & 1 deletion druid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
//! Utility features:
//!
//! * `im` - Efficient immutable data structures using the [`im` crate],
//! which is made available via the [`im` module].
//! which is made available via the [`im` module].
//! * `svg` - Scalable Vector Graphics for icons and other scalable images using the [`usvg` crate].
//! * `image` - Bitmap image support using the [`image` crate].
//! * `x11` - Work-in-progress X11 backend instead of GTK.
Expand Down
10 changes: 3 additions & 7 deletions druid/src/localization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub struct LocalizedString<T> {
struct BundleStack(Vec<FluentBundle<Arc<FluentResource>>>);

impl BundleStack {
fn get_message(&self, id: &str) -> Option<FluentMessage> {
fn get_message(&self, id: &str) -> Option<FluentMessage<'_>> {
self.0.iter().flat_map(|b| b.get_message(id)).next()
}

Expand Down Expand Up @@ -238,14 +238,10 @@ impl L10nManager {
args: impl Into<Option<&'args FluentArgs<'args>>>,
) -> Option<ArcStr> {
let args = args.into();
let value = match self
let value = self
.current_bundle
.get_message(key)
.and_then(|msg| msg.value())
{
Some(v) => v,
None => return None,
};
.and_then(|msg| msg.value())?;
let mut errs = Vec::new();
let result = self
.current_bundle
Expand Down
3 changes: 3 additions & 0 deletions druid/src/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ impl<T: Data> Harness<'_, T> {
mock_app,
window_size,
};

druid_shell::init_harness();

harness_closure(&mut harness);
}
render_context_closure(target)
Expand Down
2 changes: 1 addition & 1 deletion druid/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn temp_dir_for_test() -> std::path::PathBuf {
.prefix("TempDir")
.tempdir_in(test_dir)
.unwrap()
.into_path()
.keep()
}

/// test that the first widget to request focus during an event gets it.
Expand Down
12 changes: 6 additions & 6 deletions druid/src/text/editable_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ pub trait EditableText: Sized {
/// Create a cursor with a reference to the text and a offset position.
///
/// Returns None if the position isn't a codepoint boundary.
fn cursor(&self, position: usize) -> Option<StringCursor>;
fn cursor(&self, position: usize) -> Option<StringCursor<'_>>;

/// Replace range with new text.
/// Can panic if supplied an invalid range.
// TODO: make this generic over Self
fn edit(&mut self, range: Range<usize>, new: impl Into<String>);

/// Get slice of text at range.
fn slice(&self, range: Range<usize>) -> Option<Cow<str>>;
fn slice(&self, range: Range<usize>) -> Option<Cow<'_, str>>;

/// Get length of text (in bytes).
fn len(&self) -> usize;
Expand Down Expand Up @@ -62,7 +62,7 @@ pub trait EditableText: Sized {
}

impl EditableText for String {
fn cursor<'a>(&self, position: usize) -> Option<StringCursor> {
fn cursor<'a>(&self, position: usize) -> Option<StringCursor<'_>> {
let new_cursor = StringCursor {
text: self,
position,
Expand All @@ -79,7 +79,7 @@ impl EditableText for String {
self.replace_range(range, &new.into());
}

fn slice(&self, range: Range<usize>) -> Option<Cow<str>> {
fn slice(&self, range: Range<usize>) -> Option<Cow<'_, str>> {
self.get(range).map(Cow::from)
}

Expand Down Expand Up @@ -177,7 +177,7 @@ impl EditableText for String {
}

impl EditableText for Arc<String> {
fn cursor(&self, position: usize) -> Option<StringCursor> {
fn cursor(&self, position: usize) -> Option<StringCursor<'_>> {
<String as EditableText>::cursor(self, position)
}
fn edit(&mut self, range: Range<usize>, new: impl Into<String>) {
Expand All @@ -186,7 +186,7 @@ impl EditableText for Arc<String> {
Arc::make_mut(self).edit(range, new)
}
}
fn slice(&self, range: Range<usize>) -> Option<Cow<str>> {
fn slice(&self, range: Range<usize>) -> Option<Cow<'_, str>> {
Some(Cow::Borrowed(&self[range]))
}
fn len(&self) -> usize {
Expand Down
2 changes: 1 addition & 1 deletion druid/src/text/input_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ impl<T: TextStorage + EditableText> InputHandler for EditSessionHandle<T> {
self.text.len()
}

fn slice(&self, range: Range<usize>) -> std::borrow::Cow<str> {
fn slice(&self, range: Range<usize>) -> std::borrow::Cow<'_, str> {
self.text.slice(range).unwrap()
}

Expand Down
Loading
Loading