Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
update to latest and deprecate this project
Browse files Browse the repository at this point in the history
  • Loading branch information
coderedart committed Mar 1, 2024
1 parent 8ccd2db commit 4e3c300
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
steps:
- uses: actions/checkout@v2 # repo checkout
- uses: mymindstorm/setup-emsdk@v13 # setup emscripten toolchain
with:
version: 3.1.52
- uses: actions-rs/toolchain@v1 # get rust toolchain for wasm
with:
toolchain: stable
Expand Down
15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ edition = "2021"
[features]

[dependencies]
egui = "0.22"
egui = "0.26"
mlua = { version = "0.9", features = ["luau-vector4"] }

[dev-dependencies]
egui_backend = "0.4"
egui_render_glow = "0.4"
egui_commonmark = "0.7"
egui_commonmark = "0.13"

# disable default glfw features on emscripten
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
egui_window_glfw_passthrough = { version = "0.4", default-features = false }
egui_overlay = { version = "0.8.1", default-features = false, features = [
"egui_default",
"three_d",
] }
# enable default glfw feature (enabled by default) on non-wasm platforms.
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
egui_window_glfw_passthrough = { version = "0.4" }
egui_overlay = { version = "0.8.1" }
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Unmaintained
### This repo is abandoned and you are welcome to fork it.

## Deprecation Reason: Performance
1. Due to the immediate mode nature of `egui`, the scripts need to run *every* frame (average of 60 fps atleast).
2. Ui code creates *lots* of temporary `use once` objects, which means lots of garbage collectable objects for a reasonably complex ui script. It is also expensive to create/recreate these objects every frame.
1. Builder pattern creates a struct for every container/widget. eg: `Window::new("hello")` or `RichText::new("text").color(egui.blue)` etc..
2. return values of widget `ui` fn like `Response` also create userdata objects.
3. each `&mut Ui` needs to create a new userdata object to bind that reference to.
4. Even value types like `Rect` will need to be userdata.
3. Due to a large amount of function calls between native host egui and the script, JIT also sucks at optimizing this.
4. All the closures also require jumping between host and guest scopes which have some "setup"/"teardown" costs

This project might still work for some people, and I would encourage them to fork this repo.
But I would like to experiment with retained mode toolkits now, where you only scripts on events.



# luaegui
egui bindings for mlua.

Expand Down
48 changes: 11 additions & 37 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use egui_backend::{BackendConfig, GfxBackend, UserApp, WindowBackend};
use egui_render_glow::GlowBackend;
use egui_window_glfw_passthrough::GlfwBackend;
use egui_overlay::*;
use mlua::Function;

