Skip to content

Commit

Permalink
Implement vertical scrollbars
Browse files Browse the repository at this point in the history
Refactor snapping.

Affects: #14
Affects: #13
  • Loading branch information
io7m committed Nov 25, 2023
1 parent 240e838 commit 86dd089
Show file tree
Hide file tree
Showing 25 changed files with 2,202 additions and 82 deletions.
Expand Up @@ -16,8 +16,6 @@

package com.io7m.jsycamore.api.components;

import java.util.function.Consumer;

/**
* Write access to scrollbars.
*/
Expand Down Expand Up @@ -56,20 +54,4 @@ public interface SyScrollBarHorizontalType
*/

void removeOnClickRightListener();

/**
* Set a listener that will be executed when the left scroll button is clicked.
*
* @param listener The listener
*/

void setOnThumbDragListener(Consumer<SyScrollBarDrag> listener);

/**
* Remove any listeners that are executed when the left button is clicked.
*
* @see #setOnThumbDragListener(Consumer)
*/

void removeOnThumbDragListener();
}
Expand Up @@ -18,6 +18,8 @@

import com.io7m.jattribute.core.AttributeType;

import java.util.function.Consumer;

/**
* Write access to scrollbars.
*/
Expand Down Expand Up @@ -59,4 +61,20 @@ public interface SyScrollBarType
*/

void setScrollAmountShown(double amount);

/**
* Set a listener that will be executed when the thumb is dragged.
*
* @param listener The listener
*/

void setOnThumbDragListener(Consumer<SyScrollBarDrag> listener);

/**
* Remove any listeners that are executed when the thumb is dragged.
*
* @see #setOnThumbDragListener(Consumer)
*/

void removeOnThumbDragListener();
}
@@ -0,0 +1,49 @@
/*
* Copyright © 2021 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.jsycamore.api.themes.SyThemeClassNameType;

import java.util.List;

import static com.io7m.jsycamore.api.themes.SyThemeClassNameStandard.SCROLLBAR_VERTICAL;

/**
* Read-only access to scrollbars.
*/

public interface SyScrollBarVerticalReadableType
extends SyScrollBarReadableType
{
@Override
default List<SyThemeClassNameType> themeClassesDefaultForComponent()
{
return List.of(SCROLLBAR_VERTICAL);
}

/**
* @return The scrollbar up button
*/

SyButtonReadableType buttonUp();

/**
* @return The scrollbar down button
*/

SyButtonReadableType buttonDown();
}
@@ -0,0 +1,57 @@
/*
* Copyright © 2021 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;

/**
* Write access to scrollbars.
*/

public interface SyScrollBarVerticalType
extends SyScrollBarVerticalReadableType, SyScrollBarType
{
/**
* Set a listener that will be executed when the up scroll button is clicked.
*
* @param runnable The listener
*/

void setOnClickUpListener(Runnable runnable);

/**
* Remove any listeners that are executed when the up button is clicked.
*
* @see #setOnClickUpListener(Runnable)
*/

void removeOnClickUpListener();

/**
* Set a listener that will be executed when the down scroll button is clicked.
*
* @param runnable The listener
*/

void setOnClickDownListener(Runnable runnable);

/**
* Remove any listeners that are executed when the down button is clicked.
*
* @see #setOnClickDownListener(Runnable)
*/

void removeOnClickDownListener();
}
@@ -0,0 +1,108 @@
/*
* 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.layout;

import com.io7m.jregions.core.parameterized.sizes.PAreaSizeI;
import com.io7m.jsycamore.api.spaces.SySpaceType;
import com.io7m.jtensors.core.parameterized.vectors.PVector2I;

import static java.lang.StrictMath.round;

/**
* Snapping functions.
*/

public final class SySnapping
{
private SySnapping()
{

}

/**
* Snap a real number {@code x} to a snapping value. The value of {@code f}
* is a fractional value in the range {@code [0, 1]}.
*
* @param x The number to be snapped
* @param f The snapping value
*
* @return The snapped value
*/

public static double snapDouble(
final double x,
final double f)
{
if (f == 0.0) {
return x;
}

final var p = 1.0 / f;
var r = x * p;
r = (double) round(r);
return r / p;
}

/**
* Snap the given vector. Each element of the vector will be snapped to the
* nearest multiple of {@code snapping}.
*
* @param v The vector
* @param snapping The snapping value
* @param <T> The vector space
*
* @return The vector
*/

public static <T extends SySpaceType> PVector2I<T> snapVector(
final PVector2I<T> v,
final int snapping)
{
if (snapping > 1) {
return PVector2I.of(
(v.x() / snapping) * snapping,
(v.y() / snapping) * snapping
);
}
return v;
}

/**
* Snap the given size. Each element of the size will be snapped to the
* nearest multiple of {@code snapping}.
*
* @param v The vector
* @param snapping The snapping value
* @param <T> The vector space
*
* @return The vector
*/

public static <T extends SySpaceType> PAreaSizeI<T> snapSize(
final PAreaSizeI<T> v,
final int snapping)
{
if (snapping > 1) {
return PAreaSizeI.of(
(v.sizeX() / snapping) * snapping,
(v.sizeY() / snapping) * snapping
);
}
return v;
}
}
Expand Up @@ -169,6 +169,57 @@ public enum SyThemeClassNameStandard

SCROLLBAR_HORIZONTAL_BUTTON_THUMB_ICON("ScrollbarHorizontalButtonThumbIcon"),




/**
* A horizontal scrollbar class.
*/

SCROLLBAR_VERTICAL("ScrollbarVertical"),

/**
* A horizontal scrollbar track class.
*/

SCROLLBAR_VERTICAL_TRACK("ScrollbarVerticalTrack"),

/**
* A scrollbar button class.
*/

SCROLLBAR_VERTICAL_BUTTON_UP("ScrollbarVerticalButtonUp"),

/**
* A scrollbar button icon class.
*/

SCROLLBAR_VERTICAL_BUTTON_UP_ICON("ScrollbarVerticalButtonUpIcon"),

/**
* A scrollbar button class.
*/

SCROLLBAR_VERTICAL_BUTTON_DOWN("ScrollbarVerticalButtonDown"),

/**
* A scrollbar button icon class.
*/

SCROLLBAR_VERTICAL_BUTTON_DOWN_ICON("ScrollbarVerticalButtonDownIcon"),

/**
* A scrollbar button class.
*/

SCROLLBAR_VERTICAL_BUTTON_THUMB("ScrollbarVerticalButtonThumb"),

/**
* A scrollbar button icon class.
*/

SCROLLBAR_VERTICAL_BUTTON_THUMB_ICON("ScrollbarVerticalButtonThumbIcon"),

/**
* A text area class.
*/
Expand Down
@@ -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.SyScrollBarVerticalType;
import com.io7m.jsycamore.api.themes.SyThemeClassNameType;
import com.io7m.jsycamore.components.standard.internal.scrollbars.SyScrollBarV;

import java.util.List;

/**
* Functions to create vertical scroll bars.
*/

public final class SyScrollBarsVertical
{
private SyScrollBarsVertical()
{

}

/**
* Create a vertical scrollbar.
*
* @param themeClassesExtra The extra theme classes
*
* @return A scrollbar
*/

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

/**
* Create a vertical scrollbar.
*
* @return A scrollbar
*/

public static SyScrollBarVerticalType create()
{
return create(List.of());
}
}

0 comments on commit 86dd089

Please sign in to comment.