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

View File

@@ -18,7 +18,7 @@ pub fn create_anchor<O>(app: &mut AppState) -> anyhow::Result<OverlayData<O>>
where where
O: Default, 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( let (rect, _) = panel.layout.add_child(
panel.layout.root_widget, panel.layout.root_widget,

View File

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

View File

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

View File

@@ -167,7 +167,7 @@ fn new_toast(toast: Toast, app: &mut AppState) -> Option<(OverlayState, Box<dyn
toast.title toast.title
}; };
let mut panel = GuiPanel::new_blank(app, 600, 200).ok()?; let mut panel = GuiPanel::new_blank(app, 2048).ok()?;
let (rect, _) = panel let (rect, _) = panel
.layout .layout
@@ -232,7 +232,7 @@ fn new_toast(toast: Toast, app: &mut AppState) -> Option<(OverlayState, Box<dyn
let state = OverlayState { let state = OverlayState {
name: TOAST_NAME.clone(), name: TOAST_NAME.clone(),
want_visible: true, 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_rotation,
spawn_point, spawn_point,
z_order: Z_ORDER_TOAST, z_order: Z_ORDER_TOAST,

View File

@@ -12,7 +12,7 @@ use wgui::{
}; };
use crate::{ 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, gui::panel::GuiPanel,
state::AppState, state::AppState,
}; };
@@ -23,7 +23,7 @@ pub fn create_watch<O>(app: &mut AppState) -> anyhow::Result<OverlayData<O>>
where where
O: Default, O: Default,
{ {
let mut panel = GuiPanel::new_blank(app, 400, 200)?; let mut panel = GuiPanel::new_blank(app, 2048)?;
let (_, _) = panel.layout.add_child( let (_, _) = panel.layout.add_child(
panel.layout.root_widget, panel.layout.root_widget,