mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Added maximize_button, mimimize_button and hittest on ViewportBuilder
!!! hittest is not working because of winit !!!
This commit is contained in:
@@ -1029,7 +1029,9 @@ pub fn process_viewport_commands(
|
|||||||
}
|
}
|
||||||
ViewportCommand::CursorVisible(v) => win.set_cursor_visible(v),
|
ViewportCommand::CursorVisible(v) => win.set_cursor_visible(v),
|
||||||
ViewportCommand::CursorHitTest(v) => {
|
ViewportCommand::CursorHitTest(v) => {
|
||||||
win.set_cursor_hittest(v);
|
if let Err(err) = win.set_cursor_hittest(v) {
|
||||||
|
log::error!("Setting viewport CursorHitTest: {err}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1054,6 +1056,8 @@ pub fn create_winit_window_builder(builder: &ViewportBuilder) -> winit::window::
|
|||||||
.with_decorations(builder.decorations.map_or(false, |e| e))
|
.with_decorations(builder.decorations.map_or(false, |e| e))
|
||||||
.with_resizable(builder.resizable.map_or(false, |e| e))
|
.with_resizable(builder.resizable.map_or(false, |e| e))
|
||||||
.with_visible(builder.visible.map_or(false, |e| e))
|
.with_visible(builder.visible.map_or(false, |e| e))
|
||||||
|
.with_maximized(builder.minimized.map_or(false, |e| e))
|
||||||
|
.with_maximized(builder.maximized.map_or(false, |e| e))
|
||||||
.with_fullscreen(
|
.with_fullscreen(
|
||||||
builder
|
builder
|
||||||
.fullscreen
|
.fullscreen
|
||||||
@@ -1061,8 +1065,16 @@ pub fn create_winit_window_builder(builder: &ViewportBuilder) -> winit::window::
|
|||||||
.flatten(),
|
.flatten(),
|
||||||
)
|
)
|
||||||
.with_enabled_buttons(
|
.with_enabled_buttons(
|
||||||
WindowButtons::MAXIMIZE
|
builder
|
||||||
| WindowButtons::MINIMIZE
|
.minimize_button
|
||||||
|
.map(|v| v.then(|| WindowButtons::MINIMIZE))
|
||||||
|
.flatten()
|
||||||
|
.unwrap_or(WindowButtons::empty())
|
||||||
|
| builder
|
||||||
|
.maximize_button
|
||||||
|
.map(|v| v.then(|| WindowButtons::MAXIMIZE))
|
||||||
|
.flatten()
|
||||||
|
.unwrap_or(WindowButtons::empty())
|
||||||
| builder
|
| builder
|
||||||
.close_button
|
.close_button
|
||||||
.map(|v| v.then(|| WindowButtons::CLOSE))
|
.map(|v| v.then(|| WindowButtons::CLOSE))
|
||||||
@@ -1098,6 +1110,9 @@ pub fn create_winit_window_builder(builder: &ViewportBuilder) -> winit::window::
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: implement `ViewportBuilder::hittest`
|
||||||
|
// Is not implemented because winit in his current state will not allow to set cursor_hittest on a `WindowBuilder`
|
||||||
|
|
||||||
window_builder
|
window_builder
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1211,6 +1226,13 @@ pub fn changes_between_builders(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(hittest) = new.hittest {
|
||||||
|
if Some(hittest) != last.hittest {
|
||||||
|
last.hittest = Some(hittest);
|
||||||
|
commands.push(ViewportCommand::CursorHitTest(hittest));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Implement compare for windows buttons
|
// TODO: Implement compare for windows buttons
|
||||||
|
|
||||||
let mut recreate_window = false;
|
let mut recreate_window = false;
|
||||||
@@ -1229,6 +1251,20 @@ pub fn changes_between_builders(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(minimize_button) = new.minimize_button {
|
||||||
|
if Some(minimize_button) != last.minimize_button {
|
||||||
|
last.minimize_button = Some(minimize_button);
|
||||||
|
recreate_window = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(maximized_button) = new.maximize_button {
|
||||||
|
if Some(maximized_button) != last.maximize_button {
|
||||||
|
last.maximize_button = Some(maximized_button);
|
||||||
|
recreate_window = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(title_hidden) = new.title_hidden {
|
if let Some(title_hidden) = new.title_hidden {
|
||||||
if Some(title_hidden) != last.title_hidden {
|
if Some(title_hidden) != last.title_hidden {
|
||||||
last.title_hidden = Some(title_hidden);
|
last.title_hidden = Some(title_hidden);
|
||||||
|
|||||||
@@ -257,9 +257,19 @@ fn show_tooltip_area_dyn<'c, R>(
|
|||||||
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
use containers::*;
|
use containers::*;
|
||||||
|
// TODO: Get window pos from winit
|
||||||
|
let parent_window_pos = (0, 0);
|
||||||
|
// TODO: Need some how to calculate the ui size before rendering!
|
||||||
ctx.create_viewport_sync(
|
ctx.create_viewport_sync(
|
||||||
ViewportBuilder::default().with_title(format!("Popup Window: {area_id:?}")),
|
ViewportBuilder::default()
|
||||||
|
.with_position(Some((
|
||||||
|
window_pos.x as i32 + parent_window_pos.0,
|
||||||
|
window_pos.y as i32 + parent_window_pos.1,
|
||||||
|
)))
|
||||||
|
.with_decorations(false)
|
||||||
|
.with_title(format!("Popup Window: {area_id:?}")),
|
||||||
|ctx| {
|
|ctx| {
|
||||||
|
ctx.viewport_command(ctx.get_viewport_id(), ViewportCommand::CursorHitTest(false));
|
||||||
Area::new(area_id)
|
Area::new(area_id)
|
||||||
.order(Order::Tooltip)
|
.order(Order::Tooltip)
|
||||||
.fixed_pos(window_pos)
|
.fixed_pos(window_pos)
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ pub struct ViewportBuilder {
|
|||||||
pub drag_and_drop: Option<bool>,
|
pub drag_and_drop: Option<bool>,
|
||||||
|
|
||||||
pub close_button: Option<bool>,
|
pub close_button: Option<bool>,
|
||||||
|
pub minimize_button: Option<bool>,
|
||||||
|
pub maximize_button: Option<bool>,
|
||||||
|
|
||||||
|
pub hittest: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ViewportBuilder {
|
impl Default for ViewportBuilder {
|
||||||
@@ -72,6 +76,9 @@ impl Default for ViewportBuilder {
|
|||||||
drag_and_drop: None,
|
drag_and_drop: None,
|
||||||
close_button: None,
|
close_button: None,
|
||||||
minimized: Some(false),
|
minimized: Some(false),
|
||||||
|
minimize_button: Some(true),
|
||||||
|
maximize_button: Some(true),
|
||||||
|
hittest: Some(true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,6 +106,9 @@ impl ViewportBuilder {
|
|||||||
drag_and_drop: None,
|
drag_and_drop: None,
|
||||||
close_button: None,
|
close_button: None,
|
||||||
minimized: None,
|
minimized: None,
|
||||||
|
minimize_button: None,
|
||||||
|
maximize_button: None,
|
||||||
|
hittest: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn with_title(mut self, title: impl Into<String>) -> Self {
|
pub fn with_title(mut self, title: impl Into<String>) -> Self {
|
||||||
@@ -187,6 +197,16 @@ impl ViewportBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_minimize_button(mut self, value: bool) -> Self {
|
||||||
|
self.minimize_button = Some(value);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_maximize_button(mut self, value: bool) -> Self {
|
||||||
|
self.maximize_button = Some(value);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_drag_and_drop(mut self, value: bool) -> Self {
|
pub fn with_drag_and_drop(mut self, value: bool) -> Self {
|
||||||
self.drag_and_drop = Some(value);
|
self.drag_and_drop = Some(value);
|
||||||
self
|
self
|
||||||
@@ -196,8 +216,16 @@ impl ViewportBuilder {
|
|||||||
self.position = Some(value);
|
self.position = Some(value);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Is not implemented for winit
|
||||||
|
/// You should use `ViewportCommand::CursorHitTest` if you want to set this!
|
||||||
|
pub fn with_hittest(mut self, value: bool) -> Self {
|
||||||
|
self.hittest = Some(value);
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// You can send a `ViewportCommand` to the viewport with `Context::viewport_command`
|
||||||
#[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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user