mirror of https://github.com/wayvr-org/wayvr.git
wgui: make context menus unfold from the bottom if the mouse position is at the lower half of the screen
This commit is contained in:
parent
d4a64d6490
commit
0962f4c015
|
|
@ -1,7 +1,7 @@
|
||||||
<layout>
|
<layout>
|
||||||
<!-- text: str -->
|
<!-- text: str -->
|
||||||
<template name="Cell">
|
<template name="Cell">
|
||||||
<Button id="button" text="${text}" tooltip_str="${tooltip_str}" weight="bold" border="0" padding="4" color="#FFFFFF00" />
|
<Button id="button" text="${text}" tooltip_str="${tooltip_str}" weight="bold" border="0" padding="4" color="#FFFFFF00" height="24" justify_content="start" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template name="Separator">
|
<template name="Separator">
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use crate::{
|
||||||
layout::Layout,
|
layout::Layout,
|
||||||
parser::{self, Fetchable, ParserState},
|
parser::{self, Fetchable, ParserState},
|
||||||
task::Tasks,
|
task::Tasks,
|
||||||
windowing::window::{WguiWindow, WguiWindowParams, WguiWindowParamsExtra},
|
windowing::window::{WguiWindow, WguiWindowParams, WguiWindowParamsExtra, WguiWindowPlacement},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
@ -77,7 +77,7 @@ impl ContextMenu {
|
||||||
self.window.close();
|
self.window.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_process(
|
fn process_open(
|
||||||
&mut self,
|
&mut self,
|
||||||
params: OpenParams,
|
params: OpenParams,
|
||||||
layout: &mut Layout,
|
layout: &mut Layout,
|
||||||
|
|
@ -91,14 +91,27 @@ impl ContextMenu {
|
||||||
Blueprint::Cells(cells) => cells,
|
Blueprint::Cells(cells) => cells,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let root_size = layout.state.get_widget_size(layout.content_root_widget);
|
||||||
|
|
||||||
|
let (window_pos, placement) = if params.position.y < root_size.y / 2.0 {
|
||||||
|
(params.position, WguiWindowPlacement::TopLeft)
|
||||||
|
} else {
|
||||||
|
// invert y axis (position.y is counted from the bottom)
|
||||||
|
(
|
||||||
|
Vec2::new(params.position.x, root_size.y - params.position.y),
|
||||||
|
WguiWindowPlacement::BottomLeft,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
let globals = layout.state.globals.clone();
|
let globals = layout.state.globals.clone();
|
||||||
|
|
||||||
self.window.open(&mut WguiWindowParams {
|
self.window.open(&mut WguiWindowParams {
|
||||||
layout,
|
layout,
|
||||||
position: params.position,
|
position: window_pos,
|
||||||
extra: WguiWindowParamsExtra {
|
extra: WguiWindowParamsExtra {
|
||||||
with_decorations: false,
|
with_decorations: false,
|
||||||
close_if_clicked_outside: true,
|
close_if_clicked_outside: true,
|
||||||
|
placement,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
})?;
|
})?;
|
||||||
|
|
@ -144,7 +157,7 @@ impl ContextMenu {
|
||||||
|
|
||||||
pub fn tick(&mut self, layout: &mut Layout, parser_state: &mut ParserState) -> anyhow::Result<TickResult> {
|
pub fn tick(&mut self, layout: &mut Layout, parser_state: &mut ParserState) -> anyhow::Result<TickResult> {
|
||||||
if let Some(p) = self.pending_open.take() {
|
if let Some(p) = self.pending_open.take() {
|
||||||
self.open_process(p, layout, parser_state)?;
|
self.process_open(p, layout, parser_state)?;
|
||||||
let _ = self.tasks.drain();
|
let _ = self.tasks.drain();
|
||||||
return Ok(TickResult::Opened);
|
return Ok(TickResult::Opened);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue