SonyWWS / ATF

Authoring Tools Framework (ATF) is a set of C#/.NET components for making tools on Windows. ATF has been in continuous development in Sony Computer Entertainment's (SCE) Worldwide Studios central tools group since early 2005. ATF has been used by most SCE first party studios to make many custom tools such as Naughty Dog’s level editor and shader editor for The Last of Us, Guerrilla Games’ sequence editor for Killzone games (including the Killzone: Shadow Fall PS4 launch title), an animation blending tool at Santa Monica Studio, a level editor at Bend Studio, a visual state machine editor for Quantic Dream, sound editing tools, and many others.
Apache License 2.0
1.89k stars 262 forks source link

Set size of floating pane from code #7

Closed fuleshu closed 10 years ago

fuleshu commented 10 years ago

Hi, I have trouble finding a way to resize a floating pane by code. I create the pane this way:

ControlInfo cinfo = new ControlInfo("Menu view", "Menu viewer", StandardControlGroup.Floating); m_controlHostService.RegisterControl(m_designControl, cinfo, null);

I can resize the pane with the mouse without problems. But I want to set the size by code. When I set the control's Width or Height or ClientSize, it is just be ignored. Also SetBounds did not work.

I would also like to recognize, when the pane becomes floating, to set the size once the user undocks it from the main windows.

Any ideas how I could do that?

jhshen commented 10 years ago

ATF uses DockPanelSuite for docking layout, so I would think you need to control the size of a float window via DockPanelSuite which manages all the Forms controls. Try DockContent.Show(DockPanel dockPanel, Rectangle floatWindowBounds); you may get access of DockContent from ControlHostService.cs.

The other alternative may be using Windows ->Layouts command to save the desired layout.

Ron2 commented 10 years ago

Yeah, the ability to control the width and height of a docked panel programmatically is a bit tricky. You can get at the WeifenLuo.WinFormsUI.Docking.DockPanel that is the parent of your Control, like Shen says.

Another way is to use ControlHostService.GetPanel(Control) to get the panel and then you can call ControlHostService.SetPanelPortion() to specify which percentage (0 to 1) or absolute pixels each portion of the panel should occupy.

If you want to set the default arrangement of Controls that a user of your tool first starts with, you can create a DefaultSettings.xml file. See SettingsService.DefaultSettingsPath. So, you could manually (with a mouse) set up the GUI like you want, then copy the AppSettings.xml file and rename it to DefaultSettings.xml file, which you would include with your app. The user's own settings (AppSettings.xml) will take precedence over whatever is in DefaultSettings.xml. There may be settings in AppSettings.xml that you don't want in DefaultSettings.xml, so you might have to clean up DefaultSettings.xml with a text editor.

There's also the WindowsLayoutService which allows you to create and save named Windows layouts. You could include a couple of pre-defined layouts with your app. Guerrilla Games' CoreText Editor uses this component, to allow their users to switch between a timeline view and a circuit layout view. The layouts and associated commands appear in View -> Layouts.

To set a pane's size when it becomes floating, you could set the pane's Width and Height to the desired value, and then when the user undocks it, the original Width and Height should be used. You can do this manually, by resizing a floating pane with your mouse, then docking it, then undocking it, and you'll see the size being restored. The undocked size will be (or should be!) persisted in the user settings.

I don't know for sure how to detect if a pane becomes floating. There will be events when its Parent is set to null, for example.