+
diff --git a/wgui/src/components/tooltip.rs b/wgui/src/components/tooltip.rs
index e2be282..f270675 100644
--- a/wgui/src/components/tooltip.rs
+++ b/wgui/src/components/tooltip.rs
@@ -103,7 +103,7 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
let transform = Mat4::from_translation(Vec3::new(-0.5, 0.0, 0.0));
- let (pin_left, pin_top, pin_align_items, pin_justify_content) = match params.info.side {
+ let (mut pin_left, mut pin_top, pin_align_items, pin_justify_content) = match params.info.side {
TooltipSide::Left => (
absolute_boundary.left() - spacing,
absolute_boundary.top() + absolute_boundary.size.y / 2.0,
diff --git a/wgui/src/event.rs b/wgui/src/event.rs
index 05d3223..15874bd 100644
--- a/wgui/src/event.rs
+++ b/wgui/src/event.rs
@@ -95,6 +95,8 @@ impl Event {
pub enum StyleSetRequest {
Display(taffy::Display),
Margin(taffy::Rect
),
+ Width(taffy::Dimension),
+ Height(taffy::Dimension),
}
// alterables which will be dispatched in the next loop iteration phase
diff --git a/wgui/src/layout.rs b/wgui/src/layout.rs
index b5ea5bc..17caee9 100644
--- a/wgui/src/layout.rs
+++ b/wgui/src/layout.rs
@@ -744,6 +744,12 @@ impl Layout {
event::StyleSetRequest::Margin(margin) => {
cur_style.margin = margin;
}
+ event::StyleSetRequest::Width(val) => {
+ cur_style.size.width = val;
+ }
+ event::StyleSetRequest::Height(val) => {
+ cur_style.size.height = val;
+ }
}
if let Err(e) = self.state.tree.set_style(*node_id, cur_style) {
diff --git a/wgui/src/parser/component_button.rs b/wgui/src/parser/component_button.rs
index 17c971d..6e63d6e 100644
--- a/wgui/src/parser/component_button.rs
+++ b/wgui/src/parser/component_button.rs
@@ -1,12 +1,12 @@
use crate::{
- components::{button, tooltip, Component},
+ components::{Component, button, tooltip},
drawing::Color,
i18n::Translation,
layout::WidgetID,
parser::{
- parse_check_f32, parse_check_i32, parse_children, print_invalid_attrib, process_component,
+ AttribPair, ParserContext, ParserFile, parse_check_f32, parse_check_i32, parse_children, print_invalid_attrib,
+ process_component,
style::{parse_color_opt, parse_round, parse_style, parse_text_style},
- AttribPair, ParserContext, ParserFile,
},
widget::util::WLength,
};
@@ -94,7 +94,7 @@ pub fn parse_component_button<'a>(
text_style,
round,
tooltip: tooltip.map(|t| tooltip::TooltipInfo {
- side: tooltip_side.map_or(tooltip::TooltipSide::Bottom, |f| f),
+ side: tooltip_side.map_or(tooltip::TooltipSide::Top, |f| f),
text: Translation::from_translation_key(&t),
}),
sticky,
diff --git a/wgui/src/windowing.rs b/wgui/src/windowing.rs
index c805e3d..9fb72b8 100644
--- a/wgui/src/windowing.rs
+++ b/wgui/src/windowing.rs
@@ -1,15 +1,17 @@
use std::{cell::RefCell, rc::Rc};
use glam::Vec2;
-use taffy::prelude::length;
+use taffy::prelude::{length, percent};
use crate::{
assets::AssetPath,
components::button::ComponentButton,
+ event::StyleSetRequest,
globals::WguiGlobals,
+ i18n::Translation,
layout::{Layout, LayoutTask, LayoutTasks, WidgetPair},
parser::{self, Fetchable, ParserState},
- widget::div::WidgetDiv,
+ widget::{div::WidgetDiv, label::WidgetLabel},
};
struct OpenedWindow {
@@ -38,10 +40,28 @@ pub struct OnContentData {
pub widget: WidgetPair,
}
+#[derive(Default)]
+pub enum WguiWindowPlacement {
+ #[default]
+ TopLeft,
+ BottomLeft,
+ TopRight,
+ BottomRight,
+}
+
+#[derive(Default)]
+pub struct WguiWindowParamsExtra {
+ pub fixed_width: Option,
+ pub fixed_height: Option,
+ pub placement: WguiWindowPlacement,
+}
+
pub struct WguiWindowParams<'a> {
pub position: Vec2,
pub globals: WguiGlobals,
pub layout: &'a mut Layout,
+ pub title: Translation,
+ pub extra: WguiWindowParamsExtra,
}
impl Default for WguiWindow {
@@ -50,6 +70,9 @@ impl Default for WguiWindow {
}
}
+const WINDOW_DECORATION_HEADER_HEIGHT: f32 = 32.0;
+const WINDOW_DECORATION_PADDING: f32 = 2.0;
+
impl WguiWindow {
pub fn close(&self) {
self.0.borrow_mut().opened_window = None;
@@ -61,15 +84,59 @@ impl WguiWindow {
const XML_PATH: AssetPath = AssetPath::WguiInternal("wgui/window_frame.xml");
+ let (padding, justify_content, align_items) = match params.extra.placement {
+ WguiWindowPlacement::TopLeft => (
+ taffy::Rect {
+ left: length(params.position.x - WINDOW_DECORATION_PADDING),
+ top: length(params.position.y - WINDOW_DECORATION_HEADER_HEIGHT - WINDOW_DECORATION_PADDING),
+ bottom: length(0.0),
+ right: length(0.0),
+ },
+ taffy::JustifyContent::Start, // x start
+ taffy::AlignItems::Start, // y start
+ ),
+ WguiWindowPlacement::BottomLeft => (
+ taffy::Rect {
+ left: length(params.position.x - WINDOW_DECORATION_PADDING),
+ top: length(0.0),
+ bottom: length(params.position.y - WINDOW_DECORATION_PADDING),
+ right: length(0.0),
+ },
+ taffy::JustifyContent::Start, // x start
+ taffy::AlignItems::End, // y end
+ ),
+ WguiWindowPlacement::TopRight => (
+ taffy::Rect {
+ left: length(0.0),
+ top: length(params.position.y - WINDOW_DECORATION_HEADER_HEIGHT - WINDOW_DECORATION_PADDING),
+ bottom: length(0.0),
+ right: length(params.position.x - WINDOW_DECORATION_PADDING),
+ },
+ taffy::JustifyContent::End, // x end
+ taffy::AlignItems::Start, // y start
+ ),
+ WguiWindowPlacement::BottomRight => (
+ taffy::Rect {
+ left: length(0.0),
+ top: length(0.0),
+ bottom: length(params.position.y - WINDOW_DECORATION_PADDING),
+ right: length(params.position.x - WINDOW_DECORATION_PADDING),
+ },
+ taffy::JustifyContent::End, // x end
+ taffy::AlignItems::End, // y end
+ ),
+ };
+
let (widget, _) = params.layout.add_topmost_child(
WidgetDiv::create(),
taffy::Style {
position: taffy::Position::Absolute,
- margin: taffy::Rect {
- left: length(params.position.x),
- right: length(0.0),
- top: length(params.position.y),
- bottom: length(0.0),
+ align_items: Some(align_items),
+ justify_content: Some(justify_content),
+ padding,
+ size: taffy::Size {
+ width: percent(1.0),
+ height: percent(1.0),
},
..Default::default()
},
@@ -94,15 +161,35 @@ impl WguiWindow {
})
});
+ {
+ let mut text_title = state.fetch_widget_as::(¶ms.layout.state, "text_window_title")?;
+ text_title.set_text_simple(&mut params.globals.get(), params.title.clone());
+ }
+
let content = state.fetch_widget(¶ms.layout.state, "content")?;
self.0.borrow_mut().opened_window = Some(OpenedWindow {
widget,
state,
layout_tasks: params.layout.tasks.clone(),
- content,
+ content: content.clone(),
});
+ let mut c = params.layout.start_common();
+ if let Some(width) = params.extra.fixed_width {
+ c.common()
+ .alterables
+ .set_style(content.id, StyleSetRequest::Width(length(width)));
+ }
+
+ if let Some(height) = params.extra.fixed_height {
+ c.common()
+ .alterables
+ .set_style(content.id, StyleSetRequest::Height(length(height)));
+ }
+
+ c.finish()?;
+
Ok(())
}