hf_repo4 / src /core /layout.h
fava21's picture
Backup: patch pack applied + verified on Win11 22000 (d446cc1, ba8617e, dcf5cb8)
2edf277 verified
Raw History Blame Contribute Delete
2.92 kB
// FCS Glass - src/core/layout.h
//
// Implements: A2 (dp -> whole physical pixels, round half up, at every
// supported scale factor; hairlines exactly 1 physical px),
// A3 (radii: window / card / control, pill = height/2 for chips
// and toggles only, inner radius never above outer minus inset).
//
// PURE LOGIC. No windows, no D3D, no project headers. That is a hard
// requirement rather than a style preference: tools/extract_logic.py lifts these
// bodies VERBATIM into tools/generated_logic.inc so tools/logic_harness.cpp can
// exercise them on any machine, Windows or not. One #include <windows.h> on
// this path would take the entire portable test suite with it.
//
// This file owns ONE rounding rule for dp -> px. platform/dpi.h's DpToPx does
// the same conversion, and it could not simply call this one: extract_logic.py
// lifts function bodies as bare text, so a body referring to core::SnapPx would
// arrive in the harness with nothing to resolve against. Rather than duplicate
// the rule silently, the duplication is pinned by a test - the suite asserts
// DpToPx and SnapPx return identical values for every spec'd scale factor AND
// for negative dp, which is the input that broke DpToPx (BUG-30). A future edit
// that moves one and not the other fails the suite instead of shipping a 1 px
// disagreement that shows up as a seam.
#ifndef FCS_CORE_LAYOUT_H
#define FCS_CORE_LAYOUT_H
namespace fcs {
namespace core {
// A2. The dp -> physical pixel conversion: round half up, ties toward
// +infinity, floored explicitly. `static_cast<int>(x + 0.5f)` agrees with this
// only while x is non-negative, because the cast truncates toward zero.
int SnapPx(float dp, float scale);
// A2. A 1 dp hairline is EXACTLY 1 physical pixel at every scale factor. This is
// the one measurement that must NOT scale, or borders thicken as the user drags
// the scale slider and a 2 px border reads as a different design.
constexpr int kHairlinePx = 1;
// A3. Corner radii in dp. `window_dp` is 0 on the Classic profile, which is a
// design decision rather than an oversight, so it is a field and not a constant.
struct RadiusSet {
int window_dp = 8;
int card_dp = 8;
int control_dp = 4;
};
// A3. An inner radius can never exceed the outer radius minus the inset between
// them; past that the inner corner crosses the outer one and the outline
// self-intersects. Clamped rather than rejected: a clamp degrades to a valid
// shape, a rejection loses the widget.
int InnerRadiusClamp(int outer_px, int inset_px);
// A3. A pill is height/2 - but ONLY for chips and toggles. `allow_pill` is an
// explicit argument so a card cannot acquire a stadium outline by accident.
int PillRadiusPx(int height_px, bool allow_pill);
} // namespace core
} // namespace fcs
#endif // FCS_CORE_LAYOUT_H