Skip to content

Commit

Permalink
Implement text section replacement
Browse files Browse the repository at this point in the history
Affects: #48
Affects: #14
  • Loading branch information
io7m committed Dec 9, 2023
1 parent 11e89ca commit 4d15bfb
Show file tree
Hide file tree
Showing 20 changed files with 776 additions and 634 deletions.
Expand Up @@ -16,8 +16,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.text.SyTextMultiLineModelReadableType;
import com.io7m.jsycamore.api.themes.SyThemeClassNameType;

import java.util.List;
Expand All @@ -38,10 +37,10 @@ default List<SyThemeClassNameType> themeClassesDefaultForComponent()
}

/**
* @return The text sections within the area
* @return The underlying text model
*/

AttributeReadableType<List<SyText>> textSections();
SyTextMultiLineModelReadableType model();

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

package com.io7m.jsycamore.api.components;

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

/**
* Write access to text areas.
Expand All @@ -25,13 +25,8 @@
public interface SyTextAreaType
extends SyTextAreaReadableType, SyComponentType
{
/**
* Append a text section to the end of the text area.
*
* @param section The section
*/

void textSectionAppend(SyText section);
@Override
SyTextMultiLineModelType model();

@Override
SyScrollBarHorizontalType scrollbarHorizontal();
Expand Down
Expand Up @@ -18,12 +18,10 @@

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.text.SyTextLinePositioned;
import com.io7m.jsycamore.api.text.SyTextMultiLineModelReadableType;
import com.io7m.jsycamore.api.themes.SyThemeClassNameType;

import java.util.List;
import java.util.Optional;

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

Expand Down Expand Up @@ -56,10 +54,10 @@ default List<SyThemeClassNameType> themeClassesDefaultForComponent()
}

/**
* @return A read-only snapshot of the positioned lines of text
* @return The text model
*/

Iterable<SyTextLinePositioned> textLinesPositioned();
SyTextMultiLineModelReadableType model();

/**
* Determine the minimum size on the Y axis required to display the
Expand All @@ -70,13 +68,6 @@ default List<SyThemeClassNameType> themeClassesDefaultForComponent()
* @return The minimum size on the Y axis
*/

int minimumSizeYRequired(SyLayoutContextType layoutContext);

/**
* @param y The Y offset
*
* @return The line starting at Y offset {@code y}
*/

Optional<SyTextLineMeasuredType> textByYOffset(int y);
int minimumSizeYRequired(
SyLayoutContextType layoutContext);
}
Expand Up @@ -17,12 +17,8 @@
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.
*/
Expand All @@ -49,30 +45,6 @@ default void setTextSelectable(
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);
@Override
SyTextMultiLineModelType model();
}
Expand Up @@ -24,6 +24,7 @@
import com.io7m.jsycamore.api.sized.SySizedType;
import com.io7m.jsycamore.api.spaces.SySpaceViewportType;
import com.io7m.jsycamore.api.text.SyTextSelectionServiceType;
import com.io7m.jsycamore.api.themes.SyThemeContextType;
import com.io7m.jsycamore.api.themes.SyThemeType;
import com.io7m.jsycamore.api.windows.SyWindowServiceType;
import com.io7m.jtensors.core.parameterized.vectors.PVector2I;
Expand Down Expand Up @@ -74,6 +75,12 @@ default SyTextSelectionServiceType textSelectionService()
return this.services().requireService(SyTextSelectionServiceType.class);
}

/**
* @return The theme context
*/

SyThemeContextType themeContext();

/**
* @return The current theme used by the screen
*/
Expand Down
Expand Up @@ -31,28 +31,34 @@ public record SyTextID(BigInteger value)
private static final SyTextID FIRST_ID =
new SyTextID(BigInteger.ZERO);

/**
* @return The first text ID
*/

public static SyTextID first()
{
return FIRST_ID;
}

@Override
public int compareTo(
final SyTextID other)
{
return this.value.compareTo(other.value);
}

/**
* @return The next text ID
*/

public SyTextID next()
@Override
public String toString()
{
return new SyTextID(this.value.add(BigInteger.ONE));
return this.value.toString();
}

/**
* @return The first text ID
* @return The next text ID
*/

public static SyTextID first()
public SyTextID next()
{
return FIRST_ID;
return new SyTextID(this.value.add(BigInteger.ONE));
}
}
Expand Up @@ -59,4 +59,16 @@ public SyTextLineNumber next()
{
return new SyTextLineNumber(this.value + 1);
}

/**
* @param delta The delta
*
* @return The line number adjusted by the given delta
*/

public SyTextLineNumber adjust(
final int delta)
{
return new SyTextLineNumber(this.value + delta);
}
}
Expand Up @@ -47,17 +47,6 @@ public interface SyTextMultiLineModelReadableType

SortedMap<SyTextID, SyText> textSections();

/**
* The text section that contains the given line number.
*
* @param lineNumber The line number
*
* @return The text section, if any
*/

Optional<SyText> textSectionContainingLine(
SyTextLineNumber lineNumber);

/**
* Inspect the text at the given position. The information returned includes
* details such as the index of the character within the string at the given
Expand All @@ -82,16 +71,17 @@ Optional<SyTextLocationType> inspectAt(
int minimumSizeYRequired();

/**
* @return A read-only snapshot of the positioned lines of text
* @return The current number of lines
*/

Iterable<SyTextLinePositioned> textLinesPositioned();
int lineCount();

/**
* @param y The y offset
* @param line The line number
*
* @return The measured line that starts at Y offset {@code y}
* @return The line at the given number
*/

Optional<SyTextLineMeasuredType> textByYOffset(int y);
Optional<SyTextLinePositioned> lineAt(
SyTextLineNumber line);
}
Expand Up @@ -49,6 +49,17 @@ void setFont(
void setPageWidth(
int width);

/**
* Replace an existing text section.
*
* @param textID The text ID
* @param text The new text section
*/

void textSectionReplace(
SyTextID textID,
SyText text);

/**
* Append a section of text at the end of the model.
*
Expand Down

This file was deleted.

0 comments on commit 4d15bfb

Please sign in to comment.