From d4fab25fc8efd306c331817e71d22b45d99a6f40 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 7 Nov 2023 11:34:35 +0100 Subject: [PATCH] Improve docs for `ViewportCommand` --- crates/egui-winit/src/lib.rs | 7 ++++++- crates/egui/src/viewport.rs | 21 ++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index e76092ce4d9..3cac2b83dbc 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -994,7 +994,12 @@ pub fn process_viewport_commands( let height = size.y.max(1.0); window.set_inner_size(LogicalSize::new(width, height)); } - egui::ViewportCommand::Resize(top, bottom, right, left) => { + egui::ViewportCommand::BeginResize { + top, + bottom, + right, + left, + } => { // TODO posibile return the error to `egui::Context` let _ = window.drag_resize_window(match (top, bottom, right, left) { (true, false, false, false) => ResizeDirection::North, diff --git a/crates/egui/src/viewport.rs b/crates/egui/src/viewport.rs index 47060b230cd..6ede603add1 100644 --- a/crates/egui/src/viewport.rs +++ b/crates/egui/src/viewport.rs @@ -569,7 +569,9 @@ impl ViewportBuilder { } } -/// You can send a `ViewportCommand` to the viewport with `Context::viewport_command` +/// You can send a [`ViewportCommand`] to the viewport with [`Context::viewport_command`]. +/// +/// All coordinates are in logical points. #[derive(Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub enum ViewportCommand { @@ -578,7 +580,7 @@ pub enum ViewportCommand { Visible(bool), Drag, - /// Will probably not work as expected! + /// Set the outer position of the viewport, i.e. moves the window. OuterPosition(Pos2), /// Should be bigger then 0 @@ -593,8 +595,17 @@ pub enum ViewportCommand { /// Should be bigger then 0 ResizeIncrements(Option), - /// Top, Bottom, Right, Left - Resize(bool, bool, bool, bool), + /// Begin resizing the viewport with the left mouse button until the button is released. + /// + /// There's no guarantee that this will work unless the left mouse button was pressed + /// immediately before this function is called. + BeginResize { + top: bool, + bottom: bool, + right: bool, + left: bool, + }, + Resizable(bool), EnableButtons { close: bool, @@ -618,7 +629,7 @@ pub enum ViewportCommand { /// 0 = Informational, 1 = Critical RequestUserAttention(Option), - /// 0 = Light, 1 = Dark + /// 0 = Light, 1 = Dark, `None` = system default. SetTheme(Option), ContentProtected(bool),