ui: a renderer installs itself through the UiRenderers registry, not a global's initializer
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
07505e7ef2
commit
253d8d3632
2 changed files with 15 additions and 8 deletions
|
|
@ -20,7 +20,17 @@ export property UiBackend {
|
||||||
now: fn() -> float = null # seconds, for animation (else frames at 60 a second)
|
now: fn() -> float = null # seconds, for animation (else frames at 60 a second)
|
||||||
input: bool = true # false: take no input from Input.* (a test drives it)
|
input: bool = true # false: take no input from Input.* (a test drives it)
|
||||||
}
|
}
|
||||||
var ui_be: UiBackend = null
|
# a renderer a program installs by importing it (render3d.ludic): the first one is the backend
|
||||||
|
property UiRenderer {
|
||||||
|
key: string = ""
|
||||||
|
make: fn() -> UiBackend = null
|
||||||
|
}
|
||||||
|
registry UiRenderers of UiRenderer as UIR
|
||||||
|
function ui_default_backend() -> UiBackend {
|
||||||
|
if len(UiRenderers) == 0 { return null }
|
||||||
|
return UiRenderers[0].make()
|
||||||
|
}
|
||||||
|
var ui_be: UiBackend = ui_default_backend()
|
||||||
export function ui_backend(b: UiBackend) -> void { ui_be = b }
|
export function ui_backend(b: UiBackend) -> void { ui_be = b }
|
||||||
function ui_px(v: float) -> float {
|
function ui_px(v: float) -> float {
|
||||||
if ui_be != null and ui_be.scale != null { return v * ui_be.scale() }
|
if ui_be != null and ui_be.scale != null { return v * ui_be.scale() }
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,10 @@ var r3u_atlas_tex: []int = new []int
|
||||||
var r3u_atlas_cols: []int = new []int
|
var r3u_atlas_cols: []int = new []int
|
||||||
var r3u_atlas_rows: []int = new []int
|
var r3u_atlas_rows: []int = new []int
|
||||||
var r3u_atlas_names: [][]string = new [][]string
|
var r3u_atlas_names: [][]string = new [][]string
|
||||||
var r3u_installed: bool = r3u_install()
|
|
||||||
# importing this file is enough: it is the renderer from the program's first frame
|
# importing this file is enough: it is the renderer from the program's first frame
|
||||||
function r3u_install() -> bool {
|
def UiRenderers render3d { make: fn r3u_make }
|
||||||
ui_render3d()
|
export function ui_render3d() -> void { ui_backend(r3u_make()) }
|
||||||
return true
|
function r3u_make() -> UiBackend {
|
||||||
}
|
|
||||||
export function ui_render3d() -> void {
|
|
||||||
let b = new UiBackend
|
let b = new UiBackend
|
||||||
b.rect = fn r3u_rect
|
b.rect = fn r3u_rect
|
||||||
b.round = fn r3u_round
|
b.round = fn r3u_round
|
||||||
|
|
@ -38,7 +35,7 @@ export function ui_render3d() -> void {
|
||||||
b.unclip = fn r3u_unclip
|
b.unclip = fn r3u_unclip
|
||||||
b.scale = fn r3u_scale
|
b.scale = fn r3u_scale
|
||||||
b.now = fn r3u_now
|
b.now = fn r3u_now
|
||||||
ui_backend(b)
|
return b
|
||||||
}
|
}
|
||||||
# the player's interface size, 1.0 as designed
|
# the player's interface size, 1.0 as designed
|
||||||
export function ui_render3d_scale(s: float) -> void { r3u_user = s }
|
export function ui_render3d_scale(s: float) -> void { r3u_user = s }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue