forked from eclipse-platform/eclipse.platform.swt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add opt-in method to propagate zoom changes
Contributes to eclipse-platform#62 and eclipse-platform#127
- Loading branch information
1 parent
d76f147
commit f98648b
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/DPIZoomChangeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Yatta Solutions and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Yatta Solutions - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.swt.internal; | ||
|
||
import org.eclipse.swt.widgets.*; | ||
|
||
@FunctionalInterface | ||
public interface DPIZoomChangeHandler { | ||
public void handleDPIChange(Widget widget, int newZoom, float scalingFactor); | ||
} |
47 changes: 47 additions & 0 deletions
47
...les/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/DPIZoomChangeRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Yatta Solutions and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Yatta Solutions - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.swt.internal; | ||
|
||
import java.util.*; | ||
import java.util.Map.*; | ||
|
||
import org.eclipse.swt.widgets.*; | ||
|
||
public class DPIZoomChangeRegistry { | ||
|
||
private static Map<Class<? extends Widget>, DPIZoomChangeHandler> dpiZoomChangeHandlers = new TreeMap<>( | ||
(o1, o2) -> { | ||
if(o1.isAssignableFrom(o2)) { | ||
return -1; | ||
} | ||
if(o2.isAssignableFrom(o1)) { | ||
return 1; | ||
} | ||
return o1.getName().compareTo(o2.getName()); | ||
}); | ||
|
||
public static <E> void applyChange(Widget widget, int newZoom, float scalingFactor) { | ||
for (Entry<Class<? extends Widget>, DPIZoomChangeHandler> entry : dpiZoomChangeHandlers.entrySet()) { | ||
Class<? extends Widget> clazz = entry.getKey(); | ||
DPIZoomChangeHandler handler = entry.getValue(); | ||
if (clazz.isInstance(widget)) { | ||
handler.handleDPIChange(widget, newZoom, scalingFactor); | ||
} | ||
} | ||
} | ||
|
||
public static <E> void registerHandler(DPIZoomChangeHandler zoomChangeVisitor, Class<? extends Widget> clazzToRegisterFor) { | ||
dpiZoomChangeHandlers.put(clazzToRegisterFor, zoomChangeVisitor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters