xml anchor + GuiPanel minor refactor
This commit is contained in:
@@ -1,12 +1,5 @@
|
||||
use glam::{Vec3A, vec2};
|
||||
use glam::Vec3A;
|
||||
use std::sync::{Arc, LazyLock};
|
||||
use wgui::parser::parse_color_hex;
|
||||
use wgui::renderer_vk::text::{FontWeight, TextStyle};
|
||||
use wgui::taffy;
|
||||
use wgui::taffy::prelude::{length, percent};
|
||||
use wgui::widget::rectangle::{Rectangle, RectangleParams};
|
||||
use wgui::widget::text::{TextLabel, TextParams};
|
||||
use wgui::widget::util::WLength;
|
||||
|
||||
use crate::backend::overlay::{OverlayData, OverlayState, Positioning, Z_ORDER_ANCHOR};
|
||||
use crate::gui::panel::GuiPanel;
|
||||
@@ -18,46 +11,7 @@ pub fn create_anchor<O>(app: &mut AppState) -> anyhow::Result<OverlayData<O>>
|
||||
where
|
||||
O: Default,
|
||||
{
|
||||
let mut panel = GuiPanel::new_blank(app, 200)?;
|
||||
|
||||
let (rect, _) = panel.layout.add_child(
|
||||
panel.layout.root_widget,
|
||||
Rectangle::create(RectangleParams {
|
||||
color: wgui::drawing::Color::new(0., 0., 0., 0.),
|
||||
border_color: parse_color_hex("#ffff00").unwrap(),
|
||||
border: 2.0,
|
||||
round: WLength::Percent(1.0),
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap(),
|
||||
taffy::Style {
|
||||
size: taffy::Size {
|
||||
width: percent(1.0),
|
||||
height: percent(1.0),
|
||||
},
|
||||
align_items: Some(taffy::AlignItems::Center),
|
||||
justify_content: Some(taffy::JustifyContent::Center),
|
||||
padding: length(4.0),
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
|
||||
let _ = panel.layout.add_child(
|
||||
rect,
|
||||
TextLabel::create(TextParams {
|
||||
content: "Center".into(),
|
||||
style: TextStyle {
|
||||
weight: Some(FontWeight::Bold),
|
||||
size: Some(36.0),
|
||||
color: parse_color_hex("#ffff00"),
|
||||
..Default::default()
|
||||
},
|
||||
})
|
||||
.unwrap(),
|
||||
taffy::style::Style::DEFAULT,
|
||||
);
|
||||
|
||||
panel.layout.update(vec2(2048., 2048.), 0.0)?;
|
||||
let panel = GuiPanel::new_from_template(app, "gui/anchor.xml")?;
|
||||
|
||||
Ok(OverlayData {
|
||||
state: OverlayState {
|
||||
|
||||
@@ -18,8 +18,8 @@ pub fn create_custom(
|
||||
|
||||
unreachable!();
|
||||
|
||||
let panel = GuiPanel::new_blank(app, 2048).ok()?;
|
||||
panel.layout.update(vec2(2048., 2048.), 0.0).ok()?;
|
||||
let panel = GuiPanel::new_blank(app).ok()?;
|
||||
panel.update_layout().ok()?;
|
||||
|
||||
let state = OverlayState {
|
||||
name,
|
||||
|
||||
@@ -51,7 +51,7 @@ where
|
||||
processes: vec![],
|
||||
}));
|
||||
|
||||
let mut panel = GuiPanel::new_blank(app, 2048)?;
|
||||
let mut panel = GuiPanel::new_blank(app)?;
|
||||
|
||||
let (background, _) = panel.layout.add_child(
|
||||
panel.layout.root_widget,
|
||||
|
||||
@@ -169,7 +169,7 @@ fn new_toast(toast: Toast, app: &mut AppState) -> Option<(OverlayState, Box<dyn
|
||||
toast.title
|
||||
};
|
||||
|
||||
let mut panel = GuiPanel::new_blank(app, 2048).ok()?;
|
||||
let mut panel = GuiPanel::new_blank(app).ok()?;
|
||||
|
||||
let (rect, _) = panel
|
||||
.layout
|
||||
@@ -231,10 +231,12 @@ fn new_toast(toast: Toast, app: &mut AppState) -> Option<(OverlayState, Box<dyn
|
||||
},
|
||||
);
|
||||
|
||||
panel.update_layout().ok()?;
|
||||
|
||||
let state = OverlayState {
|
||||
name: TOAST_NAME.clone(),
|
||||
want_visible: true,
|
||||
spawn_scale: (panel.max_size as f32) * PIXELS_TO_METERS,
|
||||
spawn_scale: panel.layout.content_size.x * PIXELS_TO_METERS,
|
||||
spawn_rotation,
|
||||
spawn_point,
|
||||
z_order: Z_ORDER_TOAST,
|
||||
|
||||
@@ -23,7 +23,7 @@ pub fn create_watch<O>(app: &mut AppState) -> anyhow::Result<OverlayData<O>>
|
||||
where
|
||||
O: Default,
|
||||
{
|
||||
let mut panel = GuiPanel::new_blank(app, 2048)?;
|
||||
let mut panel = GuiPanel::new_blank(app)?;
|
||||
|
||||
let (_, _) = panel.layout.add_child(
|
||||
panel.layout.root_widget,
|
||||
@@ -52,7 +52,7 @@ where
|
||||
lerp: 1.0,
|
||||
};
|
||||
|
||||
panel.layout.update(vec2(2048., 2048.), 0.0)?;
|
||||
panel.update_layout()?;
|
||||
|
||||
Ok(OverlayData {
|
||||
state: OverlayState {
|
||||
|
||||
Reference in New Issue
Block a user