Announcement
Collapse
No announcement yet.
X
-
If you want the button to be always visible, don't make it a TabBar control, instead, style the TarBar with some extra right padding (you could use the AutoChild system to set layoutEndMargin for example), and place the add button in the freed up space, as a child of the TabSet as a whole.
-
TabSet.setCanAddTabs(true) problem
when using a TabSet with the setCanAddTabs(true) property, I encountered one inconvenience. If I have so many Tabs that I have to scroll them, then the addTab button becomes invisible on the screen and I have to scroll to the end so that it becomes visible again.
I found a solution to this problem, but I don't like it. I'm sure you have a more elegant solution. Could you guide me on the right path?
Below is an example of my solution.
Code:public class TestBug implements EntryPoint { private ImgButton addListButton; private TabSet templatesTabSet; public void onModuleLoad() { addListButton = new ImgButton(); addListButton.setSrc("[SKIN]actions/add.png"); addListButton.setVisible(false); addListButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { addTab(); } }); TabBar tabBarProperties = new TabBar(); tabBarProperties.addMembersChangedHandler(new MembersChangedHandler() { @Override public void onMembersChanged(MembersChangedEvent event) { checkAddTabButton(); } }); tabBarProperties.addScrolledHandler(new ScrolledHandler() { @Override public void onScrolled(ScrolledEvent event) { checkAddTabButton(); } }); templatesTabSet = new TabSet(); templatesTabSet.setTabBarProperties(tabBarProperties); templatesTabSet.setTabBarControls(addListButton, TabBarControls.TAB_SCROLLER, TabBarControls.TAB_PICKER); templatesTabSet.setTabBarPosition(Side.TOP); templatesTabSet.setWidth(400); templatesTabSet.setHeight(400); templatesTabSet.setCanAddTabs(true); templatesTabSet.setCanCloseTabs(true); templatesTabSet.setCloseTabIcon("[SKIN]actions/remove.png"); templatesTabSet.addAddTabClickedHandler(new AddTabClickedHandler() { @Override public void onAddTabClicked(AddTabClickedEvent event) { addTab(); } }); templatesTabSet.addCloseClickHandler(new CloseClickHandler() { @Override public void onCloseClick(TabCloseClickEvent event) { templatesTabSet.removeTab(event.getTab()); } }); String[] titles = new String[] {"tab example 1", "tab example 2", "tab example 3", "tab example 4", "tab example 5", "tab example 6"}; for(String title:titles) { Tab tab = new Tab(title, "[SKINIMG]Dialog/say.png"); templatesTabSet.addTab(tab); } templatesTabSet.draw(); } private void addTab() { Tab[] tabs = templatesTabSet.getTabs(); Tab tab = new Tab("new tab example " + tabs.length); templatesTabSet.addTab(tab); templatesTabSet.selectTab(tab); } private void checkAddTabButton() { final Timer timer = new Timer() { @Override public void run() { cancel(); TabBar tabBar = templatesTabSet.getTabBar(); Canvas[] members = tabBar.getMembers(); if(members.length > 1) { Canvas lastTab = members[members.length - 1]; Boolean isVisible = addListButton.isVisible(); ImgButton addTabButton = templatesTabSet.getAddTabButton(); if((lastTab.getRight() - tabBar.getScrollLeft()) > templatesTabSet.getWidth()) { if(!isVisible) { addListButton.setVisible(true); addTabButton.setVisible(false); } } else { if(isVisible) { addListButton.setVisible(false); addTabButton.setVisible(true); } } } } }; timer.scheduleRepeating(100); } }
Last edited by Hirn; 15 Nov 2023, 13:32.Tags: None
Leave a comment: