wip: swapchain sizes ditcated by wgui

This commit is contained in:
galister
2025-06-19 02:21:44 +09:00
parent e09783791f
commit a03a855f19
6 changed files with 17 additions and 24 deletions

View File

@@ -23,18 +23,12 @@ pub struct GuiPanel {
pub layout: Layout,
context: WguiContext,
timestep: Timestep,
pub max_width: u32,
pub max_height: u32,
pub max_size: u32,
}
impl GuiPanel {
pub fn new_from_template(
app: &AppState,
max_width: u32,
max_height: u32,
path: &str,
) -> anyhow::Result<Self> {
let mut me = Self::new_blank(app, max_width, max_height)?;
pub fn new_from_template(app: &AppState, max_size: u32, path: &str) -> anyhow::Result<Self> {
let mut me = Self::new_blank(app, max_size)?;
let parent = me.layout.root_widget;
let _res = wgui::parser::parse_from_assets(&mut me.layout, parent, path)?;
@@ -42,7 +36,7 @@ impl GuiPanel {
Ok(me)
}
pub fn new_blank(app: &AppState, max_width: u32, max_height: u32) -> anyhow::Result<Self> {
pub fn new_blank(app: &AppState, max_size: u32) -> anyhow::Result<Self> {
let layout = Layout::new(Box::new(GuiAsset {}))?;
let context = WguiContext::new(app.gfx.clone(), app.gfx.surface_format, 1.0)?;
let mut timestep = Timestep::new();
@@ -52,8 +46,7 @@ impl GuiPanel {
layout,
context,
timestep,
max_width,
max_height,
max_size,
})
}
}
@@ -154,7 +147,11 @@ impl OverlayRenderer for GuiPanel {
fn frame_meta(&mut self) -> Option<FrameMeta> {
Some(FrameMeta {
extent: [self.max_width, self.max_height, 1],
extent: [
self.max_size.max(self.layout.prev_size.x as _),
self.max_size.max(self.layout.prev_size.y as _),
1,
],
..Default::default()
})
}

View File

@@ -18,7 +18,7 @@ pub fn create_anchor<O>(app: &mut AppState) -> anyhow::Result<OverlayData<O>>
where
O: Default,
{
let mut panel = GuiPanel::new_blank(app, 200, 200)?;
let mut panel = GuiPanel::new_blank(app, 200)?;
let (rect, _) = panel.layout.add_child(
panel.layout.root_widget,

View File

@@ -18,7 +18,7 @@ pub fn create_custom(
unreachable!();
let panel = GuiPanel::new_blank(&app, 200, 200).ok()?;
let panel = GuiPanel::new_blank(app, 2048).ok()?;
let state = OverlayState {
name,

View File

@@ -100,11 +100,7 @@ where
let padding = 4f32;
let mut panel = GuiPanel::new_blank(
app,
padding.mul_add(2.0, size.x) as u32,
padding.mul_add(2.0, size.y) as u32,
)?;
let mut panel = GuiPanel::new_blank(app, 2048)?;
let (background, _) = panel.layout.add_child(
panel.layout.root_widget,

View File

@@ -167,7 +167,7 @@ fn new_toast(toast: Toast, app: &mut AppState) -> Option<(OverlayState, Box<dyn
toast.title
};
let mut panel = GuiPanel::new_blank(app, 600, 200).ok()?;
let mut panel = GuiPanel::new_blank(app, 2048).ok()?;
let (rect, _) = panel
.layout
@@ -232,7 +232,7 @@ fn new_toast(toast: Toast, app: &mut AppState) -> Option<(OverlayState, Box<dyn
let state = OverlayState {
name: TOAST_NAME.clone(),
want_visible: true,
spawn_scale: (panel.max_width as f32) * PIXELS_TO_METERS,
spawn_scale: (panel.max_size as f32) * PIXELS_TO_METERS,
spawn_rotation,
spawn_point,
z_order: Z_ORDER_TOAST,

View File

@@ -12,7 +12,7 @@ use wgui::{
};
use crate::{
backend::overlay::{ui_transform, OverlayData, OverlayState, Positioning, Z_ORDER_WATCH},
backend::overlay::{OverlayData, OverlayState, Positioning, Z_ORDER_WATCH, ui_transform},
gui::panel::GuiPanel,
state::AppState,
};
@@ -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, 400, 200)?;
let mut panel = GuiPanel::new_blank(app, 2048)?;
let (_, _) = panel.layout.add_child(
panel.layout.root_widget,