mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
Clean up ViewportCommands
This commit is contained in:
@@ -997,7 +997,7 @@ pub fn process_viewport_commands(
|
|||||||
|
|
||||||
for command in commands {
|
for command in commands {
|
||||||
match command {
|
match command {
|
||||||
egui::ViewportCommand::Drag => {
|
egui::ViewportCommand::StartDrag => {
|
||||||
// if this is not checked on x11 the input will be permanently taken until the app is killed!
|
// if this is not checked on x11 the input will be permanently taken until the app is killed!
|
||||||
if is_viewport_focused {
|
if is_viewport_focused {
|
||||||
// TODO possible return the error to `egui::Context`
|
// TODO possible return the error to `egui::Context`
|
||||||
@@ -1068,10 +1068,10 @@ pub fn process_viewport_commands(
|
|||||||
window.set_fullscreen(v.then_some(winit::window::Fullscreen::Borderless(None)));
|
window.set_fullscreen(v.then_some(winit::window::Fullscreen::Borderless(None)));
|
||||||
}
|
}
|
||||||
ViewportCommand::Decorations(v) => window.set_decorations(v),
|
ViewportCommand::Decorations(v) => window.set_decorations(v),
|
||||||
ViewportCommand::WindowLevel(o) => window.set_window_level(match o {
|
ViewportCommand::WindowLevel(l) => window.set_window_level(match l {
|
||||||
1 => WindowLevel::AlwaysOnBottom,
|
egui::viewport::WindowLevel::AlwaysOnBottom => WindowLevel::AlwaysOnBottom,
|
||||||
2 => WindowLevel::AlwaysOnTop,
|
egui::viewport::WindowLevel::AlwaysOnTop => WindowLevel::AlwaysOnTop,
|
||||||
_ => WindowLevel::Normal,
|
egui::viewport::WindowLevel::Normal => WindowLevel::Normal,
|
||||||
}),
|
}),
|
||||||
ViewportCommand::WindowIcon(icon) => {
|
ViewportCommand::WindowIcon(icon) => {
|
||||||
window.set_window_icon(icon.map(|icon| {
|
window.set_window_icon(icon.map(|icon| {
|
||||||
@@ -1087,25 +1087,26 @@ pub fn process_viewport_commands(
|
|||||||
window.set_ime_position(LogicalPosition::new(pos.x, pos.y));
|
window.set_ime_position(LogicalPosition::new(pos.x, pos.y));
|
||||||
}
|
}
|
||||||
ViewportCommand::IMEAllowed(v) => window.set_ime_allowed(v),
|
ViewportCommand::IMEAllowed(v) => window.set_ime_allowed(v),
|
||||||
ViewportCommand::IMEPurpose(o) => window.set_ime_purpose(match o {
|
ViewportCommand::IMEPurpose(p) => window.set_ime_purpose(match p {
|
||||||
1 => winit::window::ImePurpose::Password,
|
egui::viewport::IMEPurpose::Password => winit::window::ImePurpose::Password,
|
||||||
2 => winit::window::ImePurpose::Terminal,
|
egui::viewport::IMEPurpose::Terminal => winit::window::ImePurpose::Terminal,
|
||||||
_ => winit::window::ImePurpose::Normal,
|
egui::viewport::IMEPurpose::Normal => winit::window::ImePurpose::Normal,
|
||||||
|
}),
|
||||||
|
ViewportCommand::RequestUserAttention(a) => {
|
||||||
|
window.request_user_attention(a.map(|a| match a {
|
||||||
|
egui::viewport::UserAttentionType::Critical => {
|
||||||
|
winit::window::UserAttentionType::Critical
|
||||||
|
}
|
||||||
|
egui::viewport::UserAttentionType::Informational => {
|
||||||
|
winit::window::UserAttentionType::Informational
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
ViewportCommand::SetTheme(t) => window.set_theme(match t {
|
||||||
|
egui::SystemTheme::Light => Some(winit::window::Theme::Light),
|
||||||
|
egui::SystemTheme::Dark => Some(winit::window::Theme::Dark),
|
||||||
|
egui::SystemTheme::SystemDefault => None,
|
||||||
}),
|
}),
|
||||||
ViewportCommand::RequestUserAttention(o) => window.request_user_attention(o.map(|o| {
|
|
||||||
if o == 1 {
|
|
||||||
winit::window::UserAttentionType::Critical
|
|
||||||
} else {
|
|
||||||
winit::window::UserAttentionType::Informational
|
|
||||||
}
|
|
||||||
})),
|
|
||||||
ViewportCommand::SetTheme(o) => window.set_theme(o.map(|o| {
|
|
||||||
if o == 1 {
|
|
||||||
winit::window::Theme::Dark
|
|
||||||
} else {
|
|
||||||
winit::window::Theme::Light
|
|
||||||
}
|
|
||||||
})),
|
|
||||||
ViewportCommand::ContentProtected(v) => window.set_content_protected(v),
|
ViewportCommand::ContentProtected(v) => window.set_content_protected(v),
|
||||||
ViewportCommand::CursorPosition(pos) => {
|
ViewportCommand::CursorPosition(pos) => {
|
||||||
if let Err(err) = window.set_cursor_position(LogicalPosition::new(pos.x, pos.y)) {
|
if let Err(err) = window.set_cursor_position(LogicalPosition::new(pos.x, pos.y)) {
|
||||||
@@ -1114,9 +1115,9 @@ pub fn process_viewport_commands(
|
|||||||
}
|
}
|
||||||
ViewportCommand::CursorGrab(o) => {
|
ViewportCommand::CursorGrab(o) => {
|
||||||
if let Err(err) = window.set_cursor_grab(match o {
|
if let Err(err) = window.set_cursor_grab(match o {
|
||||||
1 => CursorGrabMode::Confined,
|
egui::viewport::CursorGrab::None => CursorGrabMode::None,
|
||||||
2 => CursorGrabMode::Locked,
|
egui::viewport::CursorGrab::Confined => CursorGrabMode::Confined,
|
||||||
_ => CursorGrabMode::None,
|
egui::viewport::CursorGrab::Locked => CursorGrabMode::Locked,
|
||||||
}) {
|
}) {
|
||||||
log::error!("{err}");
|
log::error!("{err}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -573,16 +573,65 @@ impl ViewportBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
pub enum WindowLevel {
|
||||||
|
Normal,
|
||||||
|
AlwaysOnBottom,
|
||||||
|
AlwaysOnTop,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
pub enum IMEPurpose {
|
||||||
|
Normal,
|
||||||
|
Password,
|
||||||
|
Terminal,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
pub enum SystemTheme {
|
||||||
|
Light,
|
||||||
|
Dark,
|
||||||
|
SystemDefault,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
pub enum CursorGrab {
|
||||||
|
None,
|
||||||
|
Confined,
|
||||||
|
Locked,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
pub enum UserAttentionType {
|
||||||
|
Informational,
|
||||||
|
Critical,
|
||||||
|
}
|
||||||
|
|
||||||
/// 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.
|
/// All coordinates are in logical points.
|
||||||
#[derive(Clone, PartialEq, Eq)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
pub enum ViewportCommand {
|
pub enum ViewportCommand {
|
||||||
|
/// Set the title
|
||||||
Title(String),
|
Title(String),
|
||||||
|
|
||||||
|
/// Turn the window transparent or not.
|
||||||
Transparent(bool),
|
Transparent(bool),
|
||||||
|
|
||||||
|
/// Set the visibility of the window.
|
||||||
Visible(bool),
|
Visible(bool),
|
||||||
Drag,
|
|
||||||
|
/// Moves the window 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.
|
||||||
|
StartDrag,
|
||||||
|
|
||||||
/// Set the outer position of the viewport, i.e. moves the window.
|
/// Set the outer position of the viewport, i.e. moves the window.
|
||||||
OuterPosition(Pos2),
|
OuterPosition(Pos2),
|
||||||
@@ -610,7 +659,10 @@ pub enum ViewportCommand {
|
|||||||
left: bool,
|
left: bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Can the window be resized?
|
||||||
Resizable(bool),
|
Resizable(bool),
|
||||||
|
|
||||||
|
/// Set which window buttons are enabled
|
||||||
EnableButtons {
|
EnableButtons {
|
||||||
close: bool,
|
close: bool,
|
||||||
minimized: bool,
|
minimized: bool,
|
||||||
@@ -619,30 +671,28 @@ pub enum ViewportCommand {
|
|||||||
Minimized(bool),
|
Minimized(bool),
|
||||||
Maximized(bool),
|
Maximized(bool),
|
||||||
Fullscreen(bool),
|
Fullscreen(bool),
|
||||||
|
|
||||||
|
/// Show window decorations, i.e. the chrome around the content
|
||||||
|
/// with the title bar, close buttons, resize handles, etc.
|
||||||
Decorations(bool),
|
Decorations(bool),
|
||||||
|
|
||||||
/// 0 = Normal, 1 = AlwaysOnBottom, 2 = AlwaysOnTop
|
WindowLevel(WindowLevel),
|
||||||
WindowLevel(u8),
|
|
||||||
WindowIcon(Option<ColorImage>),
|
WindowIcon(Option<ColorImage>),
|
||||||
|
|
||||||
IMEPosition(Pos2),
|
IMEPosition(Pos2),
|
||||||
IMEAllowed(bool),
|
IMEAllowed(bool),
|
||||||
|
IMEPurpose(IMEPurpose),
|
||||||
|
|
||||||
/// 0 = Normal, 1 = Password, 2 = Terminal
|
RequestUserAttention(Option<UserAttentionType>),
|
||||||
IMEPurpose(u8),
|
|
||||||
|
|
||||||
/// 0 = Informational, 1 = Critical
|
SetTheme(SystemTheme),
|
||||||
RequestUserAttention(Option<u8>),
|
|
||||||
|
|
||||||
/// 0 = Light, 1 = Dark, `None` = system default.
|
|
||||||
SetTheme(Option<u8>),
|
|
||||||
|
|
||||||
ContentProtected(bool),
|
ContentProtected(bool),
|
||||||
|
|
||||||
/// Will probably not work as expected!
|
/// Will probably not work as expected!
|
||||||
CursorPosition(Pos2),
|
CursorPosition(Pos2),
|
||||||
|
|
||||||
/// 0 = None, 1 = Confined, 2 = Locked
|
CursorGrab(CursorGrab),
|
||||||
CursorGrab(u8),
|
|
||||||
|
|
||||||
CursorVisible(bool),
|
CursorVisible(bool),
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user