Skip to content

Commit

Permalink
Improve docs for ViewportCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 7, 2023
1 parent 85c8708 commit d4fab25
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
7 changes: 6 additions & 1 deletion crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 16 additions & 5 deletions crates/egui/src/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -593,8 +595,17 @@ pub enum ViewportCommand {
/// Should be bigger then 0
ResizeIncrements(Option<Vec2>),

/// 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,
Expand All @@ -618,7 +629,7 @@ pub enum ViewportCommand {
/// 0 = Informational, 1 = Critical
RequestUserAttention(Option<u8>),

/// 0 = Light, 1 = Dark
/// 0 = Light, 1 = Dark, `None` = system default.
SetTheme(Option<u8>),

ContentProtected(bool),
Expand Down

0 comments on commit d4fab25

Please sign in to comment.