fix scaling, refactors
This commit is contained in:
@@ -101,7 +101,7 @@ impl SharedContext {
|
|||||||
return Ok(key);
|
return Ok(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log::debug!("Initializing SharedAtlas for pixel scale {pixel_scale:.1}");
|
log::debug!("Initializing SharedAtlas for pixel scale {pixel_scale:.2}");
|
||||||
let text_atlas = TextAtlas::new(self.text_pipeline.clone())?;
|
let text_atlas = TextAtlas::new(self.text_pipeline.clone())?;
|
||||||
Ok(self.atlas_map.insert(SharedAtlas {
|
Ok(self.atlas_map.insert(SharedAtlas {
|
||||||
text_atlas,
|
text_atlas,
|
||||||
@@ -143,7 +143,7 @@ impl Context {
|
|||||||
resolution: [u32; 2],
|
resolution: [u32; 2],
|
||||||
pixel_scale: f32,
|
pixel_scale: f32,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
if (self.pixel_scale - pixel_scale).abs() < f32::EPSILON {
|
if (self.pixel_scale - pixel_scale).abs() > f32::EPSILON {
|
||||||
self.pixel_scale = pixel_scale;
|
self.pixel_scale = pixel_scale;
|
||||||
self.shared_ctx_key = shared.atlas_for_pixel_scale(pixel_scale)?;
|
self.shared_ctx_key = shared.atlas_for_pixel_scale(pixel_scale)?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ pub(crate) const DEFAULT_METRICS: Metrics = Metrics::new(
|
|||||||
pub struct TextStyle {
|
pub struct TextStyle {
|
||||||
pub size: Option<f32>,
|
pub size: Option<f32>,
|
||||||
pub line_height: Option<f32>,
|
pub line_height: Option<f32>,
|
||||||
pub color: Option<drawing::Color>, // TODO: should this be hex?
|
pub color: Option<drawing::Color>,
|
||||||
pub style: Option<FontStyle>,
|
pub style: Option<FontStyle>,
|
||||||
pub weight: Option<FontWeight>,
|
pub weight: Option<FontWeight>,
|
||||||
pub align: Option<HorizontalAlign>,
|
pub align: Option<HorizontalAlign>,
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ impl WidgetState {
|
|||||||
(data, obj)
|
(data, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(obj: Box<dyn WidgetObj>) -> anyhow::Result<WidgetState> {
|
fn new(obj: Box<dyn WidgetObj>) -> anyhow::Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
data: WidgetData {
|
data: WidgetData {
|
||||||
hovered: 0,
|
hovered: 0,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use wgui::{
|
|||||||
MouseUpEvent, MouseWheelEvent,
|
MouseUpEvent, MouseWheelEvent,
|
||||||
},
|
},
|
||||||
layout::Layout,
|
layout::Layout,
|
||||||
|
parser::ParserResult,
|
||||||
renderer_vk::context::Context as WguiContext,
|
renderer_vk::context::Context as WguiContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -33,19 +34,25 @@ pub struct GuiPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl GuiPanel {
|
impl GuiPanel {
|
||||||
pub fn new_from_template(app: &mut AppState, path: &str) -> anyhow::Result<Self> {
|
pub fn new_from_template(
|
||||||
let (layout, _state) =
|
app: &mut AppState,
|
||||||
|
path: &str,
|
||||||
|
) -> anyhow::Result<(Self, ParserResult)> {
|
||||||
|
let (layout, parser_result) =
|
||||||
wgui::parser::new_layout_from_assets(Box::new(gui::asset::GuiAsset {}), path)?;
|
wgui::parser::new_layout_from_assets(Box::new(gui::asset::GuiAsset {}), path)?;
|
||||||
|
|
||||||
let context = WguiContext::new(&mut app.wgui_shared, 1.0)?;
|
let context = WguiContext::new(&mut app.wgui_shared, 1.0)?;
|
||||||
let mut timestep = Timestep::new();
|
let mut timestep = Timestep::new();
|
||||||
timestep.set_tps(60.0);
|
timestep.set_tps(60.0);
|
||||||
|
|
||||||
Ok(Self {
|
Ok((
|
||||||
|
Self {
|
||||||
layout,
|
layout,
|
||||||
context,
|
context,
|
||||||
timestep,
|
timestep,
|
||||||
})
|
},
|
||||||
|
parser_result,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_blank(app: &mut AppState) -> anyhow::Result<Self> {
|
pub fn new_blank(app: &mut AppState) -> anyhow::Result<Self> {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ pub fn create_anchor<O>(app: &mut AppState) -> anyhow::Result<OverlayData<O>>
|
|||||||
where
|
where
|
||||||
O: Default,
|
O: Default,
|
||||||
{
|
{
|
||||||
let panel = GuiPanel::new_from_template(app, "gui/anchor.xml")?;
|
let (panel, _) = GuiPanel::new_from_template(app, "gui/anchor.xml")?;
|
||||||
|
|
||||||
Ok(OverlayData {
|
Ok(OverlayData {
|
||||||
state: OverlayState {
|
state: OverlayState {
|
||||||
|
|||||||
@@ -20,7 +20,13 @@ 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)?;
|
let (mut panel, parser) = GuiPanel::new_from_template(app, "gui/watch.xml")?;
|
||||||
|
|
||||||
|
for (id, widget) in parser.ids.iter() {
|
||||||
|
if id.starts_with("clock") {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(clock) = parser.require_by_id("clock0") {}
|
||||||
|
|
||||||
let (_, _) = panel.layout.add_child(
|
let (_, _) = panel.layout.add_child(
|
||||||
panel.layout.root_widget,
|
panel.layout.root_widget,
|
||||||
|
|||||||
Reference in New Issue
Block a user