Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custimizable TitleRenderer callback for tab titles #759

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

PerBothner
Copy link
Contributor

This implements a customization hook that allows an application to customize how tab titles are drawn. It is based on this comment. It provides part of the needed functionality for issue #736 - it allows customizing the title part of an individual tab, but does not provide any mechanism to further customize headers, (That is a problem for another day, and can build on this PR.)

The hook is a function that has type TitleRenderer and is registered by container.setTitleRenderer. As an example of how it is used in DomTerm:

r.setTitleRenderer((container, el, width, flags) => {
   if (wname &&
        ((flags & Tab.RenderFlags.InDropdownMenu) ||
         ! (flags & Tab.RenderFlags.DropdownActive))) {
        el.innerHTML =
            DomTerm.escapeText(title)+'<span class="domterm-windowname"> '+DomTerm.escapeText(wname)+'</span>';
    } else {
        el.innerText = title;
    }
});

The functions takes four argument:

  • The container that corresponds to the Tab.
  • The lm_title element to "paint". The function is responsible for reusing or removing existing children. This allows reuse of title components, which may sometimes be a worthwhile optimization. Existing children are automatically replaced by innerHTML or innerText, which is while the example doesn't do it explicitly.
  • The available width for the title. This is a hint which the function can ignore, but in that case the caller can enforce it.
  • A set of flags: DropdownActive if there is a drop-down menu in the header; InDropdownMenu if we're creating the drop-down menu; IsActiveTab if the tab is active.

This is working acceptably for me in DomTerm, but should be considered a work-in-process. Most specifically, the tryUpdateTabSizes function in tabs-container.ts needs some polishing. For example, if space is tight, we could and should remove the close button for inactive tabs. It also needs some work to truncate a tab title if necessary.

This builds on PR #737. I've made some progress some progress is using HTML drag-and-drop (issue #680): I can drag and sort-of-drop a component from one top-level window to another. However, I'd like to move forward on customizing titles so I don't have too many changes at once - but regardless using the draggable attribute seems a good step.

This follows the conventions of the HTML5 drag-and-drop API,
and replaces the _extraAllowableChildTargets property.
This replaces the long-title branch and pull-request.
This was referenced Jan 16, 2022
@PerBothner
Copy link
Contributor Author

I checked in some polishing of the logic to layout tabs headers. I think it is pretty good now.

One new feature is "tight mode", indicated by adding lm_tight_mode to the lm_header. It is set when there isn't enough space in normal mode. Most significantly, it remove the close button from non-active tabs. It also reduces some padding. Further reductions could be done to tighten things up.

The overlap logic is enhanced. The active tab has highest z-index, and then drops off on either side. Overlap is added whenever the active tab is partially hidden. Very narrow windows degrade in a much nicer way.

@PerBothner PerBothner mentioned this pull request Jan 21, 2022
@PerBothner
Copy link
Contributor Author

I optimized updateTabSizes by wrapping it in a requestAnimationFrame.

Some tweaks when really low on space and dropdownActive:
Don't overlap tabs too much, unless needed for active tab.
PerBothner added a commit to PerBothner/DomTerm that referenced this pull request Feb 12, 2022
This is on git@github.com:PerBothner/golden-layout.git
See golden-layout/golden-layout#759
@WillooWisp
Copy link

@PerBothner any news about this PR actually being merged and released?

@PerBothner
Copy link
Contributor Author

@WillooWisp Sorry, none of the maintainers seem to have time for GoldenLayout.
You are of course free to use my fork. The d-n-d-api branch is what I'm using and maintaining. Expect some slight incompatibilies and some internal lack of polish: Given the lack of upstream activity, polishing hasn't been a priority; I've prioritized what I need for DomTerm. However, if you run into problems, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants