Skip to content

Commit

Permalink
Large refactoring
Browse files Browse the repository at this point in the history
Explicitly require all components to have a screen reference. This
allows them reliable access to various services at all times.

Implement multi-line text views with selection.
Implement scrollable text areas.

Affects: #42
Affects: #14
Affects: #13
  • Loading branch information
io7m committed Dec 3, 2023
1 parent ddb4158 commit 0f960a4
Show file tree
Hide file tree
Showing 214 changed files with 9,704 additions and 2,344 deletions.
4 changes: 4 additions & 0 deletions com.io7m.jsycamore.api/pom.xml
Expand Up @@ -41,6 +41,10 @@
<groupId>com.io7m.jcolorspace</groupId>
<artifactId>com.io7m.jcolorspace.core</artifactId>
</dependency>
<dependency>
<groupId>com.io7m.repetoir</groupId>
<artifactId>com.io7m.repetoir.core</artifactId>
</dependency>

<dependency>
<groupId>com.io7m.jcip</groupId>
Expand Down
Expand Up @@ -37,14 +37,6 @@ private SyColors()

}

private static double clamp(
final double x,
final double min,
final double max)
{
return Math.min(Math.max(x, min), max);
}

/**
* @return An opaque white color
*/
Expand All @@ -66,9 +58,9 @@ public static PVector4D<SySpaceRGBAPreType> lighter(
final PVector4D<SySpaceRGBAPreType> color)
{
return PVector4D.of(
clamp(color.x() + 0.1, 0.0, 1.0),
clamp(color.y() + 0.1, 0.0, 1.0),
clamp(color.z() + 0.1, 0.0, 1.0),
Math.clamp(color.x() + 0.1, 0.0, 1.0),
Math.clamp(color.y() + 0.1, 0.0, 1.0),
Math.clamp(color.z() + 0.1, 0.0, 1.0),
color.w()
);
}
Expand All @@ -85,9 +77,9 @@ public static PVector4D<SySpaceRGBAPreType> darker(
final PVector4D<SySpaceRGBAPreType> color)
{
return PVector4D.of(
clamp(color.x() - 0.1, 0.0, 1.0),
clamp(color.y() - 0.1, 0.0, 1.0),
clamp(color.z() - 0.1, 0.0, 1.0),
Math.clamp(color.x() - 0.1, 0.0, 1.0),
Math.clamp(color.y() - 0.1, 0.0, 1.0),
Math.clamp(color.z() - 0.1, 0.0, 1.0),
color.w()
);
}
Expand Down Expand Up @@ -136,10 +128,29 @@ public static PVector4D<SySpaceRGBAPreType> fromHex4(
final int a)
{
return PVector4D.of(
clamp((double) r / 255.0, 0.0, 1.0),
clamp((double) g / 255.0, 0.0, 1.0),
clamp((double) b / 255.0, 0.0, 1.0),
clamp((double) a / 255.0, 0.0, 1.0)
Math.clamp((double) r / 255.0, 0.0, 1.0),
Math.clamp((double) g / 255.0, 0.0, 1.0),
Math.clamp((double) b / 255.0, 0.0, 1.0),
Math.clamp((double) a / 255.0, 0.0, 1.0)
);
}

/**
* Invert the values of the R, G, and B components.
*
* @param c The color
*
* @return A color
*/

public static PVector4D<SySpaceRGBAPreType> inverted(
final PVector4D<SySpaceRGBAPreType> c)
{
return PVector4D.of(
Math.clamp(1.0 - c.x(), 0.0, 1.0),
Math.clamp(1.0 - c.y(), 0.0, 1.0),
Math.clamp(1.0 - c.z(), 0.0, 1.0),
Math.clamp(c.w(), 0.0, 1.0)
);
}
}
Expand Up @@ -17,6 +17,7 @@
package com.io7m.jsycamore.api.components;

import com.io7m.jattribute.core.AttributeReadableType;
import com.io7m.jsycamore.api.text.SyText;

/**
* Read-only access to a button.
Expand All @@ -29,5 +30,5 @@ public interface SyButtonWithTextReadableType
* @return The button text
*/

AttributeReadableType<String> text();
AttributeReadableType<SyText> text();
}
Expand Up @@ -17,16 +17,17 @@
package com.io7m.jsycamore.api.components;

import com.io7m.jattribute.core.AttributeType;
import com.io7m.jsycamore.api.text.SyText;

/**
* The basic type of button components.
*/

