Skip to content

Commit

Permalink
Initial scroll pane implementation
Browse files Browse the repository at this point in the history
Affects: #14
Affects: #13
  • Loading branch information
io7m committed Nov 26, 2023
1 parent 86dd089 commit fc61b5d
Show file tree
Hide file tree
Showing 30 changed files with 1,304 additions and 21 deletions.
Expand Up @@ -17,7 +17,10 @@
package com.io7m.jsycamore.api.components;

/**
* The basic type of button components.
* <p>The basic type of button components.</p>
* <p>A button is a component that notifies a listener when clicked.</p>
* <p>The button has a "momentary" action; every time the mouse is clicked
* on the button, the listener is notified when the mouse button is released.</p>
*/

public interface SyButtonType
Expand Down
Expand Up @@ -17,7 +17,11 @@
package com.io7m.jsycamore.api.components;

/**
* The basic type of checkbox components.
* <p>The basic type of checkbox components.</p>
* <p>A checkbox is similar to a button except that the checkbox is toggled
* by clicking it.</p>
*
* @see SyButtonType
*/

public interface SyCheckboxType
Expand Down
Expand Up @@ -53,21 +53,13 @@ public SyConstraints(
final int sizeMaximumY)
{
this.sizeMinimumX =
clamp(0, MAX_VALUE, sizeMinimumX);
Math.clamp(sizeMinimumX, 0, MAX_VALUE);
this.sizeMaximumX =
clamp(this.sizeMinimumX, MAX_VALUE, sizeMaximumX);
Math.clamp(sizeMaximumX, this.sizeMinimumX, MAX_VALUE);
this.sizeMinimumY =
clamp(0, MAX_VALUE, sizeMinimumY);
Math.clamp(sizeMinimumY, 0, MAX_VALUE);
this.sizeMaximumY =
clamp(this.sizeMinimumY, MAX_VALUE, sizeMaximumY);
}

private static int clamp(
final int min,
final int max,
final int v)
{
return Math.max(min, min(max, v));
Math.clamp(sizeMaximumY, this.sizeMinimumY, MAX_VALUE);
}

/**
Expand Down Expand Up @@ -108,8 +100,8 @@ public <T extends SySpaceType> PAreaSizeI<T> sizeWithin(
final int sizeY)
{
return PAreaSizeI.of(
clamp(this.sizeMinimumX, this.sizeMaximumX, sizeX),
clamp(this.sizeMinimumY, this.sizeMaximumY, sizeY)
Math.clamp(sizeX, this.sizeMinimumX, this.sizeMaximumX),
Math.clamp(sizeY, this.sizeMinimumY, this.sizeMaximumY)
);
}

Expand Down Expand Up @@ -186,4 +178,66 @@ public SyConstraints deriveLimitedBy(
min(this.sizeMaximumY(), size.sizeY())
);
}

/**
* Derive a new set of constraints where the new maximum width has the given
* size subtracted from it.
*
* @param size The size to subtract
*
* @return A new set of constraints
*/

public SyConstraints deriveSubtractMaximumWidth(
final int size)
{
return new SyConstraints(
this.sizeMinimumX,
this.sizeMinimumY,
this.sizeMaximumX - size,
this.sizeMaximumY
);
}

/**
* Derive a new set of constraints where the new maximum height has the given
* size subtracted from it.
*
* @param size The size to subtract
*
* @return A new set of constraints
*/

public SyConstraints deriveSubtractMaximumHeight(
final int size)
{
return new SyConstraints(
this.sizeMinimumX,
this.sizeMinimumY,
this.sizeMaximumX,
this.sizeMaximumY - size
);
}

/**
* Derive a new set of constraints where the new maximum width and height
* values have the given sizes subtracted from them.
*
* @param sizeX The X size to subtract
* @param sizeY The Y size to subtract
*
* @return A new set of constraints
*/

public SyConstraints deriveSubtractMaximumSizes(
final int sizeX,
final int sizeY)
{
return new SyConstraints(
this.sizeMinimumX,
this.sizeMinimumY,
this.sizeMaximumX - sizeX,
this.sizeMaximumY - sizeY
);
}
}
Expand Up @@ -49,6 +49,17 @@ public interface SyScrollBarReadableType

double scrollPositionSnapping();

/**
* Based on the current snapping setting and scrollbar size, determine a
* reasonable value to use to increment or decrement the current scroll
* position. This is used to implement up/down/left/right arrow buttons
* on scrollbars.
*
* @return The size of a single scroll increment in the range {@code [0, 1]}
*/

double scrollIncrementSize();

/**
* @return The scrollbar presence policy
*/
Expand Down
@@ -0,0 +1,68 @@
/*
* Copyright © 2023 Mark Raynsford <code@io7m.com> https://www.io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


package com.io7m.jsycamore.api.components;

/**
* Read-only access to a scroll pane.
*/

