Skip to content

Commit

Permalink
Account for UI scale when drawing arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
FeldrinH committed Dec 9, 2023
1 parent 1cb1032 commit 4fe90b5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/ee/ut/dendroloj/GraphGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static void initGenericGUI(double uiScale, Graph graph, Layout layout) {
graph.setAttribute("ui.stylesheet", String.format(Locale.ROOT,
"edge {" +
" size: %fpx;" +
" arrow-size: %fpx, %fpx;" +
" fill-mode: dyn-plain;" +
" text-size: %f; text-alignment: center;" +
" text-background-mode: plain; text-background-color: rgba(255, 255, 255, 180);" +
Expand All @@ -39,7 +40,7 @@ public static void initGenericGUI(double uiScale, Graph graph, Layout layout) {
" fill-color: rgb(255, 0, 0);" +
"}" +
"edge.arrowonly {" +
" text-mode: hidden;"+
" text-mode: hidden;" +
" size: 0px;" +
"}" +
"node {" +
Expand All @@ -53,7 +54,9 @@ public static void initGenericGUI(double uiScale, Graph graph, Layout layout) {
" fill-mode: plain;" +
" fill-color: #0096ff;" +
"}",
Math.max(0.8, Math.sqrt(uiScale)), uiScale * 14, uiScale + 1,
Math.max(0.8, Math.sqrt(uiScale)),
(uiScale > 1 ? Math.sqrt(uiScale) : uiScale) * 8, (uiScale > 1 ? Math.sqrt(uiScale) : uiScale) * 4,
uiScale * 14, uiScale + 1,
uiScale * 28, uiScale * 14, uiScale * 3));

init(graph, layout, null);
Expand Down Expand Up @@ -99,6 +102,9 @@ private static void init(Graph graph, Layout layout, JComponent toolbar) {

SwingViewer viewer = new SwingViewer(graph, SwingViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
View view = viewer.addDefaultView(false);

System.out.println("ARROW SIZE: " + viewer.getGraphicGraph().getStyleSheet().getDefaultGraphStyle().getArrowSize());

if (layout != null) {
// Adding an auto-layout makes dragging nodes feel really choppy and introduces strange rubber banding.
// TODO: Figure out why and fix this. (A good starting point might be seeing if official examples have this problem.)
Expand Down

0 comments on commit 4fe90b5

Please sign in to comment.