mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-25 03:58:12 +08:00
Fake Fullscreen Viewport
This commit is contained in:
@@ -46,6 +46,7 @@ pub(crate) struct App {
|
||||
cli: Cli,
|
||||
startup_time: Option<Instant>,
|
||||
exit_reason: ExitReason,
|
||||
hide_ui: bool,
|
||||
}
|
||||
|
||||
impl App {
|
||||
@@ -109,6 +110,7 @@ impl App {
|
||||
cli,
|
||||
exit_reason: ExitReason::Shutdown,
|
||||
startup_time: None,
|
||||
hide_ui: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +127,10 @@ impl App {
|
||||
}
|
||||
|
||||
fn resize(&mut self) {
|
||||
if self.hide_ui {
|
||||
self.handle_desktop_frontend_message(DesktopFrontendMessage::TmpToggleHideUI, &mut Vec::new());
|
||||
}
|
||||
|
||||
let Some(window) = &self.window else {
|
||||
tracing::error!("Resize failed due to missing window");
|
||||
return;
|
||||
@@ -239,6 +245,19 @@ impl App {
|
||||
});
|
||||
}
|
||||
DesktopFrontendMessage::UpdateViewportPhysicalBounds { x, y, width, height } => {
|
||||
if self.hide_ui {
|
||||
if x != 0.0 && y != 0.0 {
|
||||
let message = DesktopWrapperMessage::TmpUpdateViewport {
|
||||
x: 0.,
|
||||
y: 0.,
|
||||
width: self.window_size.width as f64 / self.window_scale,
|
||||
height: self.window_size.height as f64 / self.window_scale,
|
||||
};
|
||||
self.dispatch_desktop_wrapper_message(message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(render_state) = &mut self.render_state
|
||||
&& let Some(window) = &self.window
|
||||
{
|
||||
@@ -254,6 +273,9 @@ impl App {
|
||||
}
|
||||
}
|
||||
DesktopFrontendMessage::UpdateUIScale { scale } => {
|
||||
if self.hide_ui {
|
||||
return;
|
||||
}
|
||||
self.ui_scale = scale;
|
||||
self.resize();
|
||||
}
|
||||
@@ -402,6 +424,22 @@ impl App {
|
||||
DesktopFrontendMessage::Restart => {
|
||||
self.exit(Some(ExitReason::Restart));
|
||||
}
|
||||
|
||||
DesktopFrontendMessage::TmpToggleHideUI => {
|
||||
if self.hide_ui {
|
||||
self.hide_ui = false;
|
||||
} else {
|
||||
let message = DesktopWrapperMessage::TmpUpdateViewport {
|
||||
x: 0.,
|
||||
y: 0.,
|
||||
width: self.window_size.width as f64 / self.window_scale,
|
||||
height: self.window_size.height as f64 / self.window_scale,
|
||||
};
|
||||
self.dispatch_desktop_wrapper_message(message);
|
||||
self.render_state.as_mut().unwrap().unbind_ui_texture();
|
||||
self.hide_ui = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,6 +489,10 @@ impl App {
|
||||
NodeGraphExecutionResult::NotRun => {}
|
||||
},
|
||||
AppEvent::UiUpdate(texture) => {
|
||||
if self.hide_ui {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(render_state) = self.render_state.as_mut() {
|
||||
render_state.bind_ui_texture(texture);
|
||||
}
|
||||
|
||||
@@ -217,6 +217,11 @@ impl RenderState {
|
||||
self.update_bindgroup();
|
||||
}
|
||||
|
||||
pub(crate) fn unbind_ui_texture(&mut self) {
|
||||
self.ui_texture = None;
|
||||
self.update_bindgroup();
|
||||
}
|
||||
|
||||
pub(crate) fn set_viewport_scale(&mut self, scale: [f32; 2]) {
|
||||
self.surface_outdated = true;
|
||||
self.viewport_scale = scale;
|
||||
|
||||
@@ -97,5 +97,10 @@ pub(super) fn handle_desktop_wrapper_message(dispatcher: &mut DesktopWrapperMess
|
||||
let message = AppWindowMessage::PointerLockMove { x, y };
|
||||
dispatcher.queue_editor_message(message);
|
||||
}
|
||||
|
||||
DesktopWrapperMessage::TmpUpdateViewport { x, y, width, height } => {
|
||||
let message = ViewportMessage::TmpUpdateBounds { x, y, width, height };
|
||||
dispatcher.queue_editor_message(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +154,10 @@ pub(super) fn intercept_frontend_message(dispatcher: &mut DesktopWrapperMessageD
|
||||
FrontendMessage::WindowRestart => {
|
||||
dispatcher.respond(DesktopFrontendMessage::Restart);
|
||||
}
|
||||
|
||||
FrontendMessage::TmpToggleHideUI => {
|
||||
dispatcher.respond(DesktopFrontendMessage::TmpToggleHideUI);
|
||||
}
|
||||
m => return Some(m),
|
||||
}
|
||||
None
|
||||
|
||||
@@ -75,6 +75,8 @@ pub enum DesktopFrontendMessage {
|
||||
WindowHideOthers,
|
||||
WindowShowAll,
|
||||
Restart,
|
||||
|
||||
TmpToggleHideUI,
|
||||
}
|
||||
|
||||
pub enum DesktopWrapperMessage {
|
||||
@@ -126,6 +128,13 @@ pub enum DesktopWrapperMessage {
|
||||
x: f64,
|
||||
y: f64,
|
||||
},
|
||||
|
||||
TmpUpdateViewport {
|
||||
x: f64,
|
||||
y: f64,
|
||||
width: f64,
|
||||
height: f64,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, serde::Serialize, serde::Deserialize, Debug)]
|
||||
|
||||
Reference in New Issue
Block a user