Selection color from accent color

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-10-10 11:22:43 +03:00
parent 0629283aa5
commit f728d61f23
6 changed files with 116 additions and 68 deletions

View File

@@ -39,9 +39,9 @@
namespace {
constexpr int kAtlasDimension = 1024;
constexpr int kAtlasPadding = 2;
constexpr float kDefaultEmScale = 48.0f;
constexpr int ATLAS_DIMENSION = 1024;
constexpr int ATLAS_PADDING = 2;
constexpr float DEFAULT_EM_SCALE = 48.0f;
constexpr float hb_to_em(hb_position_t value, unsigned upem)
{
@@ -143,8 +143,8 @@ auto TextRenderer::flush_font(FontRuntime &rt, FontData &fd) -> void
{
rt.glyph_cache.clear();
fd.glyphs.clear();
rt.pen_x = kAtlasPadding;
rt.pen_y = kAtlasPadding;
rt.pen_x = ATLAS_PADDING;
rt.pen_y = ATLAS_PADDING;
rt.row_height = 0;
if (fd.atlas_img.data)
ImageClearBackground(&fd.atlas_img, BLANK);
@@ -156,20 +156,20 @@ auto TextRenderer::allocate_region(FontRuntime &rt, FontData &fd, int width,
int height) -> std::optional<std::pair<int, int>>
{
(void)fd;
int padded_w = width + kAtlasPadding;
if (padded_w > rt.atlas_width || height + kAtlasPadding > rt.atlas_height)
int padded_w = width + ATLAS_PADDING;
if (padded_w > rt.atlas_width || height + ATLAS_PADDING > rt.atlas_height)
return std::nullopt;
if (rt.pen_x + padded_w > rt.atlas_width) {
rt.pen_x = kAtlasPadding;
rt.pen_x = ATLAS_PADDING;
rt.pen_y += rt.row_height;
rt.row_height = 0;
}
if (rt.pen_y + height + kAtlasPadding > rt.atlas_height)
if (rt.pen_y + height + ATLAS_PADDING > rt.atlas_height)
return std::nullopt;
int x = rt.pen_x;
int y = rt.pen_y;
rt.pen_x += padded_w;
rt.row_height = std::max(rt.row_height, height + kAtlasPadding);
rt.row_height = std::max(rt.row_height, height + ATLAS_PADDING);
return std::pair { x, y };
}
@@ -212,8 +212,8 @@ auto TextRenderer::generate_glyph(FontRuntime &rt, FontData &fd,
int bmp_h = std::max(
1, static_cast<int>(std::ceil(height_em * scale + 2.0 * rt.px_range)));
if (bmp_w + kAtlasPadding > rt.atlas_width
|| bmp_h + kAtlasPadding > rt.atlas_height) {
if (bmp_w + ATLAS_PADDING > rt.atlas_width
|| bmp_h + ATLAS_PADDING > rt.atlas_height) {
TraceLog(LOG_WARNING, "Glyph %u bitmap %dx%d exceeds atlas %dx%d",
glyph_index, bmp_w, bmp_h, rt.atlas_width, rt.atlas_height);
GlyphCacheEntry too_large {};
@@ -542,13 +542,13 @@ auto TextRenderer::load_single_font(std::filesystem::path const &path)
auto runtime = std::make_unique<FontRuntime>();
runtime->face = face;
runtime->atlas_width = kAtlasDimension;
runtime->atlas_height = kAtlasDimension;
runtime->pen_x = kAtlasPadding;
runtime->pen_y = kAtlasPadding;
runtime->atlas_width = ATLAS_DIMENSION;
runtime->atlas_height = ATLAS_DIMENSION;
runtime->pen_x = ATLAS_PADDING;
runtime->pen_y = ATLAS_PADDING;
runtime->row_height = 0;
runtime->px_range = 0.05; // kDefaultPxRange;
runtime->em_scale = kDefaultEmScale;
runtime->em_scale = DEFAULT_EM_SCALE;
runtime->frame_stamp = 0;
runtime->units_per_em
= static_cast<unsigned>(face->units_per_EM ? face->units_per_EM : 2048);