UI Code Quality: General, Smaller Changes #74432

Open
opened 2020-03-04 14:03:09 +01:00 by Julian Eisel · 6 comments
Member

UI Code Quality: General, Smaller Changes

NOTE: This is a proposal, not an agreed on plan.

Naming conventions

We should avoid ambiguous names. We should also avoid abbreviations, esp. extreme ones, for variables with non-small scope. That should further remove ambiguity and make code more readable.

For example:

Type Old naming (convention) Proposed
{icon check-square-o} ARegion ar region
{icon check-square-o} ScrArea sa area
{icon check-square-o} bScreen sc, scr screen
{icon square-o} PanelType pt panel_type
{icon square-o} MenuType mt menu_type
{icon square-o} HeaderType ht header_type
{icon square-o} ColorBand coba color_band
{icon check-square-o} ExtensionRNA ext rna_extension
{icon square-o} int x1, x2, y1, y2 xmin, width, ymin, height

Note that all these examples can be changed without touching DNA (AFAICS).

Further:

  • uiListDyn -> uiList_Runtime

Various

  • Add iterators for screen data. E.g. iterating all regions (visible or not, including popups and global area regions), iterating all areas (visible or not, including all global areas), iterating all screen regions (as often done by versioning), etc. Could be done in both C (macro) and C++ (range-based for loop )
  • Introduce wrappers for commonly bundled variables (e.g. PointerRNA & PropertyRNA, wmOperatorType & PointerRNA, ScrArea & ARegion).
  • Split up bigger, "generic" types. For example uiBut contains data that only applies to certain button-types. uiButTab is an example of how this can be avoided.
  • Wrap related struct members into nested structs. E.g. rather than uiBut.editstr, uiBut.editval, uiBut.editvec, etc, it could be uiBut.edit_values.foo.
  • Replace booleans in parameter lists with enums. Having a parameter list like foo(true, false, false) is cumbersome to use (what does each boolean mean) and leads to mistakes (using wrong order of booleans). It's better to be explicit what each value refers to by using enum types. Bitflags are also an option.
  • Remove old game-engine leftovers from Ghost, e.g. GHOST_FullScreen(), GHOST_EndFullscreen(), embedder windows (GHOST_TEmbedderWindowID + non-dialog child windows)
  • Split big functions into more manageable chunks.
  • Add const where applicable
  • Of course improving naming, comments and documentation is always a good idea!
  • Use EVT_ prefix for all event types, to complete work started in D7164.
## UI Code Quality: General, Smaller Changes NOTE: This is a proposal, not an agreed on plan. **Naming conventions** We should avoid ambiguous names. We should also avoid abbreviations, esp. extreme ones, for variables with non-small scope. That should further remove ambiguity and make code more readable. For example: | | Type | Old naming (convention) | Proposed | -- | ---- | --------------------- | -------- | {icon check-square-o} | `ARegion` | `ar` | `region` | {icon check-square-o} | `ScrArea` | `sa` | `area` | {icon check-square-o} | `bScreen` | `sc`, `scr` | `screen` | {icon square-o} | `PanelType` | `pt` | `panel_type` | {icon square-o} | `MenuType` | `mt` | `menu_type` | {icon square-o} | `HeaderType` | `ht` | `header_type` | {icon square-o} | `ColorBand` | `coba` | `color_band` | {icon check-square-o} | `ExtensionRNA` | `ext` | `rna_extension` | {icon square-o} | `int` | `x1`, `x2`, `y1`, `y2` | `xmin`, `width`, `ymin`, `height` Note that all these examples can be changed without touching DNA (AFAICS). Further: - [ ] `uiListDyn` -> `uiList_Runtime` **Various** * Add iterators for screen data. E.g. iterating all regions (visible or not, including popups and global area regions), iterating all areas (visible or not, including all global areas), iterating all screen regions (as often done by versioning), etc. Could be done in both C (macro) and C++ ([range-based for loop ](https://en.cppreference.com/w/cpp/language/range-for)) * Introduce wrappers for commonly bundled variables (e.g. `PointerRNA` & `PropertyRNA`, `wmOperatorType` & `PointerRNA`, `ScrArea` & `ARegion`). * Split up bigger, "generic" types. For example `uiBut` contains data that only applies to certain button-types. `uiButTab` is an example of how this can be avoided. * Wrap related struct members into nested structs. E.g. rather than `uiBut.editstr`, `uiBut.editval`, `uiBut.editvec`, etc, it could be `uiBut.edit_values.foo`. * Replace booleans in parameter lists with enums. Having a parameter list like `foo(true, false, false)` is cumbersome to use (what does each boolean mean) and leads to mistakes (using wrong order of booleans). It's better to be explicit what each value refers to by using enum types. Bitflags are also an option. * Remove old game-engine leftovers from Ghost, e.g. `GHOST_FullScreen()`, `GHOST_EndFullscreen()`, embedder windows (`GHOST_TEmbedderWindowID` + non-dialog child windows) * Split big functions into more manageable chunks. * Add `const` where applicable * Of course improving naming, comments and documentation is always a good idea! * Use `EVT_` prefix for all event types, to complete work started in [D7164](https://archive.blender.org/developer/D7164).
Author
Member

