Size character cards by displayed content in an ordered responsive grid
This commit is contained in:
parent
a76d201b87
commit
3f0afae50c
30
PlotLine.Tests/CharacterCardLayoutTests.cs
Normal file
30
PlotLine.Tests/CharacterCardLayoutTests.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using PlotLine.Models;
|
||||
using PlotLine.ViewModels;
|
||||
|
||||
internal static class CharacterCardLayoutTests
|
||||
{
|
||||
public static void DisplayedContent()
|
||||
{
|
||||
var character = new Character { CharacterName = "Ari", CharacterImportance = 10 };
|
||||
Check(CharacterCardLayout.ColumnSpan(character) == 1, "Important characters with no description must stay compact.");
|
||||
character.DefaultDescription = "";
|
||||
Check(CharacterCardLayout.ColumnSpan(character) == 1, "Empty descriptions must work.");
|
||||
character.DefaultDescription = new string('a', 293);
|
||||
Check(CharacterCardLayout.ColumnSpan(character) == 1, "A score below 300 must remain one column.");
|
||||
character.DefaultDescription += "b";
|
||||
Check(CharacterCardLayout.ColumnSpan(character) == 2, "A score of 300 must use two columns.");
|
||||
character.DefaultDescription = new string('a', 643);
|
||||
Check(CharacterCardLayout.ColumnSpan(character) == 2, "A score below 650 must remain two columns.");
|
||||
character.DefaultDescription += "b";
|
||||
character.CharacterImportance = 1;
|
||||
Check(CharacterCardLayout.ColumnSpan(character) == 3, "A score of 650 must use three columns regardless of importance.");
|
||||
character.DefaultDescription = " A\r\n" + new string(' ', 1000) + "B\t ";
|
||||
character.Height = new string('x', 1000);
|
||||
Check(CharacterCardLayout.ColumnSpan(character) == 1, "Collapsed whitespace and undisplayed metadata must not inflate a card.");
|
||||
character.CharacterName = new string('N', 150);
|
||||
character.DefaultDescription = null;
|
||||
Check(CharacterCardLayout.ColumnSpan(character) == 2, "Displayed long names must contribute at heading weight.");
|
||||
Check(character.DefaultDescription is null && character.CharacterImportance == 1, "Presentation sizing must not change saved content.");
|
||||
}
|
||||
private static void Check(bool condition, string message) { if (!condition) throw new InvalidOperationException(message); }
|
||||
}
|
||||
@ -19,6 +19,7 @@ using PlotLine.ViewModels;
|
||||
|
||||
var tests = new (string Name, Action Test)[]
|
||||
{
|
||||
("Character card widths reflect displayed text without changing character data", CharacterCardLayoutTests.DisplayedContent),
|
||||
("Scene relationship proposals preserve direction and validate acceptance", RelationshipDevelopmentTests.SceneReviewAndAcceptance),
|
||||
("Location and asset merges require confirmation and distinct records", EntityMergeTests.ConfirmationAndDistinctRecordsAreRequired),
|
||||
("Location persisted analysis preserves contextual bedrooms and setting provenance", LocationSignificanceTests.PersistedAnalysisKeepsContextAndParentEvidence),
|
||||
|
||||
34
PlotLine/ViewModels/CharacterCardLayout.cs
Normal file
34
PlotLine/ViewModels/CharacterCardLayout.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using PlotLine.Models;
|
||||
|
||||
namespace PlotLine.ViewModels;
|
||||
|
||||
public static class CharacterCardLayout
|
||||
{
|
||||
// Tune here: names use a larger heading font; description whitespace collapses
|
||||
// in HTML. Avatars, age badges and actions are bounded, so do not affect span.
|
||||
public const int TwoColumnThreshold = 300;
|
||||
public const int ThreeColumnThreshold = 650;
|
||||
|
||||
public static int ColumnSpan(Character character)
|
||||
{
|
||||
var score = DisplayedLength(character.DefaultDescription) + 2 * DisplayedLength(character.CharacterName);
|
||||
return score >= ThreeColumnThreshold ? 3 : score >= TwoColumnThreshold ? 2 : 1;
|
||||
}
|
||||
|
||||
private static int DisplayedLength(string? text)
|
||||
{
|
||||
var length = 0;
|
||||
var pendingSpace = false;
|
||||
foreach (var character in text ?? string.Empty)
|
||||
{
|
||||
if (char.IsWhiteSpace(character))
|
||||
{
|
||||
pendingSpace = length > 0;
|
||||
continue;
|
||||
}
|
||||
length += pendingSpace ? 2 : 1;
|
||||
pendingSpace = false;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
}
|
||||
@ -22,17 +22,17 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section class="list-section">
|
||||
<section class="list-section character-card-list">
|
||||
@if (!Model.Characters.Any())
|
||||
{
|
||||
<p class="muted">No characters yet.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="asset-card-grid">
|
||||
<div class="asset-card-grid character-card-grid">
|
||||
@foreach (var character in Model.Characters)
|
||||
{
|
||||
<article class="asset-card character-card" draggable="true" data-drag-type="character" data-drag-id="@character.CharacterID" data-drag-label="@character.CharacterName">
|
||||
<article class="asset-card character-card character-card--span-@CharacterCardLayout.ColumnSpan(character)" draggable="true" data-drag-type="character" data-drag-id="@character.CharacterID" data-drag-label="@character.CharacterName">
|
||||
<div class="visual-card-heading">
|
||||
<partial name="_Avatar" model="@(new AvatarViewModel { DisplayName = character.CharacterName, ImagePath = character.AvatarImagePath ?? character.ImagePath, ThumbnailPath = character.AvatarThumbnailPath ?? character.ThumbnailPath })" />
|
||||
<div>
|
||||
|
||||
@ -2339,6 +2339,36 @@ body.timeline-inspector-resizing {
|
||||
border-left: 4px solid #8a6f3d;
|
||||
}
|
||||
|
||||
/* Ordered placement: deliberately leave gaps rather than backfill/reorder cards.
|
||||
Container widths also account for the help drawer reducing the page area. */
|
||||
.character-card-list { container: character-list / inline-size; }
|
||||
.character-card-grid {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
grid-auto-flow: row;
|
||||
align-items: start;
|
||||
}
|
||||
.character-card-grid > .character-card {
|
||||
grid-column: span 1;
|
||||
min-width: 0;
|
||||
align-self: start;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
@container character-list (min-width: 480px) {
|
||||
.character-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
.character-card-grid > .character-card--span-2,
|
||||
.character-card-grid > .character-card--span-3 { grid-column: span 2; }
|
||||
}
|
||||
@container character-list (min-width: 720px) {
|
||||
.character-card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
||||
.character-card-grid > .character-card--span-3 { grid-column: span 3; }
|
||||
}
|
||||
@container character-list (min-width: 960px) {
|
||||
.character-card-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
||||
}
|
||||
@container character-list (min-width: 1200px) {
|
||||
.character-card-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
|
||||
}
|
||||
|
||||
.character-section {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
2
PlotLine/wwwroot/css/site.min.css
vendored
2
PlotLine/wwwroot/css/site.min.css
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user