当使用带有水平策略 Never 的 Gtk ScrolledWindow 时,如果子级的水平大小请求发生变化,我希望滚动窗口能够适应。
但情况并非如此,例如在使用扩展器时:当我扩展扩展器时,子窗口比滚动窗口更宽,滚动窗口不会适应它的大小。
最小示例:
using System;
using Gtk;
namespace ExpanderIssue
{
class MainClass
{
static bool useExpander = true;
private static Widget createScrolledWindow(Widget child)
{
ScrolledWindow scrolledWindow = new ScrolledWindow();
scrolledWindow.SetPolicy(PolicyType.Never, PolicyType.Automatic);
scrolledWindow.AddWithViewport(child);
return scrolledWindow;
}
private static Widget createSingleExpaner(int index)
{
Button button = new Button(String.Format("ExampleButton {0}", index));
button.WidthRequest = 800;
if(useExpander) {
Expander expander = new Expander(String.Format("Expander {0}", index));
expander.Add(button);
return expander;
} else {
return button;
}
}
public static void Main(string[] args)
{
Application.Init();
createMainWindow();
Application.Run();
}
private static Window createMainWindow()
{
VBox vbox = new VBox();
vbox.Spacing = 4;
for(int i=0; i<32; ++i)
vbox.PackStart(createSingleExpaner(i), false, false, 0);
Window mainWindow = new Window("Expander Width Request issue");
mainWindow.SetDefaultSize(240, 160);
mainWindow.Add(createScrolledWindow(vbox));
mainWindow.ShowAll();
mainWindow.Destroyed += (sender, e) => Application.Quit();
return mainWindow;
}
}
}