Skip to content

Commit

Permalink
Text fields: Keep scroll position when vertically "middle" aligned
Browse files Browse the repository at this point in the history
  • Loading branch information
kasemir committed May 21, 2024
1 parent 3a9dee2 commit c91bda4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015-2018 Oak Ridge National Laboratory.
* Copyright (c) 2015-2024 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -20,6 +20,7 @@
import org.csstudio.display.builder.model.WidgetPropertyListener;
import org.csstudio.display.builder.model.persist.NamedWidgetColors;
import org.csstudio.display.builder.model.persist.WidgetColorService;
import org.csstudio.display.builder.model.properties.VerticalAlignment;
import org.csstudio.display.builder.model.properties.WidgetColor;
import org.csstudio.display.builder.model.widgets.PVWidget;
import org.csstudio.display.builder.model.widgets.TextEntryWidget;
Expand Down Expand Up @@ -423,7 +424,22 @@ else if(jfx_node instanceof TextArea){
if (! active)
{
if (dirty_content.checkAndClear())
{
// For middle-aligned multi-line text, keep the scroll position
TextArea area = null;
double pos = 0;
if (jfx_node instanceof TextArea &&
model_widget.propVerticalAlignment().getValue() == VerticalAlignment.MIDDLE)
{
area = (TextArea) jfx_node;
pos = area.getScrollTop();
}

jfx_node.setText(value_text);

if (area != null)
area.setScrollTop(pos);
}
}
// When not managed, trigger layout
if (!jfx_node.isManaged())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015-2020 Oak Ridge National Laboratory.
* Copyright (c) 2015-2024 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -281,8 +281,18 @@ public void updateChanges()
else
{ // Implies 'interactive' mode
final TextArea area = (TextArea)jfx_node;

// Before updating the text, get scroll position just in case we need it later
final double top = area.getScrollTop();

area.setText(value_text);
if (model_widget.propVerticalAlignment().getValue() == VerticalAlignment.BOTTOM)

final VerticalAlignment alignment = model_widget.propVerticalAlignment().getValue();
if (alignment == VerticalAlignment.MIDDLE)
{ // In 'middle' alignment mode, keep the scroll position.
area.setScrollTop(top);
}
else if (alignment == VerticalAlignment.BOTTOM)
{
// For bottom-aligned widget, scroll to bottom,
// but area.setScrollTop(Double.MAX_VALUE) has no effect.
Expand Down

0 comments on commit c91bda4

Please sign in to comment.