UI: Color Icon Theme Internal Parts #125146

Merged
Harley Acheson merged 15 commits from Harley/blender:IconThemeColor into main 2024-08-11 20:10:52 +02:00
Member

Allow color SVG icons to have their fill colors modified by theme
colors using a callback. This is done just before rasterization so
only happens once per requested size, before these are cached for
reuse.


As an example this PR alters "record_on.svg" slightly so that, only if it is defined as DEF_ICON_COLOR, it will display its inner circle in red, while the outer ring will show in the current text color and so changing with theme changes:

While in dark mode it would look like this:

image

While in light mode you notice that the outer ring color is different:

image

This PR leaves "ICON_RECORD_ON" defined as just DEF_ICON and therefore it looks and behaves as it does currently.

Allow color SVG icons to have their fill colors modified by theme colors using a callback. This is done just before rasterization so only happens once per requested size, before these are cached for reuse. --- As an example this PR alters "record_on.svg" slightly so that, **only if it is defined as DEF_ICON_COLOR**, it will display its inner circle in red, while the outer ring will show in the current text color and so changing with theme changes: While in dark mode it would look like this: ![image](/attachments/29797304-6001-43a4-ba28-ae1b6968518f) While in light mode you notice that the outer ring color is different: ![image](/attachments/47b7dabd-c5f6-4f28-bf0d-35244b069f59) This PR leaves "ICON_RECORD_ON" defined as just DEF_ICON and therefore it looks and behaves as it does currently.
Harley Acheson added this to the Module: User Interface project 2024-07-20 23:03:33 +02:00
Harley Acheson requested review from Hans Goudey 2024-07-20 23:03:43 +02:00
Harley Acheson force-pushed IconThemeColor from c96caf2e4a to 4ed805e53a 2024-08-07 23:47:47 +02:00 Compare
Harley Acheson added 2 commits 2024-08-08 02:16:25 +02:00
Hans Goudey reviewed 2024-08-08 21:51:08 +02:00
@ -109,2 +111,3 @@
float outline_alpha = 1.0f,
bool multicolor = false);
bool multicolor = false,
std::function<void(std::string &)> edit_source_cb = nullptr);
Member

FunctionRef would be a better fit here. std::function is only used when it needs to own data (i.e. the function is passed around and saved for later).

`FunctionRef` would be a better fit here. `std::function` is only used when it needs to own data (i.e. the function is passed around and saved for later).
Harley marked this conversation as resolved
Harley Acheson added 2 commits 2024-08-08 23:44:16 +02:00
Hans Goudey approved these changes 2024-08-09 17:02:46 +02:00
@ -1296,2 +1298,4 @@
}
static void svg_replace_color_attributes(std::string &svg,
const std::string name,
Member

Pass std::string by const reference rather than by value.

Generally I'm a bit concerned by the performance of this function when it starts acting on thousands of icons. There are a lot of incremental updates to the text, and then it's called once for every theme color.

I don't want to get in the way or request premature optimizations, but I'd just suggest keeping an eye on this as more SVG icons are processed with this function. It shouldn't have an impact on startup time for example.

Pass `std::string` by const reference rather than by value. Generally I'm a bit concerned by the performance of this function when it starts acting on thousands of icons. There are a lot of incremental updates to the text, and then it's called once for every theme color. I don't want to get in the way or request premature optimizations, but I'd just suggest keeping an eye on this as more SVG icons are processed with this function. It shouldn't have an impact on startup time for example.
Author
Member

Agreed. I'll add a "Todo" comment to icon_source_edit_cb indicating that this text processing is suboptimal with all the inserts and has lots of room for optimization.

Agreed. I'll add a "Todo" comment to `icon_source_edit_cb` indicating that this text processing is suboptimal with all the inserts and has lots of room for optimization.
Author
Member

Actually re-wrote that section so the processing is done by scanning the string by group, only for those that start with "blender."

Actually re-wrote that section so the processing is done by scanning the string by group, only for those that start with "blender."
Harley marked this conversation as resolved
Harley Acheson added 2 commits 2024-08-09 21:57:45 +02:00
Hans Goudey reviewed 2024-08-09 22:14:34 +02:00
@ -1298,0 +1336,4 @@
};
for (const ColorItem &item : items) {
if (name.compare(item.name) != 0) {
Member

Why not just name != item.name?

Why not just `name != item.name`?
Harley marked this conversation as resolved
@ -1298,0 +1365,4 @@
if (att_start == std::string::npos || att_start > end) {
break;
}
const size_t att_end = svg.find("\"", att_start + 6);
Member

These numbers 6, 20, 14, 16, should come from somewhere. I imagine they're the length of some string? Probably better to compute it at compile time then. For example with StringRef::size().

These numbers 6, 20, 14, 16, should come from somewhere. I imagine they're the length of some string? Probably better to compute it at compile time then. For example with `StringRef::size()`.
Harley marked this conversation as resolved
Hans Goudey requested review from Hans Goudey 2024-08-09 22:14:46 +02:00
Harley Acheson added 2 commits 2024-08-10 00:02:08 +02:00
Harley Acheson added 2 commits 2024-08-10 00:04:58 +02:00
Harley Acheson added 1 commit 2024-08-10 00:36:33 +02:00
Harley Acheson added 2 commits 2024-08-11 19:02:18 +02:00
Harley Acheson added 1 commit 2024-08-11 19:35:33 +02:00
Back for monochrome for the record button.
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
dd2a0b4dfa
Author
Member

@blender-bot build

@blender-bot build
Harley Acheson merged commit cd998d392d into main 2024-08-11 20:10:52 +02:00
Harley Acheson deleted branch IconThemeColor 2024-08-11 20:10:55 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Asset System
Module
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#125146
No description provided.