Comments (6)
As discussed in Pull Request 15, implementing the idea above does not adhere to composition over inheritance (See this article for more info).
So, to change the way that content is laid out, the content should be wrapped in some intermediate class that is then the content within VirtualizedScrollPane
. For example...
Virtualized actualContent = // creation code
ScaledVirtualized wrapper = new ScaledVirtualized(actualContent);
VirtualizedScrollPane<ScaledVirtualized> vsPane = new VirtualizedScrollPane(wrapper);
where ScaledVirtualized
scales actualContent
when user scrolls up/down and the control key is presssed (written in Groovy):
class ScaledVirtualized<V extends Node & Virtualized> extends Region implements Virtualized {
final V content
Scale scale = new Scale(1, 1, 0, 0)
ScaledVirtualized(V content) {
super()
this.content = content
getChildren().add(content)
getTransforms().add(scale)
addEventFilter(ScrollEvent.SCROLL, { ScrollEvent event ->
if (event.controlDown) {
scale.with {
if (event.deltaY > 0) {
y *= 0.8
x *= 0.8
} else {
y /= 0.8
x /= 0.8
}
}
layoutChildren()
event.consume()
}
})
}
@Override
protected void layoutChildren() {
double width = layoutBounds.width
double height = layoutBounds.height
content.resize(width / scale.x, height/ scale.y)
}
@Override
Var<Double> estimatedScrollXProperty() {
content.estimatedScrollXProperty()
}
@Override
Var<Double> estimatedScrollYProperty() {
content.estimatedScrollYProperty()
}
@Override
Val<Double> totalHeightEstimateProperty() {
content.totalHeightEstimateProperty()
}
@Override
Val<Double> totalWidthEstimateProperty() {
content.totalWidthEstimateProperty()
}
}
from flowless.
After doing the above, I came across a small issue. When one "zooms the area out," so that the content's letters are very small and it fits inside the entire viewport, the scroll bars no longer need to be visible, but still are.
from flowless.
It's clear that I need to override the totalWidth/HeightEstimateProperties somehow. I'm still figuring out how to do it correctly.
Edit: Figured out how to fix scroll bar issue. For others who might want something similar, the following code will display scroll bars when needed regardless of scale value (written in Groovy):
class ScaledVirtualized<V extends Node & Virtualized> extends Region implements Virtualized {
final V content
Scale scale = new Scale(1, 1, 0, 0)
Val<Double> estHeight
Val<Double> estWidth
Var<Double> estScrollY
Var<Double> estScrollX
ScaledVirtualized(V content) {
super()
this.content = content
getChildren().add(content)
getTransforms().add(scale)
estHeight = Val.combine(
content.totalHeightEstimateProperty(),
scale.yProperty(),
{ estHeight, scaleFactor -> estHeight * scaleFactor }
)
estWidth = Val.combine(
content.totalWidthEstimateProperty(),
scale.xProperty(),
{ estWidth, scaleFactor -> estWidth * scaleFactor }
)
estScrollX = Var.mapBidirectional(
content.estimatedScrollXProperty(),
(Function) { double scrollX -> scrollX * scale.x },
(Function) { double scrollX -> scrollX / scale.x }
)
estScrollY = Var.mapBidirectional(
content.estimatedScrollYProperty(),
(Function) { double scrollY -> scrollY * scale.y },
(Function) { double scrollY -> scrollY / scale.y }
)
addEventFilter(ScrollEvent.SCROLL, { ScrollEvent event ->
if (event.controlDown) {
scale.with {
double factor = 0.9
if (event.deltaY > 0) {
y *= factor
x *= factor
} else {
y /= factor
x /= factor
}
}
layoutChildren()
event.consume()
}
})
}
@Override
protected void layoutChildren() {
double width = layoutBounds.width
double height = layoutBounds.height
content.resize(width / scale.x, height/ scale.y)
}
@Override
Var<Double> estimatedScrollXProperty() {
estScrollX
}
@Override
Var<Double> estimatedScrollYProperty() {
estScrollY
}
@Override
Val<Double> totalHeightEstimateProperty() {
estHeight
}
@Override
Val<Double> totalWidthEstimateProperty() {
estWidth
}
}
from flowless.
Nice, I'm glad that it works!
from flowless.
If you feel like it, you can contribute this ScaledVirtualized
to Flowless. Maybe without the zooming by scroll functionality and with public scaleProperty()
, so that anyone can control the scaling however they want.
from flowless.
Good point. That would actually be better since others would already have a base from which to extend or to implement other functionality specific to their needs.
I've created a PR for that in Flowless.
from flowless.
Related Issues (20)
- Modular application cannot find flowless HOT 1
- Error fetching URL: https://github.com/FXMisc/Flowless/#flowless/apidocs/
- VirtualFlow.java does not compile in OpenJDK 17 HOT 3
- Scrollbar thumb is too small HOT 1
- VirtualFlow GridPane HOT 10
- Changing styles of rows HOT 3
- Need new maintainer HOT 6
- Why happens to performance when Nodes are used for items in the VirtualFlow/createVertical? HOT 1
- Custom Editor, Multiple Custom Objects, adding HyperlinkSegment and ImageSegment
- Expandable cell problem HOT 2
- VirtualFlow doesn't resize cells properly when layout bounds changes depending on the Orientation. HOT 1
- Keyboard paging computation error while paging up
- VirtualizedScrollPane causes high CPU and GPU on idle with 125% screen scaling HOT 6
- Can't Get Clicked Item in List HOT 27
- Adding items too fast causes scroll when item list is empty HOT 1
- Introduce negative checks, just before each access. HOT 8
- Cell positioning
- org.fxmisc.flowless.CellListManager#getCellIfPresent HOT 1
- JavaFX 16 HOT 2
- JavaFX 17 breaks scrollbar behaviours in VirtualizedScrollPane HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flowless.