143 lines
3.8 KiB
Plaintext
143 lines
3.8 KiB
Plaintext
@using TuringMachine.Core
|
|
|
|
<div class="tape-wrapper">
|
|
<button class="scroll-btn" @onclick="ScrollLeft" disabled="@(ScrollOffset <= 0)">◀</button>
|
|
|
|
<div class="tape-container" @ref="tapeContainer">
|
|
@for (int i = StartIndex; i <= EndIndex; i++)
|
|
{
|
|
var isHead = i == HeadPosition;
|
|
<div class="tape-cell @(isHead ? "head" : "")" id="@($"cell-{i}")">
|
|
<span class="cell-index">@i</span>
|
|
<span class="cell-value">@Tape[i]</span>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
<button class="scroll-btn" @onclick="ScrollRight" disabled="@(ScrollOffset >= MaxScrollOffset)">▶</button>
|
|
</div>
|
|
|
|
<style>
|
|
.tape-wrapper {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
padding: 20px;
|
|
background-color: var(--tape-bg);
|
|
border-radius: 8px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.scroll-btn {
|
|
background-color: var(--button-bg);
|
|
color: var(--button-text);
|
|
border: none;
|
|
padding: 10px 15px;
|
|
cursor: pointer;
|
|
border-radius: 4px;
|
|
font-size: 18px;
|
|
transition: background-color 0.2s;
|
|
}
|
|
|
|
.scroll-btn:hover:not(:disabled) {
|
|
background-color: var(--button-hover-bg);
|
|
}
|
|
|
|
.scroll-btn:disabled {
|
|
opacity: 0.3;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.tape-container {
|
|
display: flex;
|
|
gap: 5px;
|
|
overflow-x: scroll;
|
|
flex: 1;
|
|
padding: 10px 0;
|
|
scrollbar-width: thin;
|
|
scrollbar-color: var(--border-color) var(--tape-bg);
|
|
}
|
|
|
|
.tape-container::-webkit-scrollbar {
|
|
height: 8px;
|
|
}
|
|
|
|
.tape-container::-webkit-scrollbar-track {
|
|
background: var(--tape-bg);
|
|
}
|
|
|
|
.tape-container::-webkit-scrollbar-thumb {
|
|
background: var(--border-color);
|
|
border-radius: 4px;
|
|
}
|
|
|
|
.tape-cell {
|
|
min-width: 60px;
|
|
height: 80px;
|
|
border: 2px solid var(--tape-cell-border);
|
|
background-color: var(--tape-cell-bg);
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
border-radius: 4px;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.tape-cell.head {
|
|
background-color: var(--tape-head-bg);
|
|
border-color: var(--tape-head-border);
|
|
border-width: 3px;
|
|
transform: scale(1.1);
|
|
box-shadow: 0 4px 8px rgba(0, 123, 255, 0.3);
|
|
}
|
|
|
|
.cell-index {
|
|
font-size: 10px;
|
|
color: var(--text-secondary);
|
|
margin-bottom: 4px;
|
|
}
|
|
|
|
.cell-value {
|
|
font-size: 24px;
|
|
font-weight: bold;
|
|
font-family: 'Courier New', monospace;
|
|
color: var(--text-primary);
|
|
}
|
|
</style>
|
|
|
|
@code {
|
|
[Parameter] public Tape Tape { get; set; } = new();
|
|
[Parameter] public int HeadPosition { get; set; }
|
|
|
|
private ElementReference tapeContainer;
|
|
private int ScrollOffset = 0;
|
|
private const int CellsPerPage = 15;
|
|
private const int Padding = 5;
|
|
|
|
private int TapeStart => Tape.MinIndex - Padding;
|
|
private int TapeEnd => Tape.MaxIndex + Padding;
|
|
private int StartIndex => TapeStart + ScrollOffset;
|
|
private int EndIndex => Math.Min(StartIndex + CellsPerPage - 1, TapeEnd);
|
|
private int MaxScrollOffset => Math.Max(0, TapeEnd - TapeStart - CellsPerPage + 1);
|
|
|
|
private void ScrollLeft()
|
|
{
|
|
ScrollOffset = Math.Max(0, ScrollOffset - CellsPerPage / 2);
|
|
}
|
|
|
|
private void ScrollRight()
|
|
{
|
|
ScrollOffset = Math.Min(MaxScrollOffset, ScrollOffset + CellsPerPage / 2);
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
// Auto-center on head if it's outside visible range
|
|
if (HeadPosition < StartIndex || HeadPosition > EndIndex)
|
|
{
|
|
ScrollOffset = Math.Max(0, HeadPosition - TapeStart - CellsPerPage / 2);
|
|
}
|
|
}
|
|
}
|