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
18 changes: 9 additions & 9 deletions druid-shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ serde = ["kurbo/serde"]
[dependencies]
# NOTE: When changing the piet or kurbo versions, ensure that
# the kurbo version included in piet is compatible with the kurbo version specified here.
piet-common = "=0.5.0"
kurbo = "0.8.2"
piet-common = "=0.6.0"
kurbo = "0.9"

tracing = "0.1.22"
once_cell = "1.14.0"
Expand Down Expand Up @@ -100,14 +100,14 @@ bitflags = "1.2.1"
[target.'cfg(any(target_os = "freebsd", target_os="linux", target_os="openbsd"))'.dependencies]
ashpd = { version = "0.3.0", optional = true }
# TODO(x11/dependencies): only use feature "xcb" if using X11
cairo-rs = { version = "0.14.0", default_features = false, features = ["xcb"] }
cairo-sys-rs = { version = "0.14.0", default_features = false, optional = true }
cairo-rs = { version = "0.16.3", default_features = false, features = ["xcb"] }
cairo-sys-rs = { version = "0.16.3", default_features = false, optional = true }
futures = { version = "0.3.21", optional = true, features = ["executor"]}
gdk-sys = { version = "0.14.0", optional = true }
gdk-sys = { version = "0.16.0", optional = true }
# `gtk` gets renamed to `gtk-rs` so that we can use `gtk` as the feature name.
gtk-rs = { version = "0.14.0", features = ["v3_22"], package = "gtk", optional = true }
glib-sys = { version = "0.14.0", optional = true }
gtk-sys = { version = "0.14.0", optional = true }
gtk-rs = { version = "0.16.1", package = "gtk", optional = true }
glib-sys = { version = "0.16.3", optional = true }
gtk-sys = { version = "0.16.0", optional = true }
nix = { version = "0.24.0", optional = true }
x11rb = { version = "0.10", features = ["allow-unsafe-code", "present", "render", "randr", "xfixes", "xkb", "resource_manager", "cursor"], optional = true }
wayland-client = { version = "0.29", optional = true }
Expand All @@ -127,7 +127,7 @@ version = "0.3.44"
features = ["Window", "MouseEvent", "CssStyleDeclaration", "WheelEvent", "KeyEvent", "KeyboardEvent", "Navigator"]

[dev-dependencies]
piet-common = { version = "=0.5.0", features = ["png"] }
piet-common = { version = "=0.6.0", features = ["png"] }
static_assertions = "1.1.0"
test-log = { version = "0.2.5", features = ["trace"], default-features = false }
tracing-subscriber = { version = "0.3.2", features = ["env-filter"] }
Expand Down
3 changes: 1 addition & 2 deletions druid-shell/src/backend/gtk/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ impl Clipboard {
let targets = clipboard.wait_for_targets().unwrap_or_default();
targets
.iter()
// SAFETY: Atom::value() is 'self.0 as usize'. No idea why that is unsafe.
.map(|atom| format!("{} ({})", atom.name(), unsafe { atom.value() }))
.map(|atom| format!("{} ({})", atom.name(), atom.value()))
.collect()
}
}
Expand Down
2 changes: 1 addition & 1 deletion druid-shell/src/backend/gtk/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub(crate) fn get_file_dialog_path(
};
let title = options.title.as_deref().unwrap_or(title);

