Skip to content

Commit

Permalink
fix: refactoring form
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Jan 20, 2024
1 parent 61c3b26 commit aba354d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 42 deletions.
56 changes: 35 additions & 21 deletions src/main/java/viewtify/style/FormStyles.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,18 @@ public interface FormStyles extends ViewtyStyle {
display.opacity(0);
};

/**
* Calculate the width of specified columns.
*
* @param columns
* @return
*/
static int calculateColumnWidth(int columns) {
return Column.v * columns + Gap.v * (columns - 1);
}

private static Style colum(int size) {
return () -> {
display.width(Column.v * size + Gap.v * (size - 1), px);
};
return () -> display.width(calculateColumnWidth(size), px);
}

Style Column1 = colum(1);
Expand Down Expand Up @@ -171,30 +179,36 @@ private static Style colum(int size) {
Style Column12 = colum(12);

Style ColumnlLeft = () -> {
$.descendant(Column1, text.align::left);
$.descendant(Column2, text.align::left);
$.descendant(Column3, text.align::left);
$.descendant(Column4, text.align::left);
$.descendant(Column5, text.align::left);
$.descendant(Column6, text.align::left);
Style special = text.align::left;

$.descendant(Column1, special);
$.descendant(Column2, special);
$.descendant(Column3, special);
$.descendant(Column4, special);
$.descendant(Column5, special);
$.descendant(Column6, special);
};

Style ColumnRight = () -> {
$.descendant(Column1, text.align::right);
$.descendant(Column2, text.align::right);
$.descendant(Column3, text.align::right);
$.descendant(Column4, text.align::right);
$.descendant(Column5, text.align::right);
$.descendant(Column6, text.align::right);
Style special = text.align::right;

$.descendant(Column1, special);
$.descendant(Column2, special);
$.descendant(Column3, special);
$.descendant(Column4, special);
$.descendant(Column5, special);
$.descendant(Column6, special);
};

Style ColumnCenter = () -> {
$.descendant(Column1, text.align::center);
$.descendant(Column2, text.align::center);
$.descendant(Column3, text.align::center);
$.descendant(Column4, text.align::center);
$.descendant(Column5, text.align::center);
$.descendant(Column6, text.align::center);
Style special = text.align::center;

$.descendant(Column1, special);
$.descendant(Column2, special);
$.descendant(Column3, special);
$.descendant(Column4, special);
$.descendant(Column5, special);
$.descendant(Column6, special);
};

Style Preferences = () -> {
Expand Down
14 changes: 2 additions & 12 deletions src/main/java/viewtify/ui/ViewDSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected final void label(Variable text, Consumer<UINode>... followers) {
* @param text
* @return
*/
protected final UILabel text(String text) {
protected final UILabel text(Object text) {
return new UILabel(null).text(text);
}

Expand Down Expand Up @@ -215,16 +215,6 @@ protected final void title(Variable<String> label, Variable<String>... details)
});
}

/**
* Declare Form UI simply.
*
* @param label A form label.
* @param description A label description.
*/
protected final void form(UserInterfaceProvider label, Object description) {
form(label, null, text(String.valueOf(description)));
}

/**
* Declare Form UI simply.
*
Expand Down Expand Up @@ -318,7 +308,7 @@ protected final void form(Variable<String> label, WiseRunnable process) {
*
* @param label A form label.
*/
protected final void form(UserInterfaceProvider label, WiseRunnable process) {
private void form(UserInterfaceProvider label, WiseRunnable process) {
form(() -> {
if (label != null) {
$(label, FormStyles.Label);
Expand Down
24 changes: 15 additions & 9 deletions src/main/resources/viewtify/ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -384,36 +384,42 @@
.text-input,
.text-field,
.button {
-fx-padding: 6px 4px;
-fx-padding: 6 4;
}

.toggle-button {
-fx-padding: 6px 10px;
-fx-padding: 6 10;
}

.text-area {
-fx-padding: 0px;
-fx-padding: 0;
}

.text-area .content {
-fx-padding: 6px 8px;
-fx-padding: 6 8;
}

.text-field.noborder {
-fx-padding: 6px 0px;
-fx-padding: 6 0;
}

.combo-box {
-fx-padding: 2px 0px;
-fx-padding: 2 0;
}
.combo-box > .list-cell {
-fx-padding: 4 2 4 6;
}
.combo-box-base > .arrow-button {
-fx-padding: 4 6 4 2;
}
.combo-box-popup > .list-view > .virtual-flow > .clipped-container > .sheet > .list-cell {
-fx-padding: 7px 8px;
-fx-padding: 7 8;
}

.table-row-cell {
-fx-padding: 2px 0;
-fx-padding: 2 0;
}

.column-header .label {
-fx-padding: 5px 1px;
-fx-padding: 5 1;
}

0 comments on commit aba354d

Please sign in to comment.