mirror of
https://github.com/wayvr-org/wayvr.git
synced 2026-11-20 00:51:19 -08:00
wgui: context menu: scrolling support
This commit is contained in:
1 parent
90553ef1aa
commit
fd963a276d
5 files changed
+93
-17
No files matched your search
@@ -18,6 +18,51 @@
|
||||
</context_menu>
|
||||
</blueprint>
|
||||
|
||||
<blueprint name="my_context_menu_large">
|
||||
<context_menu>
|
||||
<cell text="Item 1"/>
|
||||
<cell text="Item 2"/>
|
||||
<cell text="Item 3"/>
|
||||
<cell text="Item 4"/>
|
||||
<cell text="Item 5"/>
|
||||
<cell text="Item 6"/>
|
||||
<cell text="Item 7"/>
|
||||
<cell text="Item 8"/>
|
||||
<cell text="Item 9"/>
|
||||
<cell text="Item 10"/>
|
||||
<cell text="Item 11"/>
|
||||
<cell text="Item 12"/>
|
||||
<cell text="Item 13"/>
|
||||
<cell text="Item 14"/>
|
||||
<cell text="Item 15"/>
|
||||
<cell text="Item 16"/>
|
||||
<cell text="Item 17"/>
|
||||
<cell text="Item 18"/>
|
||||
<cell text="Item 19"/>
|
||||
<cell text="Item 20"/>
|
||||
<cell text="Item 21"/>
|
||||
<cell text="Item 22"/>
|
||||
<cell text="Item 23"/>
|
||||
<cell text="Item 24"/>
|
||||
<cell text="Item 25"/>
|
||||
<cell text="Item 26"/>
|
||||
<cell text="Item 27"/>
|
||||
<cell text="Item 28"/>
|
||||
<cell text="Item 29"/>
|
||||
<cell text="Item 30"/>
|
||||
<cell text="Item 31"/>
|
||||
<cell text="Item 32"/>
|
||||
<cell text="Item 33"/>
|
||||
<cell text="Item 34"/>
|
||||
<cell text="Item 35"/>
|
||||
<cell text="Item 36"/>
|
||||
<cell text="Item 37"/>
|
||||
<cell text="Item 38"/>
|
||||
<cell text="Item 39"/>
|
||||
<cell text="Item 40"/>
|
||||
</context_menu>
|
||||
</blueprint>
|
||||
|
||||
<include src="various_widgets_inc.xml"/>
|
||||
|
||||
<elements>
|
||||
@@ -91,6 +136,7 @@
|
||||
<rectangle macro="rect">
|
||||
<label text="Context menu test" />
|
||||
<Button id="button_context_menu" text="Show context menu" />
|
||||
<Button id="button_context_menu_large" text="Show large context menu" />
|
||||
</rectangle>
|
||||
<rectangle macro="rect">
|
||||
<label text="Editbox test" />
|
||||
|
||||
@@ -8,10 +8,11 @@ use glam::Vec2;
|
||||
use wgui::{
|
||||
components::{
|
||||
Component,
|
||||
button::{ButtonClickCallback, ComponentButton},
|
||||
button::{ButtonClickCallback, ButtonClickEvent, ComponentButton},
|
||||
checkbox::ComponentCheckbox,
|
||||
},
|
||||
drawing::Color,
|
||||
event::CallbackDataCommon,
|
||||
font_config::WguiFontConfig,
|
||||
globals::WguiGlobals,
|
||||
i18n::Translation,
|
||||
@@ -32,7 +33,10 @@ use wlx_common::locale::WayVRLangProvider;
|
||||
#[derive(Clone)]
|
||||
pub enum TestbedTask {
|
||||
ShowPopup,
|
||||
ShowContextMenu(context_menu::Position),
|
||||
ShowContextMenu {
|
||||
pos: context_menu::Position,
|
||||
large: bool, /* large */
|
||||
},
|
||||
}
|
||||
|
||||
struct Data {
|
||||
@@ -142,6 +146,8 @@ impl TestbedGeneric {
|
||||
|
||||
let button_context_menu =
|
||||
parser_state.fetch_component_as::<ComponentButton>("button_context_menu")?;
|
||||
let button_context_menu_large =
|
||||
parser_state.fetch_component_as::<ComponentButton>("button_context_menu_large")?;
|
||||
let button_click_me = parser_state.fetch_component_as::<ComponentButton>("button_click_me")?;
|
||||
let button = button_click_me.clone();
|
||||
button_click_me.on_click(Rc::new(move |common, _e| {
|
||||
@@ -189,13 +195,21 @@ impl TestbedGeneric {
|
||||
})
|
||||
});
|
||||
|
||||
button_context_menu.on_click({
|
||||
let get_callback = |large: bool| {
|
||||
let tasks = testbed.tasks.clone();
|
||||
Rc::new(move |_common, m| {
|
||||
tasks.push(TestbedTask::ShowContextMenu(m.boundary.into()));
|
||||
Ok(())
|
||||
})
|
||||
});
|
||||
Rc::new(
|
||||
move |_common: &mut CallbackDataCommon, m: ButtonClickEvent| -> anyhow::Result<()> {
|
||||
tasks.push(TestbedTask::ShowContextMenu {
|
||||
pos: m.boundary.into(),
|
||||
large,
|
||||
});
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
};
|
||||
|
||||
button_context_menu.on_click(get_callback(false));
|
||||
button_context_menu_large.on_click(get_callback(true));
|
||||
|
||||
Ok(testbed)
|
||||
}
|
||||
@@ -208,8 +222,8 @@ impl TestbedGeneric {
|
||||
) -> anyhow::Result<()> {
|
||||
match task {
|
||||
TestbedTask::ShowPopup => self.show_popup(params, data)?,
|
||||
TestbedTask::ShowContextMenu(position) => {
|
||||
self.show_context_menu(params, data, position.clone())
|
||||
TestbedTask::ShowContextMenu { pos, large } => {
|
||||
self.show_context_menu(params, data, *pos, *large)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,13 +264,19 @@ impl TestbedGeneric {
|
||||
_params: &mut TestbedUpdateParams,
|
||||
data: &mut Data,
|
||||
position: context_menu::Position,
|
||||
large: bool,
|
||||
) {
|
||||
data.context_menu.open(context_menu::OpenParams {
|
||||
on_custom_attribs: Some(Rc::new(move |custom_attribs| {
|
||||
log::info!("custom attribs {:?}", custom_attribs.pairs);
|
||||
})),
|
||||
blueprint: context_menu::Blueprint::Template {
|
||||
template_name: "my_context_menu".into(),
|
||||
template_name: (if large {
|
||||
"my_context_menu_large"
|
||||
} else {
|
||||
"my_context_menu"
|
||||
})
|
||||
.into(),
|
||||
template_params: Default::default(),
|
||||
},
|
||||
position,
|
||||
|
||||
@@ -23,8 +23,10 @@
|
||||
</template>
|
||||
|
||||
<elements>
|
||||
<rectangle consume_mouse_events="1" color="background(opacity-0.98)" round="8" border="2" border_color="outline" gap="4" padding="8" id="buttons" flex_direction="column">
|
||||
|
||||
<rectangle consume_mouse_events="1" color="background(opacity-0.98)" round="8" border="2" border_color="outline" gap="4" height="100%" padding="4">
|
||||
<div id="buttons" flex_direction="column" overflow_y="scroll" padding="4">
|
||||
<!-- filled-in at runtime -->
|
||||
</div>
|
||||
</rectangle>
|
||||
</elements>
|
||||
</layout>
|
||||
@@ -34,7 +34,7 @@ pub enum Blueprint {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum Position {
|
||||
Unspecified,
|
||||
Absolute(Vec2),
|
||||
|
||||
@@ -349,9 +349,17 @@ impl WguiWindow {
|
||||
content.id
|
||||
} else {
|
||||
// without decorations
|
||||
let (content, _) = params
|
||||
.layout
|
||||
.add_child(topmost_widget.id, WidgetDiv::create(), Default::default())?;
|
||||
let (content, _) = params.layout.add_child(
|
||||
topmost_widget.id,
|
||||
WidgetDiv::create(),
|
||||
taffy::Style {
|
||||
max_size: taffy::Size {
|
||||
width: percent(1.0_f32),
|
||||
height: percent(1.0_f32),
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
|
||||
self.0.borrow_mut().opened_window = Some(OpenedWindow {
|
||||
widget: topmost_widget,
|
||||
|
||||
Reference in new issue
Block a user