Skip to content

Commit

Permalink
added tabbing as additional key event listener.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpinyOwl committed Nov 12, 2017
1 parent 3d99486 commit eac5f4a
Show file tree
Hide file tree
Showing 9 changed files with 541 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,3 +8,4 @@
hs_err_pid*
/logs/

*.class
118 changes: 94 additions & 24 deletions src/main/java/org/liquidengine/legui/component/Component.java
Expand Up @@ -19,8 +19,10 @@
import org.joml.Vector4f;
import org.liquidengine.legui.border.Border;
import org.liquidengine.legui.color.ColorConstants;
import org.liquidengine.legui.component.misc.listener.component.TabKeyEventListener;
import org.liquidengine.legui.component.misc.listener.component.TooltipCursorEnterListener;
import org.liquidengine.legui.event.CursorEnterEvent;
import org.liquidengine.legui.event.KeyEvent;
import org.liquidengine.legui.intersection.Intersector;
import org.liquidengine.legui.intersection.RectangleIntersector;
import org.liquidengine.legui.listener.ListenerMap;
Expand Down Expand Up @@ -104,6 +106,16 @@ public abstract class Component implements Serializable {
*/
private Tooltip tooltip;

/**
* Tab index. Used to switch between components using tab key.
*/
private int tabIndex;

/**
* Show if component can be focused by tabbing.
*/
private boolean tabFocusable = true;

////////////////////////////////
//// CONTAINER BASE DATA
////////////////////////////////
Expand Down Expand Up @@ -152,6 +164,7 @@ public Component(Vector2f position, Vector2f size) {
*/
private void initialize() {
getListenerMap().addListener(CursorEnterEvent.class, new TooltipCursorEnterListener());
getListenerMap().addListener(KeyEvent.class, new TabKeyEventListener());
Themes.getDefaultTheme().getThemeManager().getComponentTheme(Component.class).applyAll(this);
}

Expand Down Expand Up @@ -392,6 +405,7 @@ public void setVisible(boolean visible) {
* Used to determine if point intersects component (in screen space). This method uses component intersector.
*
* @param point point to check.
*
* @return true if component intersected by point.
*/
public boolean intersects(Vector2f point) {
Expand Down Expand Up @@ -551,6 +565,42 @@ public void setTooltip(Tooltip tooltip) {
}
}

/**
* Returns tab index.
*
* @return tab index.
*/
public int getTabIndex() {
return tabIndex;
}

/**
* Used to set tab index.
*
* @param tabIndex tab index.
*/
public void setTabIndex(int tabIndex) {
this.tabIndex = tabIndex;
}

/**
* Returns true if component focused by tabbing.
*
* @return true if component focused by tabbing.
*/
public boolean isTabFocusable() {
return tabFocusable;
}

/**
* Used to set tab affecting for component.
*
* @param tabFocusable new tab affecting state.
*/
public void setTabFocusable(boolean tabFocusable) {
this.tabFocusable = tabFocusable;
}

/////////////////////////////////
//// CONTAINER METHODS
/////////////////////////////////
Expand All @@ -559,6 +609,7 @@ public void setTooltip(Tooltip tooltip) {
* Returns count of child components.
*
* @return count of child components.
*
* @see List#size()
*/
public int count() {
Expand All @@ -569,6 +620,7 @@ public int count() {
* Returns true if layerFrame contains no elements.
*
* @return true if layerFrame contains no elements.
*
* @see List#isEmpty()
*/
public boolean isEmpty() {
Expand All @@ -579,7 +631,9 @@ public boolean isEmpty() {
* Returns true if layerFrame contains specified component.
*
* @param component component to check.
*
* @return true if layerFrame contains specified component.
*
* @see List#contains(Object)
*/
public boolean contains(Component component) {
Expand All @@ -590,6 +644,7 @@ public boolean contains(Component component) {
* Returns an iterator over the elements in this layerFrame. The elements are returned in no particular order.
*
* @return an iterator over the elements in this layerFrame.
*
* @see List#iterator()
*/
public Iterator<Component> containerIterator() {
Expand All @@ -600,7 +655,9 @@ public Iterator<Component> containerIterator() {
* Used to add component to layerFrame.
*
* @param component component to add.
*
* @return true if component is added.
*
* @see List#add(Object)
*/
public boolean add(Component component) {
Expand All @@ -618,6 +675,7 @@ public boolean add(Component component) {
* Used to check if component collection contains component or not. Checked by reference.
*
* @param component component to check.
*
* @return true if collection contains provided component.
*/
private boolean isContains(Component component) {
Expand All @@ -628,7 +686,9 @@ private boolean isContains(Component component) {
* Used to add components.
*
* @param components components nodes to add.
*
* @return true if added.
*
* @see List#addAll(Collection)
*/
public boolean addAll(Collection<? extends Component> components) {
Expand Down Expand Up @@ -666,7 +726,9 @@ private void changeParent(Component component) {
* Used to remove component.
*
* @param component component to remove.
*
* @return true if removed.
*
* @see List#remove(Object)
*/
public boolean remove(Component component) {
Expand All @@ -687,6 +749,7 @@ public boolean remove(Component component) {
* Used to remove components.
*
* @param components components to remove.
*
* @see List#removeAll(Collection)
*/
public void removeAll(Collection<? extends Component> components) {
Expand All @@ -705,7 +768,9 @@ public void removeAll(Collection<? extends Component> components) {
* are relayed to the caller.
*
* @param filter a predicate which returns true for elements to be removed.
*
* @return true if any components were removed.
*
* @see List#removeIf(Predicate)
*/
public boolean removeIf(Predicate<? super Component> filter) {
Expand All @@ -727,7 +792,9 @@ public void clearChilds() {
* Returns true if this Container contains all of the elements of the specified collection.
*
* @param components components collection to check.
*
* @return true if this Container contains all of the elements of the specified collection.
*
* @see List#containsAll(Collection)
*/
public boolean containsAll(Collection<Component> components) {
Expand All @@ -738,6 +805,7 @@ public boolean containsAll(Collection<Component> components) {
* Returns a sequential Stream with this collection as its source.
*
* @return a sequential Stream with this collection as its source.
*
* @see List#stream()
*/
public Stream<Component> stream() {
Expand All @@ -748,6 +816,7 @@ public Stream<Component> stream() {
* Returns a possibly parallel Stream with this collection as its source. It is allowable for this method to return a sequential stream.
*
* @return possibly parallel Stream with this collection as its source.
*
* @see List#parallelStream()
*/
public Stream<Component> parallelStream() {
Expand Down Expand Up @@ -787,37 +856,37 @@ public boolean equals(Object o) {
Component component = (Component) o;

return new EqualsBuilder()
.append(this.getCornerRadius(), component.getCornerRadius())
.append(this.isEnabled(), component.isEnabled())
.append(this.isVisible(), component.isVisible())
.append(this.isHovered(), component.isHovered())
.append(this.isFocused(), component.isFocused())
.append(this.isPressed(), component.isPressed())
.append(this.getListenerMap(), component.getListenerMap())
.append(this.getPosition(), component.getPosition())
.append(this.getSize(), component.getSize())
.append(this.getBackgroundColor(), component.getBackgroundColor())
.append(this.getBorder(), component.getBorder())
.append(this.getIntersector(), component.getIntersector())
.append(this.cornerRadius, component.cornerRadius)
.append(this.enabled, component.enabled)
.append(this.visible, component.visible)
.append(this.hovered, component.hovered)
.append(this.focused, component.focused)
.append(this.pressed, component.pressed)
.append(this.listenerMap, component.listenerMap)
.append(this.position, component.position)
.append(this.size, component.size)
.append(this.backgroundColor, component.backgroundColor)
.append(this.border, component.border)
.append(this.intersector, component.intersector)
.append(components, component.components)
.isEquals();
}

@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(getCornerRadius())
.append(getListenerMap())
.append(getPosition())
.append(getSize())
.append(getBackgroundColor())
.append(getBorder())
.append(isEnabled())
.append(isVisible())
.append(getIntersector())
.append(isHovered())
.append(isFocused())
.append(isPressed())
.append(cornerRadius)
.append(listenerMap)
.append(position)
.append(size)
.append(backgroundColor)
.append(border)
.append(enabled)
.append(visible)
.append(intersector)
.append(hovered)
.append(focused)
.append(pressed)
.append(components)
.toHashCode();
}
Expand All @@ -839,4 +908,5 @@ public String toString() {
.append("pressed", pressed)
.toString();
}

}
Expand Up @@ -81,20 +81,24 @@ private void initialize() {
verticalScrollBar.setSize(INITIAL_SCROLL_SIZE, viewportHeight);
verticalScrollBar.setOrientation(Orientation.VERTICAL);
verticalScrollBar.setViewport(this);
verticalScrollBar.setTabFocusable(false);

horizontalScrollBar = new ScrollBar();
horizontalScrollBar.setPosition(0, viewportHeight);
horizontalScrollBar.setSize(viewportWidth, INITIAL_SCROLL_SIZE);
horizontalScrollBar.setOrientation(Orientation.HORIZONTAL);
horizontalScrollBar.setViewport(this);
horizontalScrollBar.setTabFocusable(false);

viewport = new Panel(0, 0, viewportWidth, viewportHeight);
viewport.setBackgroundColor(1, 1, 1, 0);
viewport.setBorder(null);
viewport.getListenerMap().addListener(ScrollEvent.class, new ScrollablePanelViewportScrollListener());
viewport.setTabFocusable(false);

container = new Panel(0, 0, viewportWidth, viewportHeight);
container.setBorder(null);
container.setTabFocusable(false);
viewport.add(container);

this.add(viewport);
Expand Down
49 changes: 27 additions & 22 deletions src/main/java/org/liquidengine/legui/component/Widget.java
Expand Up @@ -127,35 +127,39 @@ public Widget(String title, Vector2f position, Vector2f size) {
* @param title title to set.
*/
private void initialize(String title) {
this.titleContainer = new Panel();
this.titleContainer.getSize().y = INITIAL_TITLE_HEIGHT;
this.titleContainer.setBackgroundColor(ColorConstants.white());
titleContainer = new Panel();
titleContainer.getSize().y = INITIAL_TITLE_HEIGHT;
titleContainer.setBackgroundColor(ColorConstants.white());
titleContainer.setTabFocusable(false);

this.title = new Label(title);
this.title.setPosition(0, 0);
this.title.getSize().y = INITIAL_TITLE_HEIGHT;
this.title.getTextState().getPadding().set(10, 5, 10, 5);
this.title.setBackgroundColor(ColorConstants.transparent());
this.title.setBorder(null);
this.title.setTabFocusable(false);

mouseDragEventLeguiEventListener = new WidgetDragListener(this);
this.title.getListenerMap().addListener(MouseDragEvent.class, mouseDragEventLeguiEventListener);

this.closeButton = new Button("");
this.closeButton.setBackgroundColor(ColorConstants.transparent());
closeButton = new Button("");
closeButton.setBackgroundColor(ColorConstants.transparent());
closeIcon = new CharIcon(new Vector2f(INITIAL_TITLE_HEIGHT * 2 / 3), FontRegistry.MATERIAL_DESIGN_ICONS, (char) CLOSE_ICON_CHAR,
ColorConstants.black());
closeIcon.setHorizontalAlign(HorizontalAlign.CENTER);
closeIcon.setVerticalAlign(VerticalAlign.MIDDLE);
this.closeButton.setBackgroundIcon(closeIcon);
closeButton.setBackgroundIcon(closeIcon);

this.closeButton.getListenerMap().addListener(MouseClickEvent.class, new WidgetCloseButMouseClickEventListener(this));
this.closeButton.setBorder(null);
this.closeButton.getTextState().setVerticalAlign(VerticalAlign.MIDDLE);
this.closeButton.getTextState().setHorizontalAlign(HorizontalAlign.CENTER);
closeButton.getListenerMap().addListener(MouseClickEvent.class, new WidgetCloseButMouseClickEventListener(this));
closeButton.setBorder(null);
closeButton.getTextState().setVerticalAlign(VerticalAlign.MIDDLE);
closeButton.getTextState().setHorizontalAlign(HorizontalAlign.CENTER);
closeButton.setTabFocusable(false);

this.minimizeButton = new Button("");
this.minimizeButton.setBackgroundColor(ColorConstants.transparent());
minimizeButton = new Button("");
minimizeButton.setBackgroundColor(ColorConstants.transparent());
minimizeButton.setTabFocusable(false);

minimizeIcon = new CharIcon(new Vector2f(INITIAL_TITLE_HEIGHT * 2 / 3), FontRegistry.MATERIAL_DESIGN_ICONS, (char) MINIMIZE_ICON_CHAR,
ColorConstants.black());
Expand All @@ -167,21 +171,22 @@ private void initialize(String title) {
maximizeIcon.setHorizontalAlign(HorizontalAlign.CENTER);
maximizeIcon.setVerticalAlign(VerticalAlign.MIDDLE);

this.minimizeButton.setBackgroundIcon(minimizeIcon);
minimizeButton.setBackgroundIcon(minimizeIcon);

this.minimizeButton.getListenerMap().addListener(MouseClickEvent.class, new WidgetMinimizeButMouseClickEventListener(this));
this.minimizeButton.setBorder(null);
this.minimizeButton.getTextState().setVerticalAlign(VerticalAlign.MIDDLE);
this.minimizeButton.getTextState().setHorizontalAlign(HorizontalAlign.CENTER);
minimizeButton.getListenerMap().addListener(MouseClickEvent.class, new WidgetMinimizeButMouseClickEventListener(this));
minimizeButton.setBorder(null);
minimizeButton.getTextState().setVerticalAlign(VerticalAlign.MIDDLE);
minimizeButton.getTextState().setHorizontalAlign(HorizontalAlign.CENTER);

this.container = new Panel();
container = new Panel();
container.setTabFocusable(false);

titleContainer.add(this.title);
titleContainer.add(this.closeButton);
titleContainer.add(this.minimizeButton);
titleContainer.add(closeButton);
titleContainer.add(minimizeButton);

this.add(this.titleContainer);
this.add(this.container);
add(titleContainer);
add(container);

Themes.getDefaultTheme().getThemeManager().getComponentTheme(Widget.class).applyAll(this);

Expand Down

0 comments on commit eac5f4a

Please sign in to comment.