[pve-devel] [PATCH ha-manager 02/10] Simulator: fix scrolling to end of cluster log view
Thomas Lamprecht
t.lamprecht at proxmox.com
Wed Dec 21 16:44:39 CET 2016
As the cursor may be set by the user, even if invisible, scrolling to
its position to reach the end of the TextView is potentially flawed.
Connect a signal on the 'size-allocate' event of the TextView element
instead. This event gets triggered on all size changes of the
TextViews.
In the call back use the ScrolledWindow methods to correctly scroll
to the end of its child (the TextView).
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
src/PVE/HA/Sim/RTHardware.pm | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/PVE/HA/Sim/RTHardware.pm b/src/PVE/HA/Sim/RTHardware.pm
index 02c0589..2076c0a 100644
--- a/src/PVE/HA/Sim/RTHardware.pm
+++ b/src/PVE/HA/Sim/RTHardware.pm
@@ -290,8 +290,6 @@ sub append_text {
my $end = $textbuf->get_iter_at_line($lines - $history);
$textbuf->delete($start, $end);
}
-
- $logview->scroll_to_mark($textbuf->get_insert(), 0.0, 1, 0.0, 1.0);
}
sub set_power_state {
@@ -508,6 +506,17 @@ sub create_log_view {
$swindow->set_size_request(1024, 768);
$swindow->add($logview);
+ $self->{gui}->{text_view_swindow} = $swindow;
+
+ $logview->signal_connect('size-allocate' => sub {
+ my $swindow = $self->{gui}->{text_view_swindow};
+
+ # swindows V-adjustment controls the child vertical scrollbar, set it to
+ # its upper bound to scroll to the end every time child's size changes
+ my $adjustment = $swindow->get_vadjustment();
+ $adjustment->set_value($adjustment->get_upper());
+ });
+
$nb->insert_page($swindow, $l1, 0);
my $l2 = Gtk3::Label->new('Manager Status');
--
2.1.4
More information about the pve-devel
mailing list