Skip to content
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

Move colors and sizing modules out of space_editor_tabs #274

Merged
merged 4 commits into from
Mar 27, 2024

Conversation

rewin123
Copy link
Owner

@rewin123 rewin123 commented Mar 27, 2024

Part of #267

Introduced a new trait responsible for ui styling

/// This trait use to get tab style
pub trait TabStyle: Resource {
    fn error_color(&self) -> egui::Color32;
    fn set_egui_style(&self, world: &World, style: &mut egui::Style);
    fn text_size(&self, world: &World) -> f32;

    fn collect_style(&self, world: &World) -> CollectedStyle {
        let error_color = self.error_color();
        let text_size = self.text_size(world);
        CollectedStyle {
            error_color,
            text_size,
        }
    }
}

And getter for style trait can be registered in ui

/// This resource contains registered editor tabs and current dock tree state
#[derive(Resource)]
pub struct EditorUi {
    pub registry: HashMap<TabNameHolder, EditorUiReg>,
    pub tree: egui_dock::DockState<TabNameHolder>,
    pub style_getter: fn(&World) -> &dyn TabStyle,
}

Based on this trait style collecting and pass into dock ui

/// This system use to show all egui editor ui on primary window
/// Will be useful in some specific cases to ad new system before/after this system
pub fn show_editor_ui(world: &mut World) {
    let Ok(egui_context) = world
        .query_filtered::<&mut EguiContext, With<PrimaryWindow>>()
        .get_single(world)
    else {
        return;
    };
    let mut egui_context = egui_context.clone();
    let ctx = egui_context.get_mut();
    egui_extras::install_image_loaders(ctx);

    {
        // set style for editor
        let editor_ui = world.get_resource::<EditorUi>().unwrap();
        let tab_style = (editor_ui.style_getter)(world);
        ctx.style_mut(|stl| {
            tab_style.set_egui_style(&world, stl);
        });
    }

    world.resource_scope::<EditorUi, _>(|world, mut editor_ui| {
        editor_ui.ui(world, ctx);
    });
}

DoublePanel enum variants were renamed

@rewin123 rewin123 requested a review from naomijub March 27, 2024 09:24
@rewin123 rewin123 changed the base branch from main to v0.6 March 27, 2024 09:24
Copy link

codecov bot commented Mar 27, 2024

Codecov Report

Attention: Patch coverage is 0% with 93 lines in your changes are missing coverage. Please review.

Project coverage is 34.37%. Comparing base (353b413) to head (17cb142).
Report is 4 commits behind head on v0.6.

Files Patch % Lines
crates/editor_ui/src/editor_style.rs 0.00% 29 Missing ⚠️
crates/editor_tabs/src/lib.rs 0.00% 27 Missing ⚠️
crates/editor_tabs/src/tab_style.rs 0.00% 20 Missing ⚠️
crates/editor_tabs/src/tab_viewer.rs 0.00% 8 Missing ⚠️
crates/editor_tabs/src/start_layout.rs 0.00% 6 Missing ⚠️
crates/editor_ui/src/ui_plugin.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             v0.6     #274      +/-   ##
==========================================
- Coverage   34.57%   34.37%   -0.20%     
==========================================
  Files          67       69       +2     
  Lines        9418     9471      +53     
==========================================
  Hits         3256     3256              
- Misses       6162     6215      +53     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rewin123 rewin123 merged commit 56496ad into v0.6 Mar 27, 2024
6 of 8 checks passed
@naomijub naomijub deleted the separate-tab-system branch October 10, 2024 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants