From 4dcb2bc36978786d5528f253a833f92e654889f8 Mon Sep 17 00:00:00 2001 From: Teletha Date: Sun, 26 Nov 2023 13:05:26 +0900 Subject: [PATCH] feat: Config notification more. --- src/main/java/viewtify/ui/toast/Toast.java | 29 ++++++++++++------- .../java/viewtify/ui/toast/ToastSetting.java | 8 +++-- .../viewtify/ui/toast/ToastSettingView.java | 17 +++++++++++ 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/main/java/viewtify/ui/toast/Toast.java b/src/main/java/viewtify/ui/toast/Toast.java index 2226a4477..8be54bd41 100644 --- a/src/main/java/viewtify/ui/toast/Toast.java +++ b/src/main/java/viewtify/ui/toast/Toast.java @@ -36,14 +36,22 @@ public class Toast extends Preferences { - /** The margin for each notifications. */ - private static final int MARGIN = 15; - /** The base transparent window. */ private static final LinkedList notifications = new LinkedList(); public static final ToastSetting setting = Preferences.of(ToastSetting.class); + static { + setting.gap.observe().to(Toast::layoutNotifications); + setting.area.observe().to(Toast::layoutNotifications); + setting.screen.observe().to(Toast::layoutNotifications); + setting.opacity.observe().to(v -> { + for (Notification notification : notifications) { + notification.ui().getContent().get(0).setOpacity(v / 100d); + } + }); + } + /** * Show the specified node. */ @@ -120,12 +128,13 @@ private static void remove(Notification notification) { */ private static void layoutNotifications() { Viewtify.inUI(() -> { + int gap = setting.gap.exact(); Rectangle2D rect = setting.screen.v.select(); // use viewtify notification boolean isTopSide = setting.area.v.isTopSide(); - double x = setting.area.v.isLeftSide() ? rect.getMinX() + MARGIN : rect.getMaxX() - setting.width.v - MARGIN; - double y = isTopSide ? rect.getMinY() + MARGIN : rect.getMaxY(); + double x = setting.area.v.isLeftSide() ? rect.getMinX() + gap : rect.getMaxX() - setting.width.v - gap; + double y = isTopSide ? rect.getMinY() + gap : rect.getMaxY(); Iterator iterator = isTopSide ? notifications.descendingIterator() : notifications.iterator(); while (iterator.hasNext()) { @@ -133,20 +142,20 @@ private static void layoutNotifications() { Popup popup = notify.ui(); if (popup.isShowing()) { - if (!isTopSide) y -= popup.getHeight() + MARGIN; + if (!isTopSide) y -= popup.getHeight() + gap; popup.setX(x); Animatable.play(setting.animation.v, notify.y, y); } else { popup.setOpacity(0); popup.show(Window.getWindows().get(0)); - if (!isTopSide) y -= popup.getHeight() + MARGIN; + if (!isTopSide) y -= popup.getHeight() + gap; popup.setX(x); popup.setY(y); Animatable.play(setting.animation.v, popup.opacityProperty(), 1); } - if (isTopSide) y += popup.getHeight() + MARGIN; + if (isTopSide) y += popup.getHeight() + gap; } }); } @@ -199,7 +208,7 @@ private synchronized Popup ui() { StyleHelper.of(box).style(Styles.popup); box.setMaxWidth(setting.width.v); box.setMinWidth(setting.width.v); - box.setOpacity(setting.opacity.v); + box.setOpacity(setting.opacity.v / 100d); ui.setX(0); ui.getContent().add(box); @@ -221,7 +230,7 @@ private synchronized Popup ui() { private static interface Styles extends StyleDSL { Style popup = () -> { - padding.vertical(MARGIN, px).horizontal(MARGIN, px); + padding.vertical(15, px).horizontal(15, px); background.color("derive(-fx-control-inner-background, 10%)"); border.radius(5, px).color("-fx-light-text-color"); }; diff --git a/src/main/java/viewtify/ui/toast/ToastSetting.java b/src/main/java/viewtify/ui/toast/ToastSetting.java index 2159bf3c5..e02e49573 100644 --- a/src/main/java/viewtify/ui/toast/ToastSetting.java +++ b/src/main/java/viewtify/ui/toast/ToastSetting.java @@ -10,6 +10,7 @@ package viewtify.ui.toast; import javafx.util.Duration; + import viewtify.model.Preferences; import viewtify.util.Corner; import viewtify.util.ScreenSelector; @@ -29,7 +30,7 @@ public class ToastSetting extends Preferences { public final Preference animation = initialize(Duration.millis(333)).requireMin(Duration.ONE); /** The automatic hiding time. */ - public final Preference autoHide = initialize(Duration.seconds(15)).requireMin(Duration.ZERO); + public final Preference autoHide = initialize(Duration.seconds(20)).requireMin(Duration.ZERO); /** The notification area. */ public final Preference area = initialize(Corner.BottomRight); @@ -38,8 +39,11 @@ public class ToastSetting extends Preferences { public final Preference screen = initialize(ScreenSelector.InWindow); /** The opacity of notification area. */ - public final Preference opacity = initialize(0.9).requireBetween(0, 1); + public final Preference opacity = initialize(90).requireBetween(0, 100); /** The width of notification area. */ public final Preference width = initialize(250).requireMin(50); + + /** The gap of notification area. */ + public final Preference gap = initialize(15).requireBetween(0, 30); } \ No newline at end of file diff --git a/src/main/java/viewtify/ui/toast/ToastSettingView.java b/src/main/java/viewtify/ui/toast/ToastSettingView.java index 7ef81abf8..d532a2d2d 100644 --- a/src/main/java/viewtify/ui/toast/ToastSettingView.java +++ b/src/main/java/viewtify/ui/toast/ToastSettingView.java @@ -12,7 +12,9 @@ import java.util.stream.IntStream; import javafx.util.Duration; + import viewtify.model.Preferences; +import viewtify.ui.UIButton; import viewtify.ui.UICheckBox; import viewtify.ui.UIComboBox; import viewtify.ui.UISpinner; @@ -38,6 +40,15 @@ public class ToastSettingView extends View { /** The desktop configuration UI. */ private UISpinner notificationMax; + /** The desktop configuration UI. */ + private UISpinner notificationGap; + + /** The desktop configuration UI. */ + private UISpinner notificationOpacity; + + /** Execute notification for test. */ + private UIButton notificationTest; + /** * {@inheritDoc} */ @@ -50,6 +61,9 @@ protected ViewDSL declareUI() { form(en("Notification Location"), notificationArea); form(en("Notification Duration"), notificationDuration); form(en("Max number of Notifications"), notificationMax); + form(en("Notification area spacing"), notificationGap); + form(en("Notification area opacity"), notificationOpacity); + form(en("Test notification"), notificationTest); }); } }; @@ -70,5 +84,8 @@ protected void initialize() { .sync(setting.autoHide) .format(d -> String.valueOf((int) d.toSeconds()) + en("sec")) .disableWhen(enableNotification.isNotSelected()); + notificationGap.items(IntStream.range(0, 31)).sync(setting.gap).format(x -> x + "px"); + notificationOpacity.items(IntStream.range(0, 101)).sync(setting.opacity).format(x -> x + "%"); + notificationTest.text(en("Notify")).action(() -> Toast.show("Test")); } }