1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! Minimal text positioning test
//!
//! Tests that text is correctly centered within parent containers.
//!
//! Run with: cargo run -p blinc_app --example text_position_test --features windowed
use blinc_app::prelude::*;
use blinc_app::windowed::{WindowedApp, WindowedContext};
use blinc_core::Color;
fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.init();
let config = WindowConfig {
title: "Text Position Test".to_string(),
width: 600,
height: 400,
resizable: true,
..Default::default()
};
WindowedApp::run(config, |ctx| build_ui(ctx))
}
fn build_ui(ctx: &WindowedContext) -> impl ElementBuilder {
// Use logical pixel values for consistent testing
// The scale factor is applied at render time
let scale = ctx.scale_factor;
tracing::info!(
"Window: {}x{}, scale_factor: {}",
ctx.width,
ctx.height,
scale
);
div()
.w(ctx.width)
.h(ctx.height)
.bg(Color::rgba(0.1, 0.1, 0.15, 1.0))
.flex_col()
.gap(20.0)
.p(40.0)
.items_center() // Center all children horizontally
// Test 1: Simple centered text
.child(
div()
.w(400.0)
.h(60.0)
.bg(Color::rgba(0.2, 0.2, 0.3, 1.0))
.rounded(8.0)
.items_center()
.justify_center()
.child(
text("Centered Text (items_center + justify_center)")
.size(16.0)
.color(Color::WHITE),
),
)
// Test 2: Centered text with text_center()
.child(
div()
.w(400.0)
.h(60.0)
.bg(Color::rgba(0.3, 0.2, 0.2, 1.0))
.rounded(8.0)
.items_center()
.justify_center()
.child(
text("Centered + text_center()")
.size(16.0)
.color(Color::WHITE)
.text_center(),
),
)
// Test 3: Button-like container with v_center
.child(
div()
.w(200.0)
.h(50.0)
.bg(Color::rgba(0.3, 0.5, 0.8, 1.0))
.rounded(8.0)
.items_center()
.justify_center()
.child(
text("Button (v_center)")
.size(18.0)
.color(Color::WHITE)
.v_center(),
),
)
// Test 4: Left-aligned text (default)
.child(
div()
.w(400.0)
.h(60.0)
.bg(Color::rgba(0.2, 0.3, 0.2, 1.0))
.rounded(8.0)
.items_center()
// No justify_center - text box at left, but vertically centered
.child(
text("Left-aligned (items_center only)")
.size(16.0)
.color(Color::WHITE),
),
)
}