Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaling combo text according to zoom level #1284

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}
Loading