Skip to content

Commit

Permalink
Remove Window::name
Browse files Browse the repository at this point in the history
It was just technical debt, back from when Window deduplication was by Window::name instead of Window::id
  • Loading branch information
melody-rs committed Jul 3, 2024
1 parent 83616c2 commit ec84e01
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 210 deletions.
5 changes: 0 additions & 5 deletions crates/core/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,6 @@ pub trait Window {
update_state: &mut crate::UpdateState<'_>,
);

/// Optionally used as the title of the window.
fn name(&self) -> String {
"Untitled Window".to_string()
}

/// Required to prevent duplication.
fn id(&self) -> egui::Id;

Expand Down
8 changes: 0 additions & 8 deletions crates/ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,6 @@ macro_rules! window_enum {
}
}

fn name(&self) -> String {
match self {
$(
Self::$variant(v) => v.name(),
)*
}
}

fn id(&self) -> egui::Id {
match self {
$(
Expand Down
4 changes: 0 additions & 4 deletions crates/ui/src/windows/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ impl Default for Window {
}

impl luminol_core::Window for Window {
fn name(&self) -> String {
"About".to_string()
}

fn id(&self) -> egui::Id {
egui::Id::new("About Luminol")
}
Expand Down
16 changes: 7 additions & 9 deletions crates/ui/src/windows/actors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,6 @@ fn draw_exp(ui: &mut egui::Ui, actor: &luminol_data::rpg::Actor, total: &mut boo
}

impl luminol_core::Window for Window {
fn name(&self) -> String {
if let Some(name) = &self.selected_actor_name {
format!("Editing actor {:?}", name)
} else {
"Actor Editor".into()
}
}

fn id(&self) -> egui::Id {
egui::Id::new("actor_editor")
}
Expand Down Expand Up @@ -257,7 +249,13 @@ impl luminol_core::Window for Window {

self.selected_actor_name = None;

let response = egui::Window::new(self.name())
let name = if let Some(name) = &self.selected_actor_name {
format!("Editing actor {:?}", name)
} else {
"Actor Editor".into()
};

let response = egui::Window::new(name)
.id(self.id())
.default_width(500.)
.open(open)
Expand Down
70 changes: 34 additions & 36 deletions crates/ui/src/windows/appearance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,57 +35,55 @@ impl luminol_core::Window for Window {
egui::Id::new("luminol_appearance_window")
}

fn name(&self) -> String {
"Luminol Appearance".to_string()
}

fn show(
&mut self,
ctx: &egui::Context,
open: &mut bool,
update_state: &mut luminol_core::UpdateState<'_>,
) {
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
// Or these together so if one OR the other is true the window shows.
self.egui_settings_open =
ui.button("Egui Settings").clicked() || self.egui_settings_open;
egui::Window::new("Luminol Appearance")
.open(open)
.show(ctx, |ui| {
// Or these together so if one OR the other is true the window shows.
self.egui_settings_open =
ui.button("Egui Settings").clicked() || self.egui_settings_open;

ui.menu_button("Code Theme", |ui| {
for t in luminol_config::SyntectTheme::iter() {
ui.radio_value(
&mut update_state.global_config.theme.syntect_theme,
t,
t.to_string(),
);
}
ui.menu_button("Code Theme", |ui| {
for t in luminol_config::SyntectTheme::iter() {
ui.radio_value(
&mut update_state.global_config.theme.syntect_theme,
t,
t.to_string(),
);
}

ui.label("Code sample");
ui.label(luminol_components::syntax_highlighting::highlight(
ui.ctx(),
update_state.global_config.theme,
r#"
ui.label("Code sample");
ui.label(luminol_components::syntax_highlighting::highlight(
ui.ctx(),
update_state.global_config.theme,
r#"
class Foo < Array
end
def bar(baz)
end
print 1, 2.0
puts [0x3, :4, '5']
"#,
"rb",
));
});
"rb",
));
});

if ui
.button("Clear Loaded Textures")
.on_hover_text(
"You may need to reopen maps/windows for any changes to take effect.",
)
.clicked()
{
update_state.graphics.texture_loader.clear();
update_state.graphics.atlas_loader.clear();
update_state.bytes_loader.forget_all();
}
});
if ui
.button("Clear Loaded Textures")
.on_hover_text(
"You may need to reopen maps/windows for any changes to take effect.",
)
.clicked()
{
update_state.graphics.texture_loader.clear();
update_state.graphics.atlas_loader.clear();
update_state.bytes_loader.forget_all();
}
});
}
}
16 changes: 7 additions & 9 deletions crates/ui/src/windows/armor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ impl Window {
}

impl luminol_core::Window for Window {
fn name(&self) -> String {
if let Some(name) = &self.selected_armor_name {
format!("Editing armor {:?}", name)
} else {
"Armor Editor".into()
}
}

fn id(&self) -> egui::Id {
egui::Id::new("armor_editor")
}
Expand All @@ -70,7 +62,13 @@ impl luminol_core::Window for Window {

self.selected_armor_name = None;

let response = egui::Window::new(self.name())
let name = if let Some(name) = &self.selected_armor_name {
format!("Editing armor {:?}", name)
} else {
"Armor Editor".into()
};

let response = egui::Window::new(name)
.id(self.id())
.default_width(500.)
.open(open)
Expand Down
16 changes: 7 additions & 9 deletions crates/ui/src/windows/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ impl Window {
}

impl luminol_core::Window for Window {
fn name(&self) -> String {
if let Some(name) = &self.selected_class_name {
format!("Editing class {:?}", name)
} else {
"Class Editor".into()
}
}

fn id(&self) -> egui::Id {
egui::Id::new("class_editor")
}
Expand All @@ -133,7 +125,13 @@ impl luminol_core::Window for Window {

self.selected_class_name = None;

let response = egui::Window::new(self.name())
let name = if let Some(name) = &self.selected_class_name {
format!("Editing class {:?}", name)
} else {
"Class Editor".into()
};

let response = egui::Window::new(name)
.id(self.id())
.default_width(500.)
.open(open)
Expand Down
16 changes: 7 additions & 9 deletions crates/ui/src/windows/common_event_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ impl Default for Window {
}

impl luminol_core::Window for Window {
fn name(&self) -> String {
self.tabs
.focused_name()
.map_or("Common Events".to_string(), |name| {
format!("Editing Common Event {name}")
})
}

fn id(&self) -> egui::Id {
egui::Id::new("Common Events")
}
Expand All @@ -59,7 +51,13 @@ impl luminol_core::Window for Window {
open: &mut bool,
update_state: &mut luminol_core::UpdateState<'_>,
) {
egui::Window::new(self.name())
let name = self
.tabs
.focused_name()
.map_or("Common Events".to_string(), |name| {
format!("Editing Common Event {name}")
});
egui::Window::new(name)
.default_width(500.)
.id(egui::Id::new("common_events_edit"))
.open(open)
Expand Down
52 changes: 25 additions & 27 deletions crates/ui/src/windows/config_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ pub struct Window {}
impl Window {}

impl luminol_core::Window for Window {
fn name(&self) -> String {
"Local Luminol Config".to_string()
}

fn id(&self) -> egui::Id {
egui::Id::new("Local Luminol Config")
}
Expand All @@ -44,31 +40,33 @@ impl luminol_core::Window for Window {
open: &mut bool,
update_state: &mut luminol_core::UpdateState<'_>,
) {
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
let config = update_state
.project_config
.as_mut()
.expect("project not open");
egui::Window::new("Local Luminol Config")
.open(open)
.show(ctx, |ui| {
let config = update_state
.project_config
.as_mut()
.expect("project not open");

ui.label("Project name");
ui.text_edit_singleline(&mut config.project.project_name);
ui.label("Scripts path");
ui.text_edit_singleline(&mut config.project.scripts_path);
ui.checkbox(
&mut config.project.use_ron,
"Use RON (Rusty Object Notation)",
);
egui::ComboBox::from_label("RGSS Version")
.selected_text(config.project.rgss_ver.to_string())
.show_ui(ui, |ui| {
for ver in luminol_config::RGSSVer::iter() {
ui.selectable_value(&mut config.project.rgss_ver, ver, ver.to_string());
}
});
ui.label("Project name");
ui.text_edit_singleline(&mut config.project.project_name);
ui.label("Scripts path");
ui.text_edit_singleline(&mut config.project.scripts_path);
ui.checkbox(
&mut config.project.use_ron,
"Use RON (Rusty Object Notation)",
);
egui::ComboBox::from_label("RGSS Version")
.selected_text(config.project.rgss_ver.to_string())
.show_ui(ui, |ui| {
for ver in luminol_config::RGSSVer::iter() {
ui.selectable_value(&mut config.project.rgss_ver, ver, ver.to_string());
}
});

ui.label("Playtest Executable");
ui.text_edit_singleline(&mut config.project.playtest_exe);
});
ui.label("Playtest Executable");
ui.text_edit_singleline(&mut config.project.playtest_exe);
});
}

fn requires_filesystem(&self) -> bool {
Expand Down
6 changes: 1 addition & 5 deletions crates/ui/src/windows/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ impl Window {
}

impl luminol_core::Window for Window {
fn name(&self) -> String {
self.term.title.clone()
}

fn id(&self) -> egui::Id {
self.term.id
}
Expand All @@ -57,7 +53,7 @@ impl luminol_core::Window for Window {
open: &mut bool,
update_state: &mut luminol_core::UpdateState<'_>,
) {
egui::Window::new(self.name())
egui::Window::new(&self.term.title)
.id(self.term.id)
.open(open)
.show(ctx, |ui| {
Expand Down
16 changes: 7 additions & 9 deletions crates/ui/src/windows/enemies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,6 @@ impl Window {
}

impl luminol_core::Window for Window {
fn name(&self) -> String {
if let Some(name) = &self.selected_enemy_name {
format!("Editing enemy {:?}", name)
} else {
"Enemy Editor".into()
}
}

fn id(&self) -> egui::Id {
egui::Id::new("enemy_editor")
}
Expand Down Expand Up @@ -283,7 +275,13 @@ impl luminol_core::Window for Window {

self.selected_enemy_name = None;

let response = egui::Window::new(self.name())
let name = if let Some(name) = &self.selected_enemy_name {
format!("Editing enemy {:?}", name)
} else {
"Enemy Editor".into()
};

let response = egui::Window::new(name)
.id(self.id())
.default_width(500.)
.open(open)
Expand Down
6 changes: 1 addition & 5 deletions crates/ui/src/windows/event_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ impl Window {
}

impl luminol_core::Window for Window {
fn name(&self) -> String {
format!("Event 'TODO' ID {}", self.event_id)
}

fn id(&self) -> egui::Id {
egui::Id::new("luminol_event_edit")
.with(self.map_id)
Expand All @@ -100,7 +96,7 @@ impl luminol_core::Window for Window {
let mut modified = false;
let mut graphic_modified = false;

egui::Window::new(self.name())
egui::Window::new(format!("Event '{}' ID {}", event.name, self.event_id))
.open(open)
.id(self.id())
.show(ctx, |ui| {
Expand Down
Loading

0 comments on commit ec84e01

Please sign in to comment.