Skip to content

Commit

Permalink
Scaling combo text according to zoom level
Browse files Browse the repository at this point in the history
Registering the comboDpiChange handler and applying change manually to
text, image and arrow and popup
  • Loading branch information
ShahzaibIbrahim committed Jun 28, 2024
1 parent f40502d commit 728e98e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2025,4 +2025,21 @@ public boolean traverse(int event){
}
return super.traverse(event);
}

/**
* The method accepts a combo and a callback which takes
* all the child of the CCombo as the argument and executes it.
* All children are refreshed after the execution of the callback.
*
* @noreference This method is not intended to be referenced by clients.
* @param combo
* @param childUpdater
*/
public static void updateAndRefreshChildren(CCombo combo, Consumer<Widget> childUpdater) {
childUpdater.accept(combo.text);
childUpdater.accept(combo.list);
childUpdater.accept(combo.arrow);
childUpdater.accept(combo.popup);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.swt.internal;

import org.eclipse.swt.custom.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

Expand All @@ -31,6 +32,7 @@ public class CommonWidgetsDPIChangeHandlers {

public static void registerCommonHandlers() {
DPIZoomChangeRegistry.registerHandler(CommonWidgetsDPIChangeHandlers::handleItemDPIChange, Item.class);
DPIZoomChangeRegistry.registerHandler(CommonWidgetsDPIChangeHandlers::handleCComboDPIChange, CCombo.class);
}

private static void handleItemDPIChange(Widget widget, int newZoom, float scalingFactor) {
Expand All @@ -43,4 +45,10 @@ private static void handleItemDPIChange(Widget widget, int newZoom, float scalin
item.setImage(image);
}
}
}
private static void handleCComboDPIChange(Widget widget, int newZoom, float scalingFactor) {
if (!(widget instanceof CCombo combo)) {
return;
}
CCombo.updateAndRefreshChildren(combo, childWidget -> DPIZoomChangeRegistry.applyChange(childWidget, newZoom, scalingFactor));
}
}

0 comments on commit 728e98e

Please sign in to comment.