mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 22:30:03 -04:00
Now we can drag any viewport but only the viewport that is focused will be draged because if not on x11 the input will be taken until the application is killed
This commit is contained in:
@@ -1043,6 +1043,7 @@ mod glow_integration {
|
|||||||
textures_delta,
|
textures_delta,
|
||||||
shapes,
|
shapes,
|
||||||
mut viewports,
|
mut viewports,
|
||||||
|
viewport_commands,
|
||||||
};
|
};
|
||||||
|
|
||||||
let control_flow;
|
let control_flow;
|
||||||
@@ -1077,6 +1078,7 @@ mod glow_integration {
|
|||||||
textures_delta,
|
textures_delta,
|
||||||
shapes,
|
shapes,
|
||||||
viewports,
|
viewports,
|
||||||
|
viewport_commands,
|
||||||
} = integration.update(
|
} = integration.update(
|
||||||
app.as_mut(),
|
app.as_mut(),
|
||||||
win.window.as_ref().unwrap(),
|
win.window.as_ref().unwrap(),
|
||||||
@@ -1235,6 +1237,27 @@ mod glow_integration {
|
|||||||
active_viewports_ids.push(id);
|
active_viewports_ids.push(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// TODO Make this more efficient
|
||||||
|
for (id, command) in viewport_commands {
|
||||||
|
for window in gl_window.windows.iter() {
|
||||||
|
if window.window_id == id {
|
||||||
|
if let Some(win) = &window.window {
|
||||||
|
match command {
|
||||||
|
egui::window::ViewportCommand::Drag => {
|
||||||
|
// if this is not checked on x11 the input will be permanently taken until the app is killed!
|
||||||
|
if let Some(focus) = self.is_focused {
|
||||||
|
if focus == id {
|
||||||
|
win.drag_window();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gl_window
|
gl_window
|
||||||
.windows
|
.windows
|
||||||
.retain(|w| active_viewports_ids.contains(&w.window_id));
|
.retain(|w| active_viewports_ids.contains(&w.window_id));
|
||||||
|
|||||||
@@ -143,6 +143,12 @@ impl ViewportBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
pub enum ViewportCommand {
|
||||||
|
Drag,
|
||||||
|
}
|
||||||
|
|
||||||
/// Builder for a floating window which can be dragged, closed, collapsed, resized and scrolled (off by default).
|
/// Builder for a floating window which can be dragged, closed, collapsed, resized and scrolled (off by default).
|
||||||
///
|
///
|
||||||
/// You can customize:
|
/// You can customize:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use std::sync::Arc;
|
|||||||
use crate::{
|
use crate::{
|
||||||
animation_manager::AnimationManager, data::output::PlatformOutput, frame_state::FrameState,
|
animation_manager::AnimationManager, data::output::PlatformOutput, frame_state::FrameState,
|
||||||
input_state::*, layers::GraphicLayers, memory::Options, os::OperatingSystem,
|
input_state::*, layers::GraphicLayers, memory::Options, os::OperatingSystem,
|
||||||
output::FullOutput, util::IdTypeMap, TextureHandle, *,
|
output::FullOutput, util::IdTypeMap, window::ViewportCommand, TextureHandle, *,
|
||||||
};
|
};
|
||||||
use ahash::HashMap;
|
use ahash::HashMap;
|
||||||
use epaint::{mutex::*, stats::*, text::Fonts, TessellationOptions, *};
|
use epaint::{mutex::*, stats::*, text::Fonts, TessellationOptions, *};
|
||||||
@@ -190,6 +190,8 @@ struct ContextImpl {
|
|||||||
Arc<Box<dyn Fn(&Context, u64, u64) + Sync + Send>>,
|
Arc<Box<dyn Fn(&Context, u64, u64) + Sync + Send>>,
|
||||||
),
|
),
|
||||||
>,
|
>,
|
||||||
|
viewport_commands: Vec<(u64, ViewportCommand)>,
|
||||||
|
|
||||||
viewport_counter: u64,
|
viewport_counter: u64,
|
||||||
current_rendering_viewport: u64,
|
current_rendering_viewport: u64,
|
||||||
is_desktop: bool,
|
is_desktop: bool,
|
||||||
@@ -1353,6 +1355,7 @@ impl Context {
|
|||||||
textures_delta,
|
textures_delta,
|
||||||
shapes,
|
shapes,
|
||||||
viewports,
|
viewports,
|
||||||
|
viewport_commands: self.write(|ctx| std::mem::take(&mut ctx.viewport_commands)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1975,6 +1978,10 @@ impl Context {
|
|||||||
self.write(|ctx| ctx.is_desktop = value)
|
self.write(|ctx| ctx.is_desktop = value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn viewport_command(&self, id: u64, command: ViewportCommand) {
|
||||||
|
self.write(|ctx| ctx.viewport_commands.push((id, command)))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn create_viewport(
|
pub fn create_viewport(
|
||||||
&self,
|
&self,
|
||||||
window_builder: ViewportBuilder,
|
window_builder: ViewportBuilder,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::window::ViewportCommand;
|
||||||
use crate::Context;
|
use crate::Context;
|
||||||
use crate::{window::ViewportBuilder, WidgetType};
|
use crate::{window::ViewportBuilder, WidgetType};
|
||||||
|
|
||||||
@@ -40,6 +41,8 @@ pub struct FullOutput {
|
|||||||
ViewportBuilder,
|
ViewportBuilder,
|
||||||
Arc<Box<dyn Fn(&Context, u64, u64) + Sync + Send>>,
|
Arc<Box<dyn Fn(&Context, u64, u64) + Sync + Send>>,
|
||||||
)>,
|
)>,
|
||||||
|
|
||||||
|
pub viewport_commands: Vec<(u64, ViewportCommand)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FullOutput {
|
impl FullOutput {
|
||||||
@@ -50,14 +53,16 @@ impl FullOutput {
|
|||||||
repaint_after,
|
repaint_after,
|
||||||
textures_delta,
|
textures_delta,
|
||||||
shapes,
|
shapes,
|
||||||
viewports: mut windows,
|
mut viewports,
|
||||||
|
mut viewport_commands,
|
||||||
} = newer;
|
} = newer;
|
||||||
|
|
||||||
self.platform_output.append(platform_output);
|
self.platform_output.append(platform_output);
|
||||||
self.repaint_after = repaint_after; // if the last frame doesn't need a repaint, then we don't need to repaint
|
self.repaint_after = repaint_after; // if the last frame doesn't need a repaint, then we don't need to repaint
|
||||||
self.textures_delta.append(textures_delta);
|
self.textures_delta.append(textures_delta);
|
||||||
self.shapes = shapes; // Only paint the latest
|
self.shapes = shapes; // Only paint the latest
|
||||||
self.viewports.append(&mut windows);
|
self.viewports.append(&mut viewports);
|
||||||
|
self.viewport_commands.append(&mut viewport_commands);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,15 +53,18 @@ fn main() -> Result<(), eframe::Error> {
|
|||||||
"Current rendering window: {}",
|
"Current rendering window: {}",
|
||||||
ctx.current_rendering_viewport()
|
ctx.current_rendering_viewport()
|
||||||
));
|
));
|
||||||
|
if ui.button("Drag").is_pointer_button_down_on() {
|
||||||
|
ctx.viewport_command(id, egui::window::ViewportCommand::Drag)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
let clone = window2_embedded.clone();
|
let clone = window2_embedded.clone();
|
||||||
let embedded = *window2_embedded.read().unwrap();
|
let embedded = *window2_embedded.read().unwrap();
|
||||||
egui::CollapsingHeader::new("Shout Test2").show(ui, |ui| {
|
egui::CollapsingHeader::new("Shout Test2").show(ui, |ui| {
|
||||||
egui::Window::new("Test2")
|
egui::Window::new("Test2").embedded(embedded).show(
|
||||||
.embedded(embedded)
|
ctx,
|
||||||
.show(ctx, move |ui, _, parent_id| {
|
move |ui, id, parent_id| {
|
||||||
if ui
|
if ui
|
||||||
.checkbox(&mut *clone.write().unwrap(), "Should embedd?")
|
.checkbox(&mut *clone.write().unwrap(), "Should embedd?")
|
||||||
.clicked()
|
.clicked()
|
||||||
@@ -73,7 +76,12 @@ fn main() -> Result<(), eframe::Error> {
|
|||||||
"Current rendering window: {}",
|
"Current rendering window: {}",
|
||||||
ctx.current_rendering_viewport()
|
ctx.current_rendering_viewport()
|
||||||
));
|
));
|
||||||
});
|
|
||||||
|
if ui.button("Drag").is_pointer_button_down_on() {
|
||||||
|
ctx.viewport_command(id, egui::window::ViewportCommand::Drag)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user