Add feature: get character bounds on screen#455
Add feature: get character bounds on screen#455JordanMartinez merged 1 commit intoFXMisc:masterfrom JordanMartinez:characterBounds
Conversation
|
Addresses #150. |
|
Manually tested this code (well, how would you test it via TestFX...?) with: import javafx.application.Application;
import javafx.geometry.Bounds;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.stage.Popup;
import javafx.stage.Stage;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.InlineCssTextArea;
import java.util.Optional;
public class CharacterBoundsDemo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
InlineCssTextArea area = new InlineCssTextArea("0123456789\n123456789\n123456789");
area.setWrapText(true);
area.setStyle("-fx-font-size: 32pt;");
VirtualizedScrollPane<InlineCssTextArea> vsPane = new VirtualizedScrollPane<>(area);
Region r = new Region();
r.setStyle("-fx-background-color: red;");
Popup p = new Popup();
p.getContent().add(r);
TextField fromField = new TextField("0");
TextField toField = new TextField("10");
Button b = new Button("Show");
b.setOnAction(ae -> {
int from = Integer.parseInt(fromField.getText());
int to = Integer.parseInt(toField.getText());
Optional<Bounds> optB = area.getCharacterBoundsOnScreen(from, to);
optB.ifPresent(bounds -> {
r.setMinSize(bounds.getWidth(), bounds.getHeight());
p.show(primaryStage, bounds.getMinX(), bounds.getMinY());
});
});
BorderPane root = new BorderPane();
root.setCenter(vsPane);
root.setBottom(new HBox(fromField, toField, b));
primaryStage.setScene(new Scene(root, 200, 400));
primaryStage.show();
}
} |
I don't see this as a problem because it'll only run on the JavaFX Application Thread, so there shouldn't be any issue with concurrency-related things. Additionally,
After testing this out, there wasn't any difference between |
A few questions I have:
selectionShapebe used to get the bounds? Will that switch-out approach cause any issues later on? I didn't want to create a newPathobject each time the method is called so as to reduce memory usage.FORWARDbias inendPosition = offsetToPosition(to, Bias.FORWARD). Is that correct? Or should it beBACKWARD? I still don't understand how that part of the code works.