4coder » Forums » Expand panel toggle
immortalx
John
15 posts
#21196 Expand panel toggle
3 weeks ago Edited by John on June 28, 2019, 5:32 a.m. Reason: Initial post

I just recently purchased 4coder and trying to dive into the customization layer. I'm also a beginner in C++ so bear with me!

I always use 2 panels side-by-side and have code wrapping enabled. I'd like to disable wrapping and have a toggle-binding that "expands" the active panel, and then restores the split panels with their buffers if it is pressed a second time.
I came up with the following command which does what I want. The only problem is I'm not aware of way to tell if the active panel is at the left or right of the other panel. I currently have it set up to always open a new panel to the right.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
CUSTOM_COMMAND_SIG(toggle_expand_active_panel)
{
    static bool expanded = false;
    int access = AccessAll;
    View_Summary view = get_active_view(app,access);
    static int32_t buffer_id;
    
    if (!expanded)
    {
	    change_active_panel(app);
		view = get_active_view(app,access);
	    buffer_id = view.buffer_id;
	    close_view(app, &view);
	}
	else
	{
		View_Summary newview = open_view(app, &view, ViewSplit_Right);
		change_active_panel(app);
		view_set_buffer(app, &newview, buffer_id, 0);
	}

	expanded = !expanded;
}


So what I'm looking for is a way to pass ViewSplit_Right/ViewSplit_Left to the open_view() function, depending on which panel has been previously expanded.
mrmixer
Simon Anciaux
633 posts
#21197 Expand panel toggle
3 weeks ago Edited by Simon Anciaux on June 28, 2019, 11:36 a.m. Reason: typo

I don't know if there is a way to know which view is which by default.

One way you could achieve this would be to mark the view yourself when they are created using a view managed scope, managed_variable_create, managed_variable_set and managed_variable_get.

I never used managed scope and variables so I can't really help you further but there are 3 blog posts on the subject:
Memory management overview
Memory management variables and objects
Memory management scopes.

A simpler way to achieve what you want is just to set the width of the desired view to 100% to hide the other view and set it back to 50% when you want both view again. It has the advantage of keeping your position in the view when you're looking at the same buffer in both views. The title bar text of the two buffers will overlap when you maximize the right view though.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
CUSTOM_COMMAND_SIG( maximize_panel ) {
    
    View_Summary view = get_active_view( app, AccessAll );
    view_set_split_proportion( app, &view, 1.0f );
}

CUSTOM_COMMAND_SIG( even_panel ) {
    
    View_Summary view = get_active_view( app, AccessAll );
    view_set_split_proportion( app, &view, 0.5f );
}

immortalx
John
15 posts
#21199 Expand panel toggle
3 weeks ago

That's a brilliant idea @mrmixer, I'm going to try it right away!
That would also be the right time to say a BIG thank you for your contribution to the community.
immortalx
John
15 posts
#21200 Expand panel toggle
2 weeks, 6 days ago

Well that worked absolutely fine, except for one small thing which seems to be a 4coder bug:
When the left panel is expanded everything is fine. But when the right panel is expanded, the filename rendered on the file bar is a "mix" of the filenames of the two panels. It looks like this:
mrmixer
Simon Anciaux
633 posts
#21201 Expand panel toggle
2 weeks, 6 days ago

That's what I meant by
mrmixer
The title bar text of the two buffers will overlap when you maximize the right view though.

I've already reported that bug to Allen.
immortalx
John
15 posts
#21202 Expand panel toggle
2 weeks, 6 days ago

Oh I'm sorry, I don't know how I missed that part of your post!