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 authored and fedejeanne committed Jul 1, 2024
1 parent 5cdf331 commit e138ae3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2025,4 +2025,20 @@ 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 the Combo to get the children widget from
* @param childUpdater the callback which works with the child widgets
*/
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 @@ -33,6 +33,7 @@ public class CommonWidgetsDPIChangeHandlers {
public static void registerCommonHandlers() {
DPIZoomChangeRegistry.registerHandler(CommonWidgetsDPIChangeHandlers::handleItemDPIChange, Item.class);
DPIZoomChangeRegistry.registerHandler(CommonWidgetsDPIChangeHandlers::handleStyledTextDPIChange, StyledText.class);
DPIZoomChangeRegistry.registerHandler(CommonWidgetsDPIChangeHandlers::handleCComboDPIChange, CCombo.class);
}

private static void handleItemDPIChange(Widget widget, int newZoom, float scalingFactor) {
Expand All @@ -51,9 +52,16 @@ private static void handleStyledTextDPIChange(Widget widget, int newZoom, float
return;
}


StyledText.updateAndRefreshCarets(styledText, caretToRefresh -> {
DPIZoomChangeRegistry.applyChange(caretToRefresh, newZoom, scalingFactor);
Caret.win32_setHeight(caretToRefresh, styledText.getLineHeight());
});
}
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 e138ae3

Please sign in to comment.