Skip to content

Commit

Permalink
feat: add BlockHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Jan 17, 2024
1 parent 54cba1a commit 36e0394
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/main/java/viewtify/style/FormStyles.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/viewtify/ui/UITextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
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;
import viewtify.ui.helper.ValueHelper;
import viewtify.util.MonkeyPatch;

public class UITextArea extends UserInterface<UITextArea, TextArea>
implements ValueHelper<UITextArea, String>, ContextMenuHelper<UITextArea>, EditableHelper<UITextArea>,
implements ValueHelper<UITextArea, String>, BlockHelper<UITextArea>, ContextMenuHelper<UITextArea>, EditableHelper<UITextArea>,
PlaceholderHelper<UITextArea> {

/**
Expand Down
47 changes: 35 additions & 12 deletions src/main/java/viewtify/ui/ViewDSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}

/**
Expand All @@ -321,11 +319,36 @@ protected final void form(Variable<String> 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();
});
}

Expand Down
41 changes: 41 additions & 0 deletions src/main/java/viewtify/ui/helper/BlockHelper.java
Original file line number Diff line number Diff line change
@@ -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 <Self> The type of the implementing class, enabling method chaining.
*/
public interface BlockHelper<Self extends 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;
}
}
9 changes: 9 additions & 0 deletions src/main/java/viewtify/ui/helper/PropertyAccessHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class Type<T> {
/** The defined property type. */
public static final Type<Double> GraphicTextGap = new Type("graphicTextGap");

/** The defined property type. */
public static final Type<Double> Height = new Type("prefHeight");

/** The defined property type. */
public static final Type<Double> HGap = new Type("hgap");

Expand All @@ -102,9 +105,15 @@ class Type<T> {
/** The defined property type. */
public static final Type<Boolean> Managed = new Type("managed");

/** The defined property type. */
public static final Type<Double> MaxHeight = new Type("maxHeight");

/** The defined property type. */
public static final Type<Double> MaxWidth = new Type("maxWidth");

/** The defined property type. */
public static final Type<Double> MinHeight = new Type("minHeight");

/** The defined property type. */
public static final Type<Double> MinWidth = new Type("minWidth");

Expand Down

0 comments on commit 36e0394

Please sign in to comment.