Giter Club home page Giter Club logo

Comments (1)

emilk avatar emilk commented on May 14, 2024 11

You are right in pointing this out, and I haven't quite converged on a final design here, but there is actually some method to the madness.

There are two fundamental categories in Egui:

  • Widgets: buttons, sliders, etc. You use a builder pattern to construct them, and then you add them to a ui, e.g. ui.add(Label::new("Hello world")).

  • Containers: things that wrap code that adds widgets. Examples are ScrollArea, Resize, Frame, CollapsingHeader and Window (which is a wrapper around the four previous ones). Containers need to execute some custom code to add the contents. They follow the form Container::new(...).builder(...).show(ui, |ui| {...})

Since you never run any custom closure for e.g. Label, there makes no sense to unify Widgets and Containers. So that covers your Button and Window examples.

As for ui.collapsing: this is part of a few shortcut functions. Others include ui.button("Click me"), ui.label("Hello world"), ui.checkbox(...) and ui.radio(...). It is a bit inconsistent, but it is so much nicer to write if ui.button("OK").clicked than ui.add(Button::new("OK")).clicked. If Rust supported default, named arguments, this is the way I would design all widgets (instead of using the rather verbose builder pattern).

As for Menu: that was something I threw together pretty quickly. It should probably be refactored into a Container.

from egui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.