A window with a flex layout widget has a horizontal scrollbar at the bottom. When the window is resized the scrollbar properly adjusts to the new size. The problem occurs when the scrollbar is hidden and then the window is resized. When the scrollbar is re-shown it appears in it's prior position. When the window is resized again the scrollbar will then snap to the new position and work properly. The following image shows the window after the scrollbar is re-shown. The scrollbar should be at the bottom of the window and have the new window width:
The following code can demonstrate the behavior:
// Testing the fltk scrollbar with hiding and resizing
// Be sure to have the following line in Cargo.toml after [dependencies]:
// fltk = { version = "1.4.15", features = ["fltk-bundled"] }
use fltk::{prelude::*, window::Window, enums::*, *};
fn main() {
let app = app::App::default();
let mut wind = Window::default()
.with_size(400, 100)
.with_label("Scrollbar hide test");
wind.make_resizable(true);
let mut col = group::Flex::default_fill().column();
col.set_pad(0);
let mut mbar: menu::MenuBar = menu::MenuBar::default();
col.fixed(&mbar, 25);
mbar.add(
"&Options/Hide scrollbar",
Shortcut::None,
menu::MenuFlag::Toggle,
menu_cb,
);
let mut _text = frame::Frame::default().with_label("Some text");
let mut _bar = valuator::Scrollbar::default()
.with_type(valuator::ScrollbarType::Horizontal);
col.fixed(&_bar, 20);
col.end();
wind.end();
wind.show();
app.run().unwrap();
}
fn menu_cb(mbar: &mut impl MenuExt) {
if let Ok(mpath) = mbar.item_pathname(None) {
if mpath.as_str() == "&Options/Hide scrollbar" {
let state = mbar.find_item("&Options/Hide scrollbar").unwrap().value();
let mut scroll = mbar.parent().unwrap().child(2).unwrap();
if state { scroll.hide(); }
else { scroll.show(); }
}
}
}
Take these steps to show the behavior:
- Start the program.
- Click "Options", then "Hide scrollbar". The scrollbar will disappear, but "Some text" doesn't lower to the middle.
- With mouse, drag the lower the window's lower-right corner down and to the right just a bit. "Some text" suddenly re-centers and then stays in the middle.
- Click "Options", then "Hide scrollbar" (thereby toggling it off). The scrollbar appears in its prior position, and "Some text" stays in the middle.
- Drag the window's lower-right corner again. The scrollbar will suddenly jump to its proper position and "Some text" will reposition itself properly.
Remedies? Is there a command I can issue so that everything is repositioned as if the window was resized, but instead the the scrollbar was hiddened/shown? Thanks in advance for any help.