-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a Theme
type that is more easy to edit in a configuration file
#140
Conversation
Looks pretty good so far. What happens if someone wants to override the font size adjustments baked into |
Maybe every field should have a load priority like this
Makes me think of CSS. |
I'm not sure how common of a use this would be, but if it would be used by most themes I can add support. Otherwise users could just use a The point of a So if something like "font_name_body": "Pixelify",
"font_size_body": 18,
"font_name_heading": "Pixelify",
"font_size_heading": 16,
"font_name_caption": "Pixelify",
"font_size_caption": 14,
"font_name_title": "Pixelify",
"font_size_title": 20, or "font_base_size": 18
"font_name_body": "Pixelify",
"font_scale_body": 1,
"font_name_heading": "Pixelify",
"font_scale_heading": 0.8,
"font_name_caption": "Pixelify",
"font_scale_caption": 0.7,
"font_name_title": "Pixelify",
"font_scale_title": 2.0, would be more useful, then that can be changed It could also be possible to make certain fields optional |
That sounds reasonable. I say go ahead and we can add extra fields or priority things if anyone needs them. Thanks! |
This change reduces ~645 lines of theme definition zig code to ~85 lines of json |
I have some questions:
const alloc = self.arena.allocator();
self.themes = std.StringHashMap(Theme).init(alloc); because |
There are some slight discrepancies in the themes before and after. I tried to get things as close as I could but it could still use some fine tuning. I can add back the adwaita theme zig code as a default for now.
I probably passed over this, i can adjust
I was under the impression that font sizes were floored later elsewhere in the codebase such as line 567 in var pixel_size = @as(u32, @intFromFloat(@max(min_pixel_size, @floor(font.size)))); But perhaps I misunderstood this code. Either way I can adjust the code to make sure all font sizes are rounded to the closest integer in the QuickTheme code.
Ah, I wasn't even aware of the However, the other reason I am using a theme cache is that it allows us to change the order that the themes are iterated thru. Thus, this function can guarantee that the list of themes will be in alphabetical order
Okay, I can adjust this |
That sounds good - it will also be useful for people looking at the code to see a "raw" theme in addition to the serializable ones.
We have to floor the size when we ask freetype/stb_truetype to load a font and rasterize the glyphs, but in renderText() (and textSizeEx()) the glyph sizes are scaled back up to match the
Took me a while to learn about ArrayHashMap as well. It should be plenty fast. I think we can sort StringArrayHashMap? |
…r memory bug, replace StringHashMap with StringArrayHashMap
Okay, I believe those issues have been addressed |
With the alloc issue, I see what you were thinking, but the problem isn't creating the underlying ArenaAllocator, it's doing I'll take it from here - thanks! |
I know the problem isn't creating the underlying arena. However, storing a pointer to an arena allocator stored on the heap should fix this no? var self: @This() = .{
.arena = try base_allocator.create(std.heap.ArenaAllocator),
.themes = undefined,
};
self.arena.* = std.heap.ArenaAllocator.init(base_allocator); Thus, the allocator created in this line const alloc = self.arena.allocator(); Is getting a pointer to heap memory, not a stack pointer, no? The arena is never stored on the stack - so any pointers to the arena must be pointing to the heap memory For example, isn't this the same way |
Whoops - you are totally right I missed that. Sorry! |
Question: how much more than A markdown rendering widget would use a lot of different fonts, but is it worth it to have the global scope be complicated? Now I see four types of text in
What tells me that a piece of text is title or heading? What's caption? These need to be documented, somehow. Maybe here is where we use Zig type magic to generate theme based on widgets used. Every widget can request a set of style variables to be filled in. Let's say we have a struct const style: StyleDesigner = dvui.core_style_designer;
dvui.style = style;
// later, in a widget
const font = dvui.style.give_me("body text", .type_face);
const color = dvui.style.give_me("body text", .color); The key point is that the extensible style is a Zig function, not encoded in JSON. CSS encodes rules like this. I think we should have core widgets settle on a set of constants like This new |
I have created the |
I'm not entirely sure how this idea would operate in practice. I did look over your branch. However, I do like the idea of using a subset of CSS directly rather than making our own bespoke styling system. |
I'm not sure I follow you. QuickTheme is just a way to serialize a Theme - it doesn't interact with widgets directly. const font = dvui.style.give_me("body text", .type_face); is currently written as const font = dvui.themeGet().font_body;
// or when making a widget
dvui.myWidget(@src(), ..., .{ .font_style = .body }); I agree that some kind of documentation would help, but unsure how to do it. Maybe there's a way to enhance the debugging window to give information about the font under the mouse? |
Now that I've written that, I'm tempted to get rid of the .font_style part of options in favor of just: dvui.myWidget(@src(), ..., .{ .font = dvui.themeGet().font_body }); The idea behind font_style was to be able to specify an Options struct in one place (especially the defaults of widgets) but still allow the Theme to change. But it seems that widgets never have a different font in their defaults - it's always font_body. |
It's not about |
Alternative PR to #128
Before I starting converting current theme definitions to use the new format. @david-vanderson I wanted to get your feedback on this.
Example theme using new format
jungle.json