Added subscriber: @JulianEisel

Added subscriber: @JulianEisel

Added subscriber: @ideasman42

Added subscriber: @ideasman42
  • WM Names: +1 for naming region, area, screen.

  • Type Names:

Personally I don't find the heavily abbreviated types to be an issue, (`pt`, `mt`, `ht`). In context there is often only one, and it's convenient not to have overly verbose names, especially if you have to differentiate between `panel_type_child`, `panel_type_parent`, `panel_type_next` ... etc. 
Consider event handling code that calls operators `op` and their type `ot`.
It's a short terse convention that happens to be convenient, in practice I don't find this confusing and means names such as `ot_prop_basic_count`, don't turn into `operator_type_prop_basic_count`.
  • ColorBand: +1 to name color_band.

  • ExtensionRNA: prefer rna_ext since it's a common enough abbreviation (used 200+ times in our code already).

  • x1, x2, y1, y2:

Prefer not to mix x/y width height, could be `xmin`, `ymin`, `xsize`, `ysize` instead.
Although for UI code we could pass in `rctf` / `rcti` instead.
We could have a utility to create the rectangle from xmin,ymin,xsize,ysize - since rectangles use min/max values.
- **WM Names:** +1 for naming `region`, `area`, `screen`. - **Type Names:** ``` Personally I don't find the heavily abbreviated types to be an issue, (`pt`, `mt`, `ht`). In context there is often only one, and it's convenient not to have overly verbose names, especially if you have to differentiate between `panel_type_child`, `panel_type_parent`, `panel_type_next` ... etc. ``` ``` Consider event handling code that calls operators `op` and their type `ot`. It's a short terse convention that happens to be convenient, in practice I don't find this confusing and means names such as `ot_prop_basic_count`, don't turn into `operator_type_prop_basic_count`. ``` - **ColorBand:** +1 to name `color_band`. - **ExtensionRNA:** prefer `rna_ext` since it's a common enough abbreviation (used 200+ times in our code already). - **x1, x2, y1, y2**: ``` Prefer not to mix x/y width height, could be `xmin`, `ymin`, `xsize`, `ysize` instead. ``` ``` Although for UI code we could pass in `rctf` / `rcti` instead. We could have a utility to create the rectangle from xmin,ymin,xsize,ysize - since rectangles use min/max values.
Member

Added subscriber: @Harley

Added subscriber: @Harley
Member

I would love to see refactor and standardization of our use of words like "Active" and "Selected" in the UI code. We (strangely) use "active" for the state of having the mouse hovering over. Sometimes "Selected" to simulate having focus and therefore activated by hitting "Enter". Other times "Selected" is when it is being actively acted upon. Elsewhere we use Active and Selected in a large variety of different ways. Would love for us to define how we use them in way that is similar to html pseudoclasses:

Hover - when something is being passed over by some input device, like mouse cursor moving over it.
Focus - when an item is selected for, or ready for, keyboard entry. Moved with Tab. A button with focus is executed with Enter.
Default - A preselected item, even if it does not currently have focus.
Active - when something is currently activated by the user, like when a button is being depressed
Selected - Chosen by the user
Disabled - not currently usable or applicable

I realize that the above would not eliminate the overlap with our use of Active verses Selected objects. But even in those I wish we were always just operating on a list of Selected objects, the first of which is what we now consider "Active". That could help in possibly (eventually) getting to a future where we could pass any list of objects to operators without any relation to what is currently selected by the user.

I would love to see refactor and standardization of our use of words like "Active" and "Selected" in the UI code. We (strangely) use "active" for the state of having the mouse hovering over. Sometimes "Selected" to simulate having focus and therefore activated by hitting "Enter". Other times "Selected" is when it is being actively acted upon. Elsewhere we use Active and Selected in a large variety of different ways. Would love for us to define how we use them in way that is similar to html pseudoclasses: Hover - when something is being passed over by some input device, like mouse cursor moving over it. Focus - when an item is selected for, or ready for, keyboard entry. Moved with Tab. A button with focus is executed with Enter. Default - A preselected item, even if it does not currently have focus. Active - when something is currently activated by the user, like when a button is being depressed Selected - Chosen by the user Disabled - not currently usable or applicable I realize that the above would not eliminate the overlap with our use of Active verses Selected *objects*. But even in those I wish we were always just operating on a list of Selected objects, the first of which is what we now consider "Active". That could help in possibly (eventually) getting to a future where we *could* pass any list of objects to operators without any relation to what is currently selected by the user.
Philipp Oeser removed the
Interest
User Interface
label 2023-02-10 09:24:46 +01:00
Alaska added
Status
Confirmed
and removed
Status
Needs Triage
labels 2024-03-20 11:02:48 +01:00
Member

Changing to confirmed because all TODO tasks should be confirmed. Feel free to close the task if it's no longer relevant.

Changing to confirmed because all `TODO` tasks should be confirmed. Feel free to close the task if it's no longer relevant.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
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
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
4 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#74432
No description provided.