public interface SyScrollPaneReadableType
extends SyComponentReadableType
{
/**
* @return A readable reference to the internal content region
*/

SyComponentReadableType contentArea();

/**
* @return A readable reference to the horizontal scroll bar
*/

SyScrollBarHorizontalReadableType scrollBarHorizontal();

/**
* @return A readable reference to the vertical scroll bar
*/

SyScrollBarVerticalReadableType scrollBarVertical();

/**
* @return The default listener executed when clicking on a scrollbar button
*/

Runnable onScrollClickLeftListener();

/**
* @return The default listener executed when clicking on a scrollbar button
*/

Runnable onScrollClickRightListener();

/**
* @return The default listener executed when clicking on a scrollbar button
*/

Runnable onScrollClickUpListener();

/**
* @return The default listener executed when clicking on a scrollbar button
*/

Runnable onScrollClickDownListener();
}
@@ -0,0 +1,49 @@
/*
* Copyright © 2023 Mark Raynsford <code@io7m.com> https://www.io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


package com.io7m.jsycamore.api.components;

import com.io7m.jregions.core.parameterized.sizes.PAreaSizeI;
import com.io7m.jsycamore.api.spaces.SySpaceParentRelativeType;

/**
* <p>The type of scroll panes.</p>
* <p>A scroll pane provides a scrollable viewport into a much larger internal
* content region.</p>
*/

public interface SyScrollPaneType
extends SyComponentType, SyScrollPaneReadableType
{
@Override
SyComponentType contentArea();

/**
* Set the fixed size of the internal content region.
*
* @param size The size
*/

void setContentAreaSize(
PAreaSizeI<SySpaceParentRelativeType> size);

@Override
SyScrollBarHorizontalType scrollBarHorizontal();

@Override
SyScrollBarVerticalType scrollBarVertical();
}
Expand Up @@ -169,9 +169,6 @@ public enum SyThemeClassNameStandard

SCROLLBAR_HORIZONTAL_BUTTON_THUMB_ICON("ScrollbarHorizontalButtonThumbIcon"),




/**
* A horizontal scrollbar class.
*/
Expand Down Expand Up @@ -220,6 +217,24 @@ public enum SyThemeClassNameStandard

SCROLLBAR_VERTICAL_BUTTON_THUMB_ICON("ScrollbarVerticalButtonThumbIcon"),

/**
* A scrollpane class.
*/

SCROLLPANE("ScrollPane"),

/**
* A scrollpane content area class.
*/

SCROLLPANE_CONTENT_AREA("ScrollPaneContentArea"),

/**
* A scrollpane content area viewport class.
*/

SCROLLPANE_CONTENT_AREA_VIEWPORT("ScrollPaneContentAreaViewport"),

/**
* A text area class.
*/
Expand Down
Expand Up @@ -364,10 +364,19 @@ public final JOTreeNodeType<SyComponentType> node()
@Override
public final String toString()
{
final var currentSize =
this.size.get();
final var currentPosition =
this.position.get();

return String.format(
"[%s 0x%s]",
"[%s 0x%s %dx%d %d,%d]",
this.getClass().getSimpleName(),
Integer.toUnsignedString(this.hashCode(), 16)
Integer.toUnsignedString(this.hashCode(), 16),
Integer.valueOf(currentSize.sizeX()),
Integer.valueOf(currentSize.sizeY()),
Integer.valueOf(currentPosition.x()),
Integer.valueOf(currentPosition.y())
);
}
}
@@ -0,0 +1,61 @@
/*
* Copyright © 2023 Mark Raynsford <code@io7m.com> https://www.io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


package com.io7m.jsycamore.components.standard;

import com.io7m.jsycamore.api.components.SyScrollPaneType;
import com.io7m.jsycamore.api.themes.SyThemeClassNameType;
import com.io7m.jsycamore.components.standard.internal.scrollpanes.SyScrollPane;

import java.util.List;

/**
* Functions to create scroll panes.
*/

public final class SyScrollPanes
{
private SyScrollPanes()
{

}

/**
* Create a scroll pane.
*
* @param themeClassesExtra The extra theme classes
*
* @return A scroll pane
*/

public static SyScrollPaneType create(
final List<SyThemeClassNameType> themeClassesExtra)
{
return new SyScrollPane(themeClassesExtra);
}

/**
* Create a scroll pane.
*
* @return A scroll pane
*/

public static SyScrollPaneType create()
{
return create(List.of());
}
}
Expand Up @@ -256,6 +256,12 @@ public void removeOnThumbDragListener()
this.track.removeOnThumbDragListener();
}

@Override
public double scrollIncrementSize()
{
return this.track.scrollIncrementSize();
}

@Override
public void setScrollPosition(
final double position)
Expand Down

0 comments on commit fc61b5d

Please sign in to comment.