Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Jan 16, 2024
1 parent c2a8122 commit 2197dc3
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 12 deletions.
106 changes: 101 additions & 5 deletions src/main/java/viewtify/style/FormStyles.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
*/
public interface FormStyles extends ViewtyStyle {

int GAP = 4;
int HorizontalGap = 2;

int VerticalGap = 4;

Style Row = () -> {
margin.vertical(GAP, px);
text.verticalAlign.baseline();
margin.vertical(VerticalGap, px);
text.verticalAlign.middle();
background.color("red");
};

Expand Down Expand Up @@ -54,7 +56,7 @@ public interface FormStyles extends ViewtyStyle {
};

Style Description = () -> {
margin.vertical(GAP, px);
margin.vertical(VerticalGap, px);
};

Style DescriptionTitle = () -> {
Expand Down Expand Up @@ -106,7 +108,101 @@ public interface FormStyles extends ViewtyStyle {
});
};

Style FormMin = () -> {
$.descendant(Label, () -> {
display.width(80, px);
});

$.descendant(LabelMin, () -> {
display.width(40, px);
});
};

Style FormSlim = () -> {
$.descendant(Label, () -> {
display.width(100, px);
});

$.descendant(LabelMin, () -> {
display.width(60, px);
});
};

Style Form = () -> {
$.descendant(Label, () -> {
display.width(120, px);
});

$.descendant(LabelMin, () -> {
display.width(80, px);
});
};

Style FormWide = () -> {
$.descendant(Label, () -> {
display.width(140, px);
});

$.descendant(LabelMin, () -> {
display.width(100, px);
});
};

Style FormMax = () -> {
$.descendant(Label, () -> {
display.width(160, px);
});

$.descendant(LabelMin, () -> {
display.width(120, px);
});
};

Style LabelLeft = () -> {
$.descendant(Label, () -> {
text.align.left();
});

$.descendant(LabelMin, () -> {
text.align.left();
});
};

Style LabelRight = () -> {
$.descendant(Label, () -> {
text.align.right();
});

$.descendant(LabelMin, () -> {
text.align.right();
});
};

Style LabelCenter = () -> {
$.descendant(Label, () -> {
text.align.center();
});

$.descendant(LabelMin, () -> {
text.align.center();
});
};

Style Sequencial = () -> {
margin.left(GAP, px);
margin.right(HorizontalGap, px);
};

Style Combined = () -> {
display.height.fitContent();
padding.size(0, px).right(2, px);
margin.size(0, px);
};

Style CombinedItem = () -> {
text.align.center();
};

Style CheckBox = () -> {
text.align.left();
};
}
25 changes: 25 additions & 0 deletions src/main/java/viewtify/ui/UIText.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Label;
Expand All @@ -38,6 +39,7 @@
import kiss.I;
import viewtify.Viewtify;
import viewtify.property.SmartProperty;
import viewtify.style.FormStyles;
import viewtify.ui.helper.ContextMenuHelper;
import viewtify.ui.helper.EditableHelper;
import viewtify.ui.helper.PlaceholderHelper;
Expand Down Expand Up @@ -419,6 +421,29 @@ public UIText<V> suggest(Callback<ISuggestionRequest, Collection<V>> suggestionP
return this;
}

/**
* Create combined text input user interface.
*
* @return
*/
public UIHBox combine(UIText... combiners) {
UIHBox container = new UIHBox(view).style("text-input").style(FormStyles.Combined);
ObservableList<Node> children = container.ui().getChildren();
UIText[] inputs = I.array(new UIText[] {this}, combiners);

for (UIText<?> input : inputs) {
input.style("noborder").style(FormStyles.CombinedItem).whenFocus(focused -> {
if (focused) {
container.style("focused");
} else {
container.unstyle("focused");
}
});
children.add(input.ui());
}
return container;
}

/**
*
*/
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/viewtify/ui/ViewDSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,28 @@ protected final void form(Style style, UserInterfaceProvider... userInterfaces)
*
* @param label A form label.
* @param style Additional style for controls.
* @param userInterfaces A list of form controls.
* @param providers A list of form controls.
*/
private void form(UserInterfaceProvider label, Style style, UserInterfaceProvider... userInterfaces) {
form(label, () -> {
for (UserInterfaceProvider userInterface : userInterfaces) {
$(userInterface, style == null ? new Style[] {FormStyles.Input} : new Style[] {FormStyles.Input, style});
}
});
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);
}
}

/**
* Declare Form UI simply.
*
* @param label A form label.
*/
protected final void form(String label, WiseRunnable process) {
form(() -> TextNotation.parse(label), process);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/viewtify/ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
-fx-accent-4: derive(-fx-accent, 20%);
}

/* ==========================================================================
CheckBox
===========================================================================*/
.check-box {
-fx-label-padding: 0 0 0 3px;
}

/* ==========================================================================
CheckComboBox - bug fix for focused style
===========================================================================*/
Expand Down

0 comments on commit 2197dc3

Please sign in to comment.