mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 14:18:04 +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)]
|
||||
|
||||
@@ -26,7 +26,7 @@ pub const VIEWPORT_SCROLL_RATE: f64 = 0.6;
|
||||
|
||||
pub const VIEWPORT_ROTATE_SNAP_INTERVAL: f64 = 15.;
|
||||
|
||||
pub const VIEWPORT_ZOOM_TO_FIT_PADDING_SCALE_FACTOR: f64 = 0.95;
|
||||
pub const VIEWPORT_ZOOM_TO_FIT_PADDING_SCALE_FACTOR: f64 = 0.999;
|
||||
|
||||
pub const DRAG_BEYOND_VIEWPORT_MAX_OVEREXTENSION_PIXELS: f64 = 50.;
|
||||
pub const DRAG_BEYOND_VIEWPORT_SPEED_FACTOR: f64 = 20.;
|
||||
|
||||
@@ -14,4 +14,5 @@ pub enum AppWindowMessage {
|
||||
Hide,
|
||||
HideOthers,
|
||||
ShowAll,
|
||||
TmpToggleHideUI
|
||||
}
|
||||
|
||||
@@ -44,6 +44,19 @@ impl MessageHandler<AppWindowMessage, ()> for AppWindowMessageHandler {
|
||||
responses.add(PortfolioMessage::AutoSaveAllDocuments);
|
||||
responses.add(FrontendMessage::WindowRestart);
|
||||
}
|
||||
AppWindowMessage::TmpToggleHideUI => {
|
||||
responses.add(FrontendMessage::TmpToggleHideUI);
|
||||
responses.add(PortfolioMessage::ToggleFocusDocument);
|
||||
responses.add(DeferMessage::AfterGraphRun {
|
||||
messages: vec![
|
||||
DocumentMessage::ZoomCanvasToFitAll.into(),
|
||||
DeferMessage::AfterGraphRun {
|
||||
messages: vec![DocumentMessage::ZoomCanvasToFitAll.into()],
|
||||
}
|
||||
.into(),
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
advertise_actions!(AppWindowMessageDiscriminant;
|
||||
@@ -54,6 +67,7 @@ impl MessageHandler<AppWindowMessage, ()> for AppWindowMessageHandler {
|
||||
Drag,
|
||||
Hide,
|
||||
HideOthers,
|
||||
TmpToggleHideUI,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -377,4 +377,6 @@ pub enum FrontendMessage {
|
||||
WindowHideOthers,
|
||||
WindowShowAll,
|
||||
WindowRestart,
|
||||
|
||||
TmpToggleHideUI,
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ pub fn input_mappings(zoom_with_scroll: bool) -> Mapping {
|
||||
entry!(KeyDown(F11); disabled=is_mac, action_dispatch=AppWindowMessage::Fullscreen),
|
||||
entry!(KeyDown(KeyF); modifiers=[Command, Control], disabled=!is_mac, action_dispatch=AppWindowMessage::Fullscreen),
|
||||
entry!(KeyDown(KeyQ); modifiers=[Command], disabled=cfg!(not(target_os = "macos")), action_dispatch=AppWindowMessage::Close),
|
||||
entry!(KeyDown(F11); modifiers=[Alt], action_dispatch=AppWindowMessage::TmpToggleHideUI),
|
||||
//
|
||||
// ClipboardMessage
|
||||
entry!(KeyDown(KeyX); modifiers=[Accel], action_dispatch=ClipboardMessage::Cut),
|
||||
|
||||
@@ -1402,7 +1402,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
|
||||
responses.add(NavigationMessage::CanvasFlip);
|
||||
}
|
||||
responses.add(NavigationMessage::CanvasTiltSet { angle_radians: 0. });
|
||||
responses.add(NavigationMessage::FitViewportToBounds { bounds, prevent_zoom_past_100: true });
|
||||
responses.add(NavigationMessage::FitViewportToBounds { bounds, prevent_zoom_past_100: false });
|
||||
} else {
|
||||
warn!("Cannot zoom due to no bounds")
|
||||
}
|
||||
|
||||
@@ -1111,6 +1111,16 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
|
||||
responses.add(PortfolioMessage::UpdateDocumentWidgets);
|
||||
responses.add(PropertiesPanelMessage::Clear);
|
||||
}
|
||||
|
||||
responses.add(DeferMessage::AfterGraphRun {
|
||||
messages: vec![
|
||||
DocumentMessage::ZoomCanvasToFitAll.into(),
|
||||
DeferMessage::AfterGraphRun {
|
||||
messages: vec![DocumentMessage::ZoomCanvasToFitAll.into()],
|
||||
}
|
||||
.into(),
|
||||
],
|
||||
});
|
||||
}
|
||||
PortfolioMessage::SubmitDocumentExport {
|
||||
name,
|
||||
|
||||
@@ -4,5 +4,6 @@ use crate::messages::prelude::*;
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ViewportMessage {
|
||||
Update { x: f64, y: f64, width: f64, height: f64, scale: f64 },
|
||||
TmpUpdateBounds { x: f64, y: f64, width: f64, height: f64 },
|
||||
RepropagateUpdate,
|
||||
}
|
||||
|
||||
@@ -35,6 +35,14 @@ impl MessageHandler<ViewportMessage, ()> for ViewportMessageHandler {
|
||||
};
|
||||
responses.add(NodeGraphMessage::UpdateNodeGraphWidth);
|
||||
}
|
||||
ViewportMessage::TmpUpdateBounds { x, y, width, height } => {
|
||||
self.bounds = Bounds {
|
||||
offset: Point { x, y },
|
||||
size: Point { x: width, y: height },
|
||||
};
|
||||
responses.add(NodeGraphMessage::UpdateNodeGraphWidth);
|
||||
}
|
||||
|
||||
ViewportMessage::RepropagateUpdate => {}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user