UI Code Quality: Move interface files to folders? #98518

Open
opened 2022-05-31 12:57:57 +02:00 by Julian Eisel · 8 comments
Member

The list of files in interface/ is getting quite long. This makes it harder to scan the list visually. File should also be named and structured in a way, that just by briefly looking at a list of files and directories, it's clear what kind of elements and logic the code deals with. This is a quality for high level readability. Long lists of files make this harder. At the same time we should encourage splitting files into more manageable, more coherent files.
With directories you also have a more isolated environment for internal data and functions. E.g. interface_handlers.c could be split into multiple files with a common header inside a handlers/ directory.

Proposal

I'd propose the following file/directory structure to start with:

interface/
  eyedroppers/
    interface_eyedropper.c
    interface_eyedropper_colorband.c
    interface_eyedropper_color.c
    interface_eyedropper_datablock.c
    interface_eyedropper_depth.c
    interface_eyedropper_driver.c
    interface_eyedropper_gpencil_color.c
    interface_eyedropper_intern.h
  regions/
    interface_region_color_picker.cc
    interface_region_hud.cc
    interface_region_menu_pie.cc
    interface_region_menu_popup.cc
    interface_region_popover.cc
    interface_region_popup.cc
    interface_regions.cc
    interface_region_search.cc
    interface_regions_intern.h
    interface_region_tooltip.c
  templates/
    interface_template_asset_view.cc
    interface_template_attribute_search.cc
    interface_template_list.cc
    interface_templates.c
    interface_template_search_menu.cc
    interface_template_search_operator.c
  views/
    grid_view.cc /* future */
    interface_view.cc
    table_view.cc /* future */
    tree_view.cc
  view2d/
    view2d.cc
    view2d_draw.cc
    view2d_edge_pan.cc
    view2d_gizmo_navigate.cc
    view2d_ops.cc
  CMakeLists.txt
  interface_align.c
  interface_anim.c
  interface_button_group.c
  interface.cc
  interface_context_menu.c
  interface_context_path.cc
  interface_draw.c
  interface_dropboxes.cc
  interface_handlers.c
  interface_icons.c
  interface_icons_event.c
  interface_intern.h
  interface_layout.c
  interface_ops.c
  interface_panel.c
  interface_query.cc
  interface_style.cc
  interface_undo.c
  interface_utils.cc
  interface_widgets.c
  resources.c
The list of files in `interface/` is getting quite long. This makes it harder to scan the list visually. File should also be named and structured in a way, that just by briefly looking at a list of files and directories, it's clear what kind of elements and logic the code deals with. This is a quality for high level readability. Long lists of files make this harder. At the same time we should encourage splitting files into more manageable, more coherent files. With directories you also have a more isolated environment for internal data and functions. E.g. `interface_handlers.c` could be split into multiple files with a common header inside a `handlers/` directory. ## Proposal I'd propose the following file/directory structure to start with: ```lines=15 interface/ eyedroppers/ interface_eyedropper.c interface_eyedropper_colorband.c interface_eyedropper_color.c interface_eyedropper_datablock.c interface_eyedropper_depth.c interface_eyedropper_driver.c interface_eyedropper_gpencil_color.c interface_eyedropper_intern.h regions/ interface_region_color_picker.cc interface_region_hud.cc interface_region_menu_pie.cc interface_region_menu_popup.cc interface_region_popover.cc interface_region_popup.cc interface_regions.cc interface_region_search.cc interface_regions_intern.h interface_region_tooltip.c templates/ interface_template_asset_view.cc interface_template_attribute_search.cc interface_template_list.cc interface_templates.c interface_template_search_menu.cc interface_template_search_operator.c views/ grid_view.cc /* future */ interface_view.cc table_view.cc /* future */ tree_view.cc view2d/ view2d.cc view2d_draw.cc view2d_edge_pan.cc view2d_gizmo_navigate.cc view2d_ops.cc CMakeLists.txt interface_align.c interface_anim.c interface_button_group.c interface.cc interface_context_menu.c interface_context_path.cc interface_draw.c interface_dropboxes.cc interface_handlers.c interface_icons.c interface_icons_event.c interface_intern.h interface_layout.c interface_ops.c interface_panel.c interface_query.cc interface_style.cc interface_undo.c interface_utils.cc interface_widgets.c resources.c ```
Author
Member