public interface SyButtonWithTextType
extends SyButtonWithTextReadableType
extends SyButtonWithTextReadableType, SyButtonType
{
@Override
AttributeType<String> text();
AttributeType<SyText> text();

/**
* Set the button text.
Expand All @@ -35,7 +36,7 @@ public interface SyButtonWithTextType
*/

default void setText(
final String text)
final SyText text)
{
this.text().set(text);
}
Expand Down
Expand Up @@ -20,6 +20,7 @@
import com.io7m.jsycamore.api.active.SyActiveReadableType;
import com.io7m.jsycamore.api.bounded.SyBoundedReadableType;
import com.io7m.jsycamore.api.mouse.SyMouseFocusAcceptingReadableType;
import com.io7m.jsycamore.api.screens.SyScreenType;
import com.io7m.jsycamore.api.spaces.SySpaceParentRelativeType;
import com.io7m.jsycamore.api.spaces.SySpaceViewportType;
import com.io7m.jsycamore.api.themes.SyThemeableReadableType;
Expand All @@ -43,6 +44,12 @@ public interface SyComponentReadableType
SyBoundedReadableType<SySpaceParentRelativeType>,
SyThemeableReadableType
{
/**
* @return The screen that owns the component
*/

SyScreenType screen();

/**
* @return The window to which this component belongs
*/
Expand Down Expand Up @@ -201,10 +208,11 @@ default PVector2I<SySpaceParentRelativeType> relativePositionOf(
{
Objects.requireNonNull(position, "position");

final var base =
this.viewportPositionOf(PVectors2I.zero());
final var componentBase =
this.viewportPositionOf(this.position().get());

final var delta =
PVectors2I.subtract(position, base);
PVectors2I.subtract(position, componentBase);

return PVector2I.of(delta.x(), delta.y());
}
Expand Down
Expand Up @@ -17,6 +17,7 @@
package com.io7m.jsycamore.api.components;

import com.io7m.jattribute.core.AttributeReadableType;
import com.io7m.jsycamore.api.text.SyText;
import com.io7m.jsycamore.api.themes.SyThemeClassNameType;

import java.util.List;
Expand All @@ -40,7 +41,7 @@ default List<SyThemeClassNameType> themeClassesDefaultForComponent()
* @return The text sections within the area
*/

AttributeReadableType<List<String>> textSections();
AttributeReadableType<List<SyText>> textSections();

/**
* @return Access to the horizontal scrollbar
Expand Down
Expand Up @@ -16,6 +16,8 @@

package com.io7m.jsycamore.api.components;

import com.io7m.jsycamore.api.text.SyText;

/**
* Write access to text areas.
*/
Expand All @@ -29,7 +31,7 @@ public interface SyTextAreaType
* @param section The section
*/

void textSectionAppend(String section);
void textSectionAppend(SyText section);

@Override
SyScrollBarHorizontalType scrollbarHorizontal();
Expand Down
@@ -0,0 +1,73 @@
/*
* 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.jattribute.core.AttributeReadableType;
import com.io7m.jsycamore.api.layout.SyLayoutContextType;
import com.io7m.jsycamore.api.text.SyTextLineMeasuredType;
import com.io7m.jsycamore.api.themes.SyThemeClassNameType;

import java.util.List;
import java.util.SortedMap;

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

/**
* Read-only access to multi-line text views.
*/

public interface SyTextMultiLineViewReadableType
extends SyComponentReadableType
{
/**
* @return An attribute indicating if this text view is selectable
*/

AttributeReadableType<Boolean> textSelectable();

/**
* @return {@code true} if {@link #textSelectable()} is {@code true}
*/

default boolean isTextSelectable()
{
return this.textSelectable().get().booleanValue();
}

@Override
default List<SyThemeClassNameType> themeClassesDefaultForComponent()
{
return List.of(TEXT_MULTILINE_VIEW);
}

/**
* @return A read-only snapshot of the texts by Y offset
*/

SortedMap<Integer, SyTextLineMeasuredType> textsByYOffset();

/**
* Determine the minimum size on the Y axis required to display the
* contained text fully.
*
* @param layoutContext The layout context
*
* @return The minimum size on the Y axis
*/

int minimumSizeYRequired(SyLayoutContextType layoutContext);
}
@@ -0,0 +1,78 @@
/*
* 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.jattribute.core.AttributeType;
import com.io7m.jsycamore.api.text.SyText;
import com.io7m.jsycamore.api.text.SyTextMultiLineModelType;

import java.util.List;
import java.util.Objects;

/**
* Write access to multi-line text views.
*/

public interface SyTextMultiLineViewType
extends SyTextMultiLineViewReadableType, SyComponentType
{
/**
* @return An attribute indicating if this text view is selectable
*/

@Override
AttributeType<Boolean> textSelectable();

/**
* Set whether the text view is selectable.
*
* @param selectable {@code true} if the text view is selectable
*/

default void setTextSelectable(
final boolean selectable)
{
this.textSelectable().set(Boolean.valueOf(selectable));
}

/**
* Append a section of text.
*
* @param section The text section
*
* @see SyTextMultiLineModelType#textSectionAppend(SyText)
*/

default void textSectionAppend(
final SyText section)
{
this.textSectionsAppend(
List.of(Objects.requireNonNull(section, "section"))
);
}

/**
* Append sections of text.
*
* @param sections The text sections
*
* @see SyTextMultiLineModelType#textSectionsAppend(List)
*/

void textSectionsAppend(
List<SyText> sections);
}
Expand Up @@ -20,6 +20,7 @@
import com.io7m.jregions.core.parameterized.sizes.PAreaSizeI;
import com.io7m.jsycamore.api.layout.SyLayoutContextType;
import com.io7m.jsycamore.api.spaces.SySpaceParentRelativeType;
import com.io7m.jsycamore.api.text.SyText;
import com.io7m.jsycamore.api.themes.SyThemeClassNameType;

import java.util.List;
Expand All @@ -33,6 +34,21 @@
public interface SyTextViewReadableType
extends SyComponentReadableType
{
/**
* @return An attribute indicating if this text view is selectable
*/

AttributeReadableType<Boolean> textSelectable();

/**
* @return {@code true} if {@link #textSelectable()} is {@code true}
*/

default boolean isTextSelectable()
{
return this.textSelectable().get().booleanValue();
}

@Override
default List<SyThemeClassNameType> themeClassesDefaultForComponent()
{
Expand All @@ -54,5 +70,5 @@ PAreaSizeI<SySpaceParentRelativeType> minimumSizeRequired(
* @return The current text
*/

AttributeReadableType<String> text();
AttributeReadableType<SyText> text();
}

0 comments on commit 0f960a4

Please sign in to comment.