Added a stack view in bottom panel
This commit is contained in:
@@ -0,0 +1,63 @@
|
|||||||
|
package simulator
|
||||||
|
import "core:fmt"
|
||||||
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
|
gui_tab_stack :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
||||||
|
// Panel below header
|
||||||
|
panel_rect := rl.Rectangle{
|
||||||
|
rect.x,
|
||||||
|
rect.y + PANEL_HEADER,
|
||||||
|
rect.width,
|
||||||
|
rect.height - PANEL_HEADER,
|
||||||
|
}
|
||||||
|
rl.GuiPanel(panel_rect, nil)
|
||||||
|
|
||||||
|
// Header background
|
||||||
|
rl.DrawRectangle(i32(rect.x), i32(rect.y), i32(rect.width), i32(PANEL_HEADER), rl.BLACK)
|
||||||
|
rl.DrawTextEx(sim.font, "Stack", {rect.x + 4, rect.y + 4}, 18, 1, rl.WHITE)
|
||||||
|
|
||||||
|
// SP indicator in header
|
||||||
|
sp_label := fmt.ctprintf("SP: %d", sim.machine.sp)
|
||||||
|
sp_size := rl.MeasureTextEx(sim.font, sp_label, 18, 1)
|
||||||
|
rl.DrawTextEx(sim.font, sp_label, {rect.x + rect.width - sp_size.x - 8, rect.y + 4}, 18, 1, rl.WHITE)
|
||||||
|
|
||||||
|
// Use full panel height so empty slots fill the space
|
||||||
|
total_height := max(f32(16) * LINE_HEIGHT, panel_rect.height)
|
||||||
|
content_rect := rl.Rectangle{
|
||||||
|
x = panel_rect.x,
|
||||||
|
y = panel_rect.y - PANEL_HEADER,
|
||||||
|
width = panel_rect.width - 15,
|
||||||
|
height = total_height,
|
||||||
|
}
|
||||||
|
view: rl.Rectangle
|
||||||
|
rl.GuiScrollPanel(panel_rect, nil, content_rect, &sim.stack_scroll, &view)
|
||||||
|
rl.BeginScissorMode(i32(view.x), i32(view.y), i32(view.width), i32(view.height))
|
||||||
|
defer rl.EndScissorMode()
|
||||||
|
|
||||||
|
index_x := panel_rect.x + PADDING_X
|
||||||
|
colon_x := index_x + 30
|
||||||
|
|
||||||
|
for i in 0..<16 {
|
||||||
|
y_pos := panel_rect.y + (f32(i) * LINE_HEIGHT) + sim.stack_scroll.y
|
||||||
|
is_active := i < int(sim.machine.sp)
|
||||||
|
is_top := i == int(sim.machine.sp) - 1
|
||||||
|
// Only draw a background for active slots
|
||||||
|
if is_active {
|
||||||
|
rl.DrawRectangleV(
|
||||||
|
{panel_rect.x + sim.stack_scroll.x, y_pos},
|
||||||
|
{panel_rect.width, LINE_HEIGHT},
|
||||||
|
rl.BLACK,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
sp_marker := ""
|
||||||
|
if is_top do sp_marker = " <- SP"
|
||||||
|
|
||||||
|
color := rl.WHITE if is_top else (rl.BLACK if is_active else rl.WHITE)
|
||||||
|
|
||||||
|
txt_index := fmt.ctprintf("%02d", i)
|
||||||
|
txt_value := fmt.ctprintf(": 0x%04X%s", sim.machine.stack[i], sp_marker)
|
||||||
|
|
||||||
|
rl.DrawTextEx(sim.font, txt_index, {index_x + sim.stack_scroll.x, y_pos}, 18, 1, color)
|
||||||
|
rl.DrawTextEx(sim.font, txt_value, {colon_x + sim.stack_scroll.x, y_pos}, 18, 1, color)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user