fn main() {
Expand All @@ -9,20 +7,22 @@ fn main() {

const LUA_CODE: &str = include_str!("script.lua");

struct AppData<W: WindowBackend, G: GfxBackend> {
struct AppData {
pub script_time: std::time::Duration,
pub lua: mlua::Lua,
pub code: String,
pub markdown_cache: egui_commonmark::CommonMarkCache,
pub egui_context: egui::Context,
pub gfx_backend: G,
pub window_backend: W,
}

impl<W: WindowBackend, G: GfxBackend> UserApp for AppData<W, G> {
fn gui_run(&mut self) {
impl EguiOverlay for AppData {
fn gui_run(
&mut self,
egui_context: &egui::Context,
_default_gfx_backend: &mut egui_render_three_d::ThreeDBackend,
_glfw_backend: &mut egui_window_glfw_passthrough::GlfwBackend,
) {
use egui::*;
let ctx = self.egui_context.clone();
let ctx = egui_context.clone();
Window::new("README").show(&ctx, |ui| {
egui_commonmark::CommonMarkViewer::new("readme renderer").show(
ui,
Expand Down Expand Up @@ -58,44 +58,18 @@ impl<W: WindowBackend, G: GfxBackend> UserApp for AppData<W, G> {
}
self.script_time = start.elapsed();
}
type UserGfxBackend = G;
type UserWindowBackend = W;
fn get_all(
&mut self,
) -> (
&mut Self::UserWindowBackend,
&mut Self::UserGfxBackend,
&egui::Context,
) {
(
&mut self.window_backend,
&mut self.gfx_backend,
&mut self.egui_context,
)
}
}

fn fake_main() {
let mut window_backend = GlfwBackend::new(
Default::default(),
BackendConfig {
is_opengl: true,
..Default::default()
},
);
let gfx_backend = GlowBackend::new(&mut window_backend, Default::default());
let lua = mlua::Lua::new();
luaegui::register_egui_bindings(&lua).unwrap();
let app = AppData {
egui_context: Default::default(),
gfx_backend,
window_backend,
lua,
code: LUA_CODE.to_string(),
script_time: std::time::Duration::ZERO,
markdown_cache: Default::default(),
};
GlfwBackend::run_event_loop(app);
start(app)
}

const README: &str = include_str!("../README.md");
75 changes: 38 additions & 37 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use egui::{
epaint::Shadow,
load::SizedTexture,
style::{Spacing, WidgetVisuals},
Align, Align2, Area, CentralPanel, Color32, Context, Direction, Frame, Id, LayerId, Layout,
Margin, Order, PointerButton, Pos2, Rect, RichText, Rounding, Sense, SidePanel, Stroke, Style,
Expand Down Expand Up @@ -73,8 +74,8 @@ fn add_context(lua: &Lua, _: &Table) -> mlua::Result<()> {
impl LuaHelperTrait for Id {
fn from_lua(value: Value) -> Result<Self> {
Ok(match value {
Value::Nil => Id::null(),
Value::String(s) => Id::null().with(s.to_str().unwrap_or_default()),
Value::Nil => Id::NULL,
Value::String(s) => Id::NULL.with(s.to_str().unwrap_or_default()),
Value::UserData(u) => {
*u.borrow()
.map_err(|_e| mlua::Error::FromLuaConversionError {
Expand Down Expand Up @@ -106,7 +107,7 @@ impl LuaHelperTrait for Id {
lua.register_userdata_type(|reg: &mut UserDataRegistry<Id>| {
reg.add_method("with", |lua, this, value: Value| {
lua.create_any_userdata(match value {
Value::Nil => Id::null(),
Value::Nil => Id::NULL,
Value::Boolean(b) => this.with(b),
Value::Integer(b) => this.with(b),
Value::String(b) => this.with(b),
Expand All @@ -123,7 +124,7 @@ impl LuaHelperTrait for Id {
Ok(this.short_debug_format())
});
})?;
id.set("null", lua.create_any_userdata(Id::null())?)?;
id.set("null", lua.create_any_userdata(Id::NULL)?)?;
egui_table.set("id", id)?;
Ok(())
}
Expand Down Expand Up @@ -166,7 +167,7 @@ fn add_widget_visuals(lua: &Lua, egui_table: &Table) -> mlua::Result<()> {
Ok(())
});
})?;
id.set("null", lua.create_any_userdata(Id::null())?)?;
id.set("null", lua.create_any_userdata(Id::NULL)?)?;
egui_table.set("id", id)?;
Ok(())
}
Expand Down Expand Up @@ -246,16 +247,16 @@ fn add_spacing(lua: &Lua, _egui_table: &Table) -> mlua::Result<()> {
Ok(this.indent_ends_with_horizontal_line)
});
reg.add_field_method_get("combo_height", |_, this| Ok(this.combo_height));
reg.add_field_method_get("scroll_bar_width", |_, this| Ok(this.scroll_bar_width));
reg.add_field_method_get("scroll_handle_min_length", |_, this| {
Ok(this.scroll_handle_min_length)
});
reg.add_field_method_get("scroll_bar_inner_margin", |_, this| {
Ok(this.scroll_bar_inner_margin)
});
reg.add_field_method_get("scroll_bar_outer_margin", |_, this| {
Ok(this.scroll_bar_outer_margin)
});
// reg.add_field_method_get("scroll_bar_width", |_, this| Ok(this.scroll_bar_width));
// reg.add_field_method_get("scroll_handle_min_length", |_, this| {
// Ok(this.scroll_handle_min_length)
// });
// reg.add_field_method_get("scroll_bar_inner_margin", |_, this| {
// Ok(this.scroll_bar_inner_margin)
// });
// reg.add_field_method_get("scroll_bar_outer_margin", |_, this| {
// Ok(this.scroll_bar_outer_margin)
// });

// reg.add_field_method_set("weak_bg_fill", |_, this, value: Value| {
// this.weak_bg_fill = Color32::from_lua(value)?;
Expand Down Expand Up @@ -591,12 +592,12 @@ fn add_ui(lua: &Lua, _egui_table: &Table) -> mlua::Result<()> {
},
);

reg.add_method(
"debug_paint_cursor",
|_, this, ()| {
Ok(this.debug_paint_cursor())
},
);
// reg.add_method(
// "debug_paint_cursor",
// |_, this, ()| {
// Ok(this.debug_paint_cursor())
// },
// );
reg.add_method_mut("drag_angle", |lua, this, value: Table| {
let mut b: f32 = value.get("value")?;
let result = lua.create_any_userdata(this.drag_angle(&mut b));
Expand Down Expand Up @@ -749,7 +750,7 @@ fn add_ui(lua: &Lua, _egui_table: &Table) -> mlua::Result<()> {
reg.add_method("id", |lua, this, ()| lua.create_any_userdata(this.id()));

reg.add_method_mut("image", |lua, this, (texture, size): (UserDataRef<TextureHandle>, Value)| {
lua.create_any_userdata(this.image(texture.id(), Vec2::from_lua(size)? ))
lua.create_any_userdata(this.image(SizedTexture::new(texture.id(), Vec2::from_lua(size)?) ))
});
reg.add_method_mut(
"indent",
Expand Down Expand Up @@ -1143,7 +1144,7 @@ impl LuaHelperTrait for Rounding {
)?;
rounding.set(
"none",
lua.create_function(|lua, ()| Rounding::to_lua(Rounding::none(), lua))?,
lua.create_function(|lua, ()| Rounding::to_lua(Rounding::ZERO, lua))?,
)?;
rounding.set(
"is_same",
Expand Down Expand Up @@ -1262,8 +1263,8 @@ impl LuaHelperTrait for Color32 {
color32.set("gold", Color32::to_lua(Color32::GOLD, lua)?)?;
color32.set("debug_color", Color32::to_lua(Color32::DEBUG_COLOR, lua)?)?;
color32.set(
"temporary_color",
Color32::to_lua(Color32::TEMPORARY_COLOR, lua)?,
"placeholder_color",
Color32::to_lua(Color32::PLACEHOLDER, lua)?,
)?;

color32.set(
Expand Down Expand Up @@ -1914,10 +1915,10 @@ fn add_area(lua: &Lua, egui_table: &Table) -> Result<()> {
*this = this.default_pos(Pos2::from_lua(default_pos)?);
Ok(())
});
area.add_method_mut("drag_bounds", |_, this, bounds: Value| {
*this = this.drag_bounds(Rect::from_lua(bounds)?);
Ok(())
});
// area.add_method_mut("drag_bounds", |_, this, bounds: Value| {
// *this = this.drag_bounds(Rect::from_lua(bounds)?);
// Ok(())
// });
area.add_method_mut("enabled", |_, this, enabled: bool| {
*this = this.enabled(enabled);
Ok(())
Expand Down Expand Up @@ -2065,14 +2066,14 @@ fn add_window(lua: &Lua, egui_table: &Table) -> Result<()> {
);
Ok(())
});
window.add_method_mut("drag_bounds", |_, this, bounds: Value| {
*this = Some(
this.take()
.ok_or_else(|| mlua::Error::RuntimeError("window is null".to_owned()))?
.drag_bounds(Rect::from_lua(bounds)?),
);
Ok(())
});
// window.add_method_mut("drag_bounds", |_, this, bounds: Value| {
// *this = Some(
// this.take()
// .ok_or_else(|| mlua::Error::RuntimeError("window is null".to_owned()))?
// .drag_bounds(Rect::from_lua(bounds)?),
// );
// Ok(())
// });
window.add_method_mut("enabled", |_, this, enabled: bool| {
*this = Some(
this.take()
Expand Down

0 comments on commit 4e3c300

Please sign in to comment.