UI: Input Placeholders #112104
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
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, Assets & 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
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
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
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 project
No Assignees
7 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#112104
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "Harley/blender:placeholders"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Optional inline hint describing the expected value of an input field.
Implementation of input placeholders, proposed in #111436. This only shows the placeholder when the input is empty and not editing, at 33% opacity of the text color.
Following shows it being set in
space_outliner.py
:Nice to have this prototype, helps a lot to actually see it working.
I'm not sure about the use of italics. It's not standard (nor on web or apps) and if we ever use italics for something else it'd conflict (one of the the most popular RCS posts refers to it).
Here is a comparison with the following changes:
0.33f
.On a light theme.
Thanks! I updated this PR and the capture in the first comment.
@pablovazquez
I have updated this PR further to work more-or-less correctly, although the details of the implementation could change.
All the hardcoded text is gone and are all set like this:
This is great! Super easy to add.
Design-wise I think this is good to go.
WIP: UI: Input Placeholdersto UI: Input PlaceholdersGreat!
I think we can and should have a default placeholder for many cases. For example the pointer properties and ID templates can get this from the RNA struct UI name. In search buttons the default can be "Search". The
placeholder
parameter can then be an override.Good point. It'd be akin to how operators/props/enums display a text label unless we do
text=""
.@JulianEisel @pablovazquez
I have updated this PR to remove all the changes to the python files that had added placeholders. Instead they are all set automatically, in a new
UI_but_placeholder_get
function. You can still explicitly set a placeholder to override those defaults.I'm not sure if my determination of defaults is ideal or not. For buts of type UI_BTYPE_SEARCH_MENU If use the Id names, for UI_BTYPE_TEXT I check the property identifier against "search_filter", "filter_text", "filter_search" to set "Search". These all seem to work correctly when translated.
This will allow the extraction of those new messages to the .po translation files:
I have a slight concern about the translation of these messages: they can currently only use the default translation context. This means that there is no way to distinguish between "[The] search" (noun) and "[Do] search" (verb), which at least in French makes this specific message sound off already. And I’m sure other placeholders can use equally short messages, which will bring up the same kind of issue.
But then again it may be overkill to add a
placeholder_ctxt
argument just for that. Maybe it could reuse the existingtext_ctxt
? It should hopefully reduce the probability of a conflict enough.@pioverfour
I updated the PR with your suggested changes above. I'm not sure what to do about context though, and would appreciate any help and guidance you can provide.
Here is what I would do for the translation part:
I’m not sure at all the code is correct, it’s just the way I could make it work the way I think makes sense:
rna_translate_ui_text()
using the existingtext_ctxt
argument.UI_but_placeholder_get()
, translate using already known contexts:BLT_I18NCONTEXT_ID_ID
context, and are already extracted elsewhere;Search
can have a hardcoded context as well, sayBLT_I18NCONTEXT_ID_WINDOWMANAGER
because the search is expected to happen in the UI, and the WM context is the closest we have to that.I’m not sure how familiar you are with the translation logic, let me know if anything is unclear.
This handles the translation part, but the extraction part remains (UI code parsing from bl_extract_messages.py). I couldn’t make the extraction work using
text_ctxt
yet…However if you don’t want this blocking the patch, I don’t expect there will be hundreds of placeholders soon so I think it’s fine to proceed with the change as is, without the disambiguation. We can improve it at a later stage. And @mont29 will probably have ideas on how to proceed, too.
EDIT: If you want to test that this works, you can put the attached object translation file in your user’s
blender/4.0/datafiles/locale/fr/LC_MESSAGES/
dir, and switch the language to French. It includes a "Search" translation with "WindowManager" context. This should make the search bar display "Placeholder with context!".@pioverfour
Thanks for the help.
It's making more sense now with your help. I did have translation going on in
rna_ui_api.cc
early on (probably without context), but then when I addedUI_but_placeholder_get
it made sense to do it there there, but maybe not in both places. I can see now that it has to be done differently in both places to work correctly.Thanks again!
This should do it for the extraction part! (CC @mont29)
Changes suggested by @pioverfour regarding handling of translations make total sense to me.
i do not have time currently to handle/check the 'extraction' part though
@Harley It looks like the second part of my latest diff was skipped, but without it there is an exception during message extraction.
OMG, I completely missed that. So glad you double-checked. Thanks!!!
The patch is simple and makes sense. I think exposing it as an argument in python makes sense too. I'd hope that the existing
uiBut
string storage could be used (drawstr
) for example. That would require storing a flag like "the text is just a placeholder" for the drawing code, but that should be okay. The goal of reusing the existing storage is just to keepuiBut
smaller and have more consistency about where we store draw strings.I could be thinking about this completely wrong, but I had been assuming that because we want these to work with UI_BTYPE_TEXT (regular text input) that I couldn't use any of the strings needed for editable text, since they are needed. Or maybe I am misunderstanding the life cycle of these things?
I thought that a button would have either placeholder text or editable text, not both at the same time, since once you start editing, the placeholder isn't drawn anymore.
Not sure it is worth the complexity of using one member for two different uses and then having to maintain a flag to keep track of it.
This just adds a single pointer. But uiBut still has some actual char arrays, like
strdata
at 128 bytes anddrawstr
with 400 bytes. So the 8 here seems like the least of our worries. Or perhaps I'm just being lazy.@ -915,1 +915,4 @@
/* Hint that describes the expected value when empty */
void UI_but_placeholder_set(uiBut *but, const char *placeholder_text);
const char *UI_but_placeholder_get(uiBut *but);
This shouldn't be in the public API, put it in
interface_intern.hh
.@blender-bot build
@ -741,0 +743,4 @@
/**
* Hint that describes the expected value when empty.
*/
void UI_but_placeholder_set(uiBut *but, const char *placeholder_text);
My earlier comment was only about
UI_but_placeholder_get()
. The setter makes sense in the public API, it's also part of the public Python API. If that can override the placeholder, other external UI code should be able to as well.Convention is also to prefix internal functions with
ui_
, notUI_
.Yikes, thanks for noticing my mistake. I totally misread your "this" as "these".
@ -5900,0 +5905,4 @@
void UI_but_placeholder_set(uiBut *but, const char *placeholder_text)
{
/* Remove any existing placeholder. */
if (but && but->placeholder) {
Do we have to check that
but
is non-null here? Seems like this function should only be called when it's non-null anyway.This function can probably be simplified:
Indeed, usually we assume pointers like
uiBut *
are non-null in such functions (could also useATTR_NONNULL()
). Best would be to port all of these to use references soon, to make clear in the interface that null is not expected.UI: Input Placeholdersto UI: Input Placeholders