let mut dialog = gtk::FileChooserNativeBuilder::new()
let mut dialog = gtk::FileChooserNative::builder()
.transient_for(window)
.title(title);
if let Some(button_text) = &options.button_text {
Expand Down
4 changes: 2 additions & 2 deletions druid-shell/src/backend/gtk/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use gtk::gdk::ModifierType;
use gtk::{
AccelGroup, CheckMenuItem, Menu as GtkMenu, MenuBar as GtkMenuBar, MenuItem as GtkMenuItem,
};
use gtk_rs::SeparatorMenuItemBuilder;
use gtk_rs::SeparatorMenuItem;

use gtk::prelude::{GtkMenuExt, GtkMenuItemExt, MenuShellExt, WidgetExt};

Expand Down Expand Up @@ -114,7 +114,7 @@ impl Menu {

menu.append(&item);
}
MenuItem::Separator => menu.append(&SeparatorMenuItemBuilder::new().build()),
MenuItem::Separator => menu.append(&SeparatorMenuItem::new()),
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions druid-shell/src/backend/gtk/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use kurbo::{Point, Rect, Size};

fn translate_gdk_rectangle(r: Rectangle) -> Rect {
Rect::from_origin_size(
Point::new(r.x as f64, r.y as f64),
Size::new(r.width as f64, r.height as f64),
Point::new(r.x() as f64, r.y() as f64),
Size::new(r.width() as f64, r.height() as f64),
)
}

Expand All @@ -30,9 +30,7 @@ fn translate_gdk_monitor(mon: gtk::gdk::Monitor) -> Monitor {
Monitor::new(
mon.is_primary(),
area,
mon.get_property_workarea()
.map(translate_gdk_rectangle)
.unwrap_or(area),
translate_gdk_rectangle(mon.workarea()),
)
}

Expand Down
22 changes: 11 additions & 11 deletions druid-shell/src/backend/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl WindowBuilder {
window.set_decorated(self.show_titlebar);
let mut transparent = false;
if self.transparent {
if let Some(screen) = window.screen() {
if let Some(screen) = gtk::prelude::GtkWindowExt::screen(&window) {
let visual = screen.rgba_visual();
transparent = visual.is_some();
window.set_visual(visual.as_ref());
Expand Down Expand Up @@ -475,13 +475,13 @@ impl WindowBuilder {
// Create a new cairo surface if necessary (either because there is no surface, or
// because the size or scale changed).
let extents = widget.allocation();
let size_px = Size::new(extents.width as f64, extents.height as f64);
let size_px = Size::new(extents.width() as f64, extents.height() as f64);
let no_surface = state.surface.try_borrow().map(|x| x.is_none()).ok() == Some(true);
if no_surface || scale_changed || state.area.get().size_px() != size_px {
let area = ScaledArea::from_px(size_px, scale);
let size_dp = area.size_dp();
state.area.set(area);
if let Err(e) = state.resize_surface(extents.width, extents.height) {
if let Err(e) = state.resize_surface(extents.width(), extents.height()) {
error!("Failed to resize surface: {}", e);
}
state.with_handler(|h| h.size(size_dp));
Expand Down Expand Up @@ -526,7 +526,7 @@ impl WindowBuilder {
// TODO: how are we supposed to handle these errors? What can we do besides panic? Probably nothing right?
let alloc = widget.allocation();
context.set_source_surface(surface, 0.0, 0.0).unwrap();
context.rectangle(0.0, 0.0, alloc.width as f64, alloc.height as f64);
context.rectangle(0.0, 0.0, alloc.width() as f64, alloc.height() as f64);
context.fill().unwrap();
});
} else {
Expand Down Expand Up @@ -1025,24 +1025,24 @@ impl WindowHandle {
let scale = state.scale.get();
let (width_px, height_px) = state.window.size();
let alloc_px = state.drawing_area.allocation();
let menu_height_px = height_px - alloc_px.height;
let menu_height_px = height_px - alloc_px.height();

if let Some(window) = state.window.window() {
let frame = window.frame_extents();
let (pos_x, pos_y) = window.position();
Insets::new(
(pos_x - frame.x) as f64,
(pos_y - frame.y + menu_height_px) as f64,
(frame.x + frame.width - (pos_x + width_px)) as f64,
(frame.y + frame.height - (pos_y + height_px)) as f64,
(pos_x - frame.x()) as f64,
(pos_y - frame.y() + menu_height_px) as f64,
(frame.x() + frame.width() - (pos_x + width_px)) as f64,
(frame.y() + frame.height() - (pos_y + height_px)) as f64,
)
.to_dp(scale)
.nonnegative()
} else {
let window = Size::new(width_px as f64, height_px as f64).to_dp(scale);
let alloc = Rect::from_origin_size(
(alloc_px.x as f64, alloc_px.y as f64),
(alloc_px.width as f64, alloc_px.height as f64),
(alloc_px.x() as f64, alloc_px.y() as f64),
(alloc_px.width() as f64, alloc_px.height() as f64),
)
.to_dp(scale);
window.to_rect() - alloc
Expand Down
8 changes: 4 additions & 4 deletions druid-shell/src/backend/mac/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ fn mouse_event(
unsafe {
let point = nsevent.locationInWindow();
let view_point = view.convertPoint_fromView_(point, nil);
let pos = Point::new(view_point.x as f64, view_point.y as f64);
let pos = Point::new(view_point.x, view_point.y);
let buttons = get_mouse_buttons(NSEvent::pressedMouseButtons(nsevent));
let modifiers = make_modifiers(nsevent.modifierFlags());
MouseEvent {
Expand Down Expand Up @@ -776,8 +776,8 @@ extern "C" fn scroll_wheel(this: &mut Object, _: Sel, nsevent: id) {
let view_state: *mut c_void = *this.get_ivar("viewState");
let view_state = &mut *(view_state as *mut ViewState);
let (dx, dy) = {
let dx = -nsevent.scrollingDeltaX() as f64;
let dy = -nsevent.scrollingDeltaY() as f64;
let dx = -nsevent.scrollingDeltaX();
let dy = -nsevent.scrollingDeltaY();
if nsevent.hasPreciseScrollingDeltas() == cocoa::base::YES {
(dx, dy)
} else {
Expand All @@ -803,7 +803,7 @@ extern "C" fn pinch_event(this: &mut Object, _: Sel, nsevent: id) {
let view_state = &mut *(view_state as *mut ViewState);

let delta: CGFloat = msg_send![nsevent, magnification];
view_state.handler.zoom(delta as f64);
view_state.handler.zoom(delta);
}
}

Expand Down
2 changes: 1 addition & 1 deletion druid-shell/src/backend/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ impl Window {
let invalid = std::mem::replace(&mut *borrow_mut!(self.invalid)?, Region::EMPTY);
{
let surface = borrow!(self.cairo_surface)?;
let cairo_ctx = cairo::Context::new(&surface).unwrap();
let cairo_ctx = cairo::Context::new(&*surface).unwrap();
let scale = self.scale.get();
for rect in invalid.rects() {
let rect = rect.to_px(scale).round();
Expand Down
2 changes: 1 addition & 1 deletion druid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ console_error_panic_hook = { version = "0.1.6" }
float-cmp = { version = "0.8.0", features = ["std"], default-features = false }
# tempfile 3.2.0 broke wasm; I assume it will be yanked (Jan 12, 2021)
tempfile = "=3.1.0"
piet-common = { version = "=0.5.0", features = ["png"] }
piet-common = { version = "=0.6.0", features = ["png"] }
pulldown-cmark = { version = "0.8", default-features = false }
test-log = { version = "0.2.5", features = ["trace"], default-features = false }
# test-env-log needs it
Expand Down
3 changes: 1 addition & 2 deletions druid/examples/async_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ fn generate_colors(event_sink: druid::ExtEventSink) {
(_, _) => Color::rgb8(r, g, b.wrapping_add(3)),
};

let color_clone = color.clone();
// schedule idle callback to change the data
event_sink.add_idle_callback(move |data: &mut Color| {
*data = color_clone;
*data = color;
});
thread::sleep(Duration::from_millis(20));
}
Expand Down
2 changes: 1 addition & 1 deletion druid/examples/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<T: Data> Widget<T> for OverPainter {
let color = env.get_debug_color(self.0);
let radius = (rect + INSETS).size().height / 2.0;
let circle = Circle::new(rect.center(), radius);
let grad = RadialGradient::new(1.0, (color.clone(), color.clone().with_alpha(0.0)));
let grad = RadialGradient::new(1.0, (color, color.with_alpha(0.0)));
ctx.fill(circle, &grad);
ctx.stroke(rect, &color, 2.0);
}
Expand Down
2 changes: 1 addition & 1 deletion druid/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl Env {
#[doc(hidden)]
pub fn get_debug_color(&self, id: u64) -> Color {
let color_num = id as usize % DEBUG_COLOR.len();
DEBUG_COLOR[color_num].clone()
DEBUG_COLOR[color_num]
}
}

Expand Down
2 changes: 1 addition & 1 deletion druid/src/widget/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ impl<T, W: Widget<T>> Annotated<T, W> {
while walk < self.mapping.max + f64::EPSILON * 10.0 {
let layout = text
.new_text_layout(format!("{}", walk))
.text_color(text_color.clone())
.text_color(text_color)
.build()
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion druid/src/widget/spinner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<T: Data> Widget<T> for Spinner {
let t = self.t;
let (width, height) = (ctx.size().width, ctx.size().height);
let center = Point::new(width / 2.0, height / 2.0);
let (r, g, b, original_alpha) = Color::as_rgba(&self.color.resolve(env));
let (r, g, b, original_alpha) = Color::as_rgba(self.color.resolve(env));
let scale_factor = width.min(height) / 40.0;

for step in 1..=12 {
Expand Down