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 26, 2024
1 parent f40502d commit 2e1e202
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2025,4 +2025,13 @@ public boolean traverse(int event){
}
return super.traverse(event);
}
/**
* @since 3.126
*/
public static void adapt(CCombo combo, Consumer<Widget> consumer) {
consumer.accept(combo.text);
consumer.accept(combo.list);
consumer.accept(combo.arrow);
consumer.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,12 @@ 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)) {
return;
}
CCombo combo = (CCombo) widget;

CCombo.adapt(combo, w -> DPIZoomChangeRegistry.applyChange(w, newZoom, scalingFactor));
}
}

0 comments on commit 2e1e202

Please sign in to comment.