From 36e0394b0140a878a15aabd263383ab15feb30b9 Mon Sep 17 00:00:00 2001 From: Teletha Date: Wed, 17 Jan 2024 16:06:49 +0900 Subject: [PATCH] feat: add BlockHelper --- src/main/java/viewtify/style/FormStyles.java | 4 ++ src/main/java/viewtify/ui/UITextArea.java | 4 +- src/main/java/viewtify/ui/ViewDSL.java | 47 ++++++++++++++----- .../java/viewtify/ui/helper/BlockHelper.java | 41 ++++++++++++++++ .../ui/helper/PropertyAccessHelper.java | 9 ++++ 5 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 src/main/java/viewtify/ui/helper/BlockHelper.java diff --git a/src/main/java/viewtify/style/FormStyles.java b/src/main/java/viewtify/style/FormStyles.java index 67ad35f01..d3d2bed6b 100644 --- a/src/main/java/viewtify/style/FormStyles.java +++ b/src/main/java/viewtify/style/FormStyles.java @@ -31,6 +31,10 @@ public interface FormStyles extends ViewtyStyle { margin.top(6, px); }; + Style LabelInfo = Label.with(() -> { + font.size(0.88, em); + }); + Style Input = () -> { display.width(160, px); }; diff --git a/src/main/java/viewtify/ui/UITextArea.java b/src/main/java/viewtify/ui/UITextArea.java index 2f2089c92..36da66fb2 100644 --- a/src/main/java/viewtify/ui/UITextArea.java +++ b/src/main/java/viewtify/ui/UITextArea.java @@ -12,7 +12,7 @@ import javafx.beans.property.BooleanProperty; import javafx.beans.property.Property; import javafx.scene.control.TextArea; - +import viewtify.ui.helper.BlockHelper; import viewtify.ui.helper.ContextMenuHelper; import viewtify.ui.helper.EditableHelper; import viewtify.ui.helper.PlaceholderHelper; @@ -20,7 +20,7 @@ import viewtify.util.MonkeyPatch; public class UITextArea extends UserInterface - implements ValueHelper, ContextMenuHelper, EditableHelper, + implements ValueHelper, BlockHelper, ContextMenuHelper, EditableHelper, PlaceholderHelper { /** diff --git a/src/main/java/viewtify/ui/ViewDSL.java b/src/main/java/viewtify/ui/ViewDSL.java index aa28ef5a4..37f6ccb79 100644 --- a/src/main/java/viewtify/ui/ViewDSL.java +++ b/src/main/java/viewtify/ui/ViewDSL.java @@ -285,16 +285,14 @@ protected final void form(Style style, UserInterfaceProvider... userInterfaces) * @param providers A list of form controls. */ private void form(UserInterfaceProvider label, Style style, UserInterfaceProvider... providers) { - form(label, () -> extracted(style, providers)); - } - - private void extracted(Style style, UserInterfaceProvider... providers) { - Style[] styles = style == null ? new Style[] {FormStyles.Input} : new Style[] {FormStyles.Input, style}; - for (int i = 0; i < providers.length; i++) { - if (i != providers.length - 1) styles = I.array(styles, FormStyles.Sequencial); - if (providers[i] instanceof UICheckBox) styles = I.array(styles, FormStyles.CheckBox); - $(providers[i], styles); - } + form(label, () -> { + Style[] styles = style == null ? new Style[] {} : new Style[] {style}; + for (int i = 0; i < providers.length; i++) { + if (i != providers.length - 1) styles = I.array(styles, FormStyles.Sequencial); + if (providers[i] instanceof UICheckBox) styles = I.array(styles, FormStyles.CheckBox); + $(providers[i], styles); + } + }); } /** @@ -321,11 +319,36 @@ protected final void form(Variable label, WiseRunnable process) { * @param label A form label. */ protected final void form(UserInterfaceProvider label, WiseRunnable process) { - $(hbox, FormStyles.Row, () -> { + form(() -> { if (label != null) { $(label, FormStyles.Label); } - process.run(); + }, process); + } + + /** + * Declare Form UI simply. + * + * @param label A form label. + */ + protected final void form(String label, WiseRunnable labelProcess, WiseRunnable process) { + form(() -> { + $(vbox, () -> { + $(() -> TextNotation.parse(label), FormStyles.Label); + labelProcess.run(); + }); + }, process); + } + + /** + * Declare Form UI simply. + * + * @param label A form label. + */ + private final void form(WiseRunnable label, WiseRunnable form) { + $(hbox, FormStyles.Row, () -> { + if (label != null) label.run(); + if (form != null) form.run(); }); } diff --git a/src/main/java/viewtify/ui/helper/BlockHelper.java b/src/main/java/viewtify/ui/helper/BlockHelper.java new file mode 100644 index 000000000..e592f205c --- /dev/null +++ b/src/main/java/viewtify/ui/helper/BlockHelper.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2024 The VIEWTIFY Development Team + * + * Licensed under the MIT License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/MIT + */ +package viewtify.ui.helper; + +/** + * An interface providing methods to set alignment, orientation, horizontal gap, and vertical gap + * properties. + * + * @param The type of the implementing class, enabling method chaining. + */ +public interface BlockHelper extends PropertyAccessHelper { + + /** + * Sets the height property. + * + * @return The implementing class instance for method chaining. + */ + default Self height(double size) { + property(Type.Height).setValue(size); + + return (Self) this; + } + + /** + * Sets the width property. + * + * @return The implementing class instance for method chaining. + */ + default Self width(double size) { + property(Type.Width).setValue(size); + + return (Self) this; + } +} \ No newline at end of file diff --git a/src/main/java/viewtify/ui/helper/PropertyAccessHelper.java b/src/main/java/viewtify/ui/helper/PropertyAccessHelper.java index 95dba93b4..1cab745fe 100644 --- a/src/main/java/viewtify/ui/helper/PropertyAccessHelper.java +++ b/src/main/java/viewtify/ui/helper/PropertyAccessHelper.java @@ -87,6 +87,9 @@ class Type { /** The defined property type. */ public static final Type GraphicTextGap = new Type("graphicTextGap"); + /** The defined property type. */ + public static final Type Height = new Type("prefHeight"); + /** The defined property type. */ public static final Type HGap = new Type("hgap"); @@ -102,9 +105,15 @@ class Type { /** The defined property type. */ public static final Type Managed = new Type("managed"); + /** The defined property type. */ + public static final Type MaxHeight = new Type("maxHeight"); + /** The defined property type. */ public static final Type MaxWidth = new Type("maxWidth"); + /** The defined property type. */ + public static final Type MinHeight = new Type("minHeight"); + /** The defined property type. */ public static final Type MinWidth = new Type("minWidth");