Added subscriber: @JulianEisel

Added subscriber: @JulianEisel

Added subscriber: @ideasman42

Added subscriber: @ideasman42

This proposal seems fine, although personally I don't find the number of files a problem at the moment.

We could split out regions, eyedroppers & templates and leave it at that, it avoids having so many files in interface/, I don't feel so strongly about splitting out the other files.

Side-note, we could split up interface_templates.c much further (it's over 6.5k lines currently - defining separate templates that make sense to be in their own files).

This proposal seems fine, although personally I don't find the number of files a problem at the moment. We could split out `regions`, `eyedroppers` & `templates` and leave it at that, it avoids having so many files in `interface/`, I don't feel so strongly about splitting out the other files. Side-note, we could split up `interface_templates.c` much further (it's over 6.5k lines currently - defining separate templates that make sense to be in their own files).
Member

Added subscriber: @HooglyBoogly

Added subscriber: @HooglyBoogly
Member

I like the proposal, I think smaller files are almost always helpful, as long as the abstractions used to divide them up aren't totally wrong.

I think we could remove the redundant words from the file names then though. For example, I'd propose changing templates/interface_template_search_menu.cc to templates/search_menu.cc. Though that could be considered separately too!

I like the proposal, I think smaller files are almost always helpful, as long as the abstractions used to divide them up aren't totally wrong. I think we could remove the redundant words from the file names then though. For example, I'd propose changing `templates/interface_template_search_menu.cc` to `templates/search_menu.cc`. Though that could be considered separately too!

Added subscriber: @AlexeyAdamitsky

Added subscriber: @AlexeyAdamitsky

Added subscriber: @dominikfill

Added subscriber: @dominikfill
Author
Member

Added the views/ and eyedroppers/ directories now. I don't want to change everything at once, no idea how Git handles merging/rebasing when files are renamed. There might be patches that need some manual work to update them now, so I'm going slow on it.

In #98518#1367076, @HooglyBoogly wrote:
I think we could remove the redundant words from the file names then though. For example, I'd propose changing templates/interface_template_search_menu.cc to templates/search_menu.cc. Though that could be considered separately too!

I stripped away the (IMO overly verbose) interface_ prefix from all files but interface_eyedroppers.c and interface_views.c, because they deal exactly with integrating eyedroppers/views into the interface on a general level.

One point for keeping some redundancy: For opening files by name in IDEs it can be useful, there may be a bunch of color.c's, but probably only one eyedropper_color.c. I guess in most IDEs you can type eyedroppers/color.c instead, and even use fuzzy search, but it's less obvious. Esp for newer devs. For views we have some redundancy as well, and I don't think it's an issue: views/grid_view.cc, views/tree_view.cc, etc.

We can still figure out the exact naming convention of course, now we have a first iteration :)

Added the `views/` and `eyedroppers/` directories now. I don't want to change everything at once, no idea how Git handles merging/rebasing when files are renamed. There might be patches that need some manual work to update them now, so I'm going slow on it. > In #98518#1367076, @HooglyBoogly wrote: > I think we could remove the redundant words from the file names then though. For example, I'd propose changing `templates/interface_template_search_menu.cc` to `templates/search_menu.cc`. Though that could be considered separately too! I stripped away the (IMO overly verbose) `interface_` prefix from all files but `interface_eyedroppers.c` and `interface_views.c`, because they deal exactly with integrating eyedroppers/views into the interface on a general level. One point for keeping some redundancy: For opening files by name in IDEs it can be useful, there may be a bunch of `color.c`'s, but probably only one `eyedropper_color.c`. I guess in most IDEs you can type `eyedroppers/color.c` instead, and even use fuzzy search, but it's less obvious. Esp for newer devs. For views we have some redundancy as well, and I don't think it's an issue: `views/grid_view.cc`, `views/tree_view.cc`, etc. We can still figure out the exact naming convention of course, now we have a first iteration :)
Philipp Oeser removed the
Interest
User Interface
label 2023-02-10 09:21:57 +01:00
Iliya Katushenock removed the
Status
Needs Triage
label 2023-08-24 17:38:55 +02:00
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
5 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#98518
No description provided.