Remove grow augment

This commit is contained in:
crschnick
2025-12-31 22:51:04 +00:00
parent bc859df654
commit ae4876acb5
11 changed files with 23 additions and 95 deletions
@@ -63,7 +63,6 @@ public class ActionShortcutComp extends SimpleComp {
var copyButton = new ButtonComp(null, new FontIcon("mdi2c-clipboard-multiple-outline"), () -> {
ClipboardHelper.copyUrl(url.getValue());
})
.grow(false, true)
.descriptor(d -> d.nameKey("copyUrl"));
var field = new TextFieldComp(url);
field.apply(struc -> struc.get().setEditable(false));
@@ -89,7 +88,6 @@ public class ActionShortcutComp extends SimpleComp {
DesktopHelper.browseFileInDirectory(file);
});
})
.grow(false, true)
.descriptor(d -> d.nameKey("createShortcut"));
var field = new TextFieldComp(name);
var group = new InputGroupComp(List.of(field, copyButton));
@@ -109,7 +107,6 @@ public class ActionShortcutComp extends SimpleComp {
ClipboardHelper.copyUrl(sa.toNode().toPrettyString());
}
})
.grow(false, true)
.descriptor(d -> d.nameKey("copyBody"));
var field = new TextFieldComp(prop, true);
field.apply(struc -> struc.get().setEditable(false));
@@ -75,8 +75,7 @@ public class BrowserTransferComp extends SimpleComp {
},
sourceItem.get().getProgress());
}
})
.grow(false, true);
});
var dragNotice = new LabelComp(AppI18n.observable("dragLocalFiles"))
.apply(struc -> struc.get().setGraphic(new FontIcon("mdi2h-hand-back-left-outline")))
.apply(struc -> struc.get().setWrapText(true))
@@ -175,66 +175,6 @@ public abstract class Comp<S extends CompStructure<?>> {
return apply(struc -> struc.get().getStyleClass().add(styleClass));
}
public Comp<S> grow(boolean width, boolean height) {
return apply(struc -> {
struc.get().parentProperty().addListener((c, o, n) -> {
if (o instanceof Region) {
if (width) {
struc.get().prefWidthProperty().unbind();
}
if (height) {
struc.get().prefHeightProperty().unbind();
}
}
bindGrow(struc.get(), n, width, height);
});
bindGrow(struc.get(), struc.get().getParent(), width, height);
});
}
private void bindGrow(Region r, Node parent, boolean width, boolean height) {
if (!(parent instanceof Region p)) {
return;
}
if (width) {
r.prefWidthProperty()
.bind(Bindings.createDoubleBinding(
() -> {
var val = p.getWidth()
- p.getInsets().getLeft()
- p.getInsets().getRight();
if (val <= 0) {
return Region.USE_COMPUTED_SIZE;
}
// Floor to prevent rounding issues which cause an infinite growing
return Math.floor(val);
},
p.widthProperty(),
p.insetsProperty()));
}
if (height) {
r.prefHeightProperty()
.bind(Bindings.createDoubleBinding(
() -> {
var val = p.getHeight()
- p.getInsets().getTop()
- p.getInsets().getBottom();
if (val <= 0) {
return Region.USE_COMPUTED_SIZE;
}
// Floor to prevent rounding issues which cause an infinite growing
return Math.floor(val);
},
p.heightProperty(),
p.insetsProperty()));
}
}
public Comp<S> descriptor(Consumer<CompDescriptor.CompDescriptorBuilder> c) {
var desc = CompDescriptor.builder();
c.accept(desc);
@@ -91,9 +91,7 @@ public class ContextualFileReferenceChoiceComp extends Comp<CompStructure<HBox>>
false,
directory,
filter);
})
.styleClass(sync != null ? Styles.CENTER_PILL : Styles.RIGHT_PILL)
.grow(false, true);
});
var gitShareButton = new ButtonComp(null, new FontIcon("mdi2g-git"), () -> {
if (!DataStorageSyncHandler.getInstance().supportsSync()) {
@@ -157,7 +155,6 @@ public class ContextualFileReferenceChoiceComp extends Comp<CompStructure<HBox>>
});
gitShareButton.styleClass("git-sync-file-button");
gitShareButton.descriptor(d -> d.nameKey("gitShareFileTooltip"));
gitShareButton.styleClass(Styles.RIGHT_PILL).grow(false, true);
gitShareButton.disable(Bindings.createBooleanBinding(
() -> {
return filePath.getValue() != null
@@ -171,7 +168,7 @@ public class ContextualFileReferenceChoiceComp extends Comp<CompStructure<HBox>>
if (sync != null) {
nodes.add(gitShareButton);
}
var layout = new HorizontalComp(nodes).apply(struc -> struc.get().setFillHeight(true));
var layout = new InputGroupComp(nodes).setMainReference(path).apply(struc -> struc.get().setFillHeight(true));
layout.apply(struc -> {
struc.get().focusedProperty().addListener((observable, oldValue, newValue) -> {
@@ -219,8 +216,6 @@ public class ContextualFileReferenceChoiceComp extends Comp<CompStructure<HBox>>
},
filePath));
combo.hgrow();
combo.styleClass(Styles.LEFT_PILL);
combo.grow(false, true);
return combo;
}
@@ -233,9 +228,7 @@ public class ContextualFileReferenceChoiceComp extends Comp<CompStructure<HBox>>
filePath.setValue(newValue != null && !newValue.isBlank() ? FilePath.of(newValue.strip()) : null);
});
var fileNameComp = new TextFieldComp(prop)
.apply(struc -> HBox.setHgrow(struc.get(), Priority.ALWAYS))
.styleClass(Styles.LEFT_PILL)
.grow(false, true);
.apply(struc -> HBox.setHgrow(struc.get(), Priority.ALWAYS));
if (prompt != null) {
fileNameComp.apply(struc -> {
@@ -18,13 +18,21 @@ public class InputGroupComp extends Comp<CompStructure<InputGroup>> {
private final List<Comp<?>> entries;
@Setter
private Comp<?> mainReference;
public InputGroupComp(List<Comp<?>> comps) {
entries = List.copyOf(comps);
}
public InputGroupComp setMainReference(Comp<?> mainReference) {
this.mainReference = mainReference;
return this;
}
public InputGroupComp setMainReference(int index) {
return setMainReference(entries.get(index));
}
@Override
public CompStructure<InputGroup> createBase() {
InputGroup b = new InputGroup();
@@ -121,7 +121,6 @@ public class SecretFieldComp extends Comp<SecretFieldComp.Structure> {
var copyButton = new ButtonComp(null, new FontIcon("mdi2c-clipboard-multiple-outline"), () -> {
ClipboardHelper.copyPassword(value.getValue());
})
.grow(false, true)
.descriptor(d -> d.nameKey("copy"));
var list = new ArrayList<Comp<?>>();
@@ -40,11 +40,10 @@ public class StoreIconChoiceDialog {
var filterText = new SimpleStringProperty();
var filter = new FilterComp(filterText).hgrow();
filter.focusOnShow();
var github = new ButtonComp(null, new FontIcon("mdomz-settings"), () -> {
var settings = new ButtonComp(null, new FontIcon("mdomz-settings"), () -> {
overlay.close();
AppPrefs.get().selectCategory("icons");
})
.grow(false, true);
});
var modal = ModalOverlay.of(
"chooseCustomIcon",
new StoreIconChoiceComp(
@@ -63,7 +62,7 @@ public class StoreIconChoiceDialog {
finish();
})
.prefWidth(600));
modal.addButtonBarComp(github);
modal.addButtonBarComp(settings);
modal.addButtonBarComp(filter);
modal.addButton(new ModalButton(
"clear",
@@ -3,6 +3,7 @@ package io.xpipe.app.prefs;
import io.xpipe.app.comp.Comp;
import io.xpipe.app.comp.base.ButtonComp;
import io.xpipe.app.comp.base.HorizontalComp;
import io.xpipe.app.comp.base.InputGroupComp;
import io.xpipe.app.comp.base.TextFieldComp;
import io.xpipe.app.core.AppProperties;
import io.xpipe.app.issue.TrackEvent;
@@ -57,15 +58,12 @@ public class DeveloperCategory extends AppPrefsCategory {
});
};
var runLocalCommand = new HorizontalComp(List.of(
var runLocalCommand = new InputGroupComp(List.of(
new TextFieldComp(localCommand)
.apply(struc -> struc.get().setPromptText("Local command"))
.styleClass(Styles.LEFT_PILL)
.grow(false, true)
.hgrow(),
new ButtonComp(null, new FontIcon("mdi2p-play"), test)
.styleClass(Styles.RIGHT_PILL)
.grow(false, true)))
new ButtonComp(null, new FontIcon("mdi2p-play"), test)))
.setMainReference(0)
.padding(new Insets(15, 0, 0, 0))
.apply(struc -> struc.get().setAlignment(Pos.CENTER_LEFT))
.apply(struc -> struc.get().setFillHeight(true))
@@ -56,7 +56,6 @@ public class HostAddressChoiceComp extends Comp<CompStructure<HBox>> {
currentAddress.setValue(null);
adding.set(false);
});
addButton.styleClass(Styles.CENTER_PILL).grow(false, true);
addButton.descriptor(d -> d.nameKey("addAnotherHostName"));
var nodes = new ArrayList<Comp<?>>();
@@ -180,9 +179,7 @@ public class HostAddressChoiceComp extends Comp<CompStructure<HBox>> {
});
});
combo.hgrow();
combo.styleClass(Styles.LEFT_PILL);
combo.styleClass("host-address-choice-comp");
combo.grow(false, true);
return combo;
}
}
@@ -159,12 +159,12 @@ public class IdentitySelectComp extends Comp<CompStructure<HBox>> {
addNamedIdentity();
}
});
addButton.styleClass(Styles.RIGHT_PILL).grow(false, true).descriptor(d -> d.nameKey("addReusableIdentity"));
addButton.descriptor(d -> d.nameKey("addReusableIdentity"));
var nodes = new ArrayList<Comp<?>>();
nodes.add(createComboBox());
nodes.add(addButton);
var layout = new HorizontalComp(nodes).apply(struc -> struc.get().setFillHeight(true));
var layout = new InputGroupComp(nodes).setMainReference(0).apply(struc -> struc.get().setFillHeight(true));
layout.apply(struc -> {
struc.get().focusedProperty().addListener((observable, oldValue, newValue) -> {
@@ -269,7 +269,6 @@ public class IdentitySelectComp extends Comp<CompStructure<HBox>> {
});
combo.apply(struc -> struc.get().setEditable(allowUserInput));
combo.styleClass(Styles.LEFT_PILL);
combo.grow(false, true);
combo.apply(struc -> {
var binding = Bindings.createStringBinding(
@@ -53,8 +53,7 @@ public class CustomAgentStrategy implements SshIdentityStrategy {
new ButtonComp(null, new FontIcon("mdomz-settings"), () -> {
AppPrefs.get().selectCategory("ssh");
})
.padding(new Insets(7))
.grow(false, true)))
.padding(new Insets(7))))
.spacing(9);
return new OptionsBuilder()