Giter VIP home page Giter VIP logo

imagine's Introduction

Imagine

An experimental Rust GUI framework.

WARNING

This is a work in progress and is not meant to be used in production.

The current implementation is quite messy, but it is meant as a proof of concept and I plan to rewrite the majority of the code if this approach seems viable.

Basic Design

Imagine uses an ECS library (specs) which maintains all the widgets in the world. Widgets are composed of various components which is used to determine layout, rendering, and interactivity. Currently the bulk of the layout and render work is done via trait objects and a single Widget component which stores the Widget trit object. This benefit of this approach is that it allows anyone to build their own custom widgets in a separate crate. To demonstrate this, all the available widgets are in the imagine_toolkit crate rather than the imagine crate. Widgets are identifiable by a WidgetId which is a wrapper over a specs Entity. A WidgetId is only constructed when an entity with a widget component has been added to the World. Widgets can store these WidgetIds to keep track of their children. End users use WidgetIds to build their UI hierarchy and to attach event listeners to widgets.

Current Features

  • Widgets
    • Flex Box
    • Padding
    • Label
    • Button
    • Colored Box
  • Basic Interactivity
    • Hover
    • Click

Example

Calculator

Calculator Example

Inspiration

The layout is done via Flutter's box constraints and I have taken a lot of inspiration from druid.

imagine's People

Contributors

cbrewster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

imagine's Issues

UI State

We need to determine how we should handle state within the UI. There is a lot of state in any GUI application, so I believe it should be split up into two main categories:

  1. Application State
    This is the state managed by the user of the library.

  2. UI State
    This is the state of the UI widgets. This includes whether a UI element is hovered, clicked, focused. This also includes text field state: cursor position, selected text, etc...

There are many different approaches to managing this state:

  • Functional
    The UI is a function of the application state. This method works well for frameworks that are built on top of an already functional UI (like web browser DOM) because the UI state is handled at a lower level. This approach is difficult for this project, because UI state like text field selections would have to be stored along side application state. This also requires the UI to be rebuilt every time state is changed (this can be optimized somewhat, but it is still extra overhead).

  • Imperative
    With this approach, we create a single UI tree and store handles to each UI component and update components states via those handles. Users can also subscribe to UI component events to determine when actions occur (ex. button click). This method doesn't require reconstructing the UI tree every time the state changes; however, this approach can lead to inconsistent UI states. The internal state may be updated, but the UI may not be updated to reflect that.

  • Hybrid
    The best approach will probably be some sort of hybrid, but I'm not sure what trade-offs to take yet.

project fails to compile

error[E0433]: failed to resolve: use of undeclared type or module `LayoutRect`
  --> imagine/src/systems/render_system.rs:32:26
   |
32 |             let bounds = LayoutRect::new(LayoutPoint::zero(), builder.content_size());
   |                          ^^^^^^^^^^ use of undeclared type or module `LayoutRect`

error[E0433]: failed to resolve: use of undeclared type or module `LayoutPoint`
  --> imagine/src/systems/render_system.rs:32:42
   |
32 |             let bounds = LayoutRect::new(LayoutPoint::zero(), builder.content_size());
   |                                          ^^^^^^^^^^^ use of undeclared type or module `LayoutPoint`

error[E0433]: failed to resolve: use of undeclared type or module `LayoutPrimitiveInfo`
  --> imagine/src/systems/render_system.rs:34:24
   |
34 |             let info = LayoutPrimitiveInfo::new(bounds);
   |                        ^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `LayoutPrimitiveInfo`

error[E0433]: failed to resolve: use of undeclared type or module `LayoutPoint`
  --> imagine/src/text.rs:32:28
   |
32 |                     point: LayoutPoint::new(position.x, position.y),
   |                            ^^^^^^^^^^^ use of undeclared type or module `LayoutPoint`

error[E0433]: failed to resolve: use of undeclared type or module `LayoutPoint`
  --> imagine/src/text.rs:56:24
   |
56 |                 point: LayoutPoint::new(glyph.point.x + origin.x, glyph.point.y + origin.y),
   |                        ^^^^^^^^^^^ use of undeclared type or module `LayoutPoint`

error[E0433]: failed to resolve: use of undeclared type or module `LayoutSize`
   --> imagine/src/lib.rs:109:34
    |
109 |                     layout_size: LayoutSize::zero(),
    |                                  ^^^^^^^^^^ use of undeclared type or module `LayoutSize`

error[E0433]: failed to resolve: use of undeclared type or module `DeviceIntSize`
   --> imagine/src/lib.rs:178:21
    |
178 |                     DeviceIntSize::new(size.width as i32, size.height as i32)
    |                     ^^^^^^^^^^^^^ use of undeclared type or module `DeviceIntSize`

error[E0433]: failed to resolve: could not find `TypedScale` in `euclid`
   --> imagine/src/lib.rs:182:57
    |
182 |                     framebuffer_size.to_f32() / euclid::TypedScale::new(hidpi_factor as f32);
    |                                                         ^^^^^^^^^^ could not find `TypedScale` in `euclid`

error[E0433]: failed to resolve: use of undeclared type or module `DeviceIntSize`
   --> imagine/src/lib.rs:220:21
    |
220 |                     DeviceIntSize::new(size.width as i32, size.height as i32)
    |                     ^^^^^^^^^^^^^ use of undeclared type or module `DeviceIntSize`

error[E0433]: failed to resolve: use of undeclared type or module `DeviceIntSize`
   --> imagine/src/lib.rs:340:13
    |
340 |             DeviceIntSize::new(size.width as i32, size.height as i32)
    |             ^^^^^^^^^^^^^ use of undeclared type or module `DeviceIntSize`

error[E0433]: failed to resolve: use of undeclared type or module `DeviceIntSize`
   --> imagine/src/lib.rs:405:21
    |
405 |                     DeviceIntSize::new(size.width as i32, size.height as i32)
    |                     ^^^^^^^^^^^^^ use of undeclared type or module `DeviceIntSize`

error[E0433]: failed to resolve: use of undeclared type or module `DeviceIntRect`
   --> imagine/src/lib.rs:411:21
    |
411 |                     DeviceIntRect::new(DeviceIntPoint::zero(), framebuffer_size),
    |                     ^^^^^^^^^^^^^ use of undeclared type or module `DeviceIntRect`

error[E0433]: failed to resolve: use of undeclared type or module `DeviceIntPoint`
   --> imagine/src/lib.rs:411:40
    |
411 |                     DeviceIntRect::new(DeviceIntPoint::zero(), framebuffer_size),
    |                                        ^^^^^^^^^^^^^^ use of undeclared type or module `DeviceIntPoint`

error[E0433]: failed to resolve: use of undeclared type or module `WorldPoint`
   --> imagine/src/lib.rs:433:38
    |
433 |                 let world_position = WorldPoint::new(position.x as f32, position.y as f32);
    |                                      ^^^^^^^^^^ use of undeclared type or module `WorldPoint`

error[E0412]: cannot find type `LayoutPrimitiveInfo` in this scope
  --> imagine/src/text.rs:46:16
   |
46 |         info: &LayoutPrimitiveInfo,
   |                ^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `LayoutPoint` in this scope
  --> imagine/src/text.rs:47:17
   |
47 |         origin: LayoutPoint,
   |                 ^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `LayoutSize` in this scope
   --> imagine/src/lib.rs:181:34
    |
181 |                 let layout_size: LayoutSize =
    |                                  ^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `LayoutSize` in this scope
   --> imagine/src/lib.rs:262:18
    |
262 |     layout_size: LayoutSize,
    |                  ^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `LayoutSize` in this scope
   --> imagine/src/lib.rs:273:34
    |
273 |     pub fn layout_size(&self) -> LayoutSize {
    |                                  ^^^^^^^^^^ not found in this scope

warning: trait objects without an explicit `dyn` are deprecated
  --> imagine/src/widget.rs:47:19
   |
47 |     type Target = Widget;
   |                   ^^^^^^ help: use `dyn`: `dyn Widget`
   |
   = note: `#[warn(bare_trait_objects)]` on by default

warning: trait objects without an explicit `dyn` are deprecated
   --> imagine/src/lib.rs:537:28
    |
537 |     fn clone(&self) -> Box<RenderNotifier> {
    |                            ^^^^^^^^^^^^^^ help: use `dyn`: `dyn RenderNotifier`

error[E0061]: this function takes 5 arguments but 4 arguments were supplied
   --> imagine/src/lib.rs:344:13
    |
344 |             webrender::Renderer::new(gl.clone(), notifier, opts, None).unwrap();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^ ----------  --------  ----  ---- supplied 4 arguments
    |             |
    |             expected 5 arguments

error[E0599]: no method named `set_window_parameters` found for struct `webrender_api::api::RenderApi` in the current scope
   --> imagine/src/lib.rs:408:26
    |
408 |                 self.api.set_window_parameters(
    |                          ^^^^^^^^^^^^^^^^^^^^^ method not found in `webrender_api::api::RenderApi`

error[E0599]: no method named `toggle_debug_flags` found for struct `webrender::renderer::Renderer` in the current scope
   --> imagine/src/lib.rs:426:22
    |
426 |                     .toggle_debug_flags(webrender::DebugFlags::PROFILER_DBG);
    |                      ^^^^^^^^^^^^^^^^^^ help: there is an associated function with a similar name: `get_debug_flags`

error[E0061]: this function takes 12 arguments but 6 arguments were supplied
  --> imagine/src/systems/render_system.rs:36:21
   |
36 |             builder.push_stacking_context(
   |                     ^^^^^^^^^^^^^^^^^^^^^ expected 12 arguments
37 |                 &info,
   |                 -----
38 |                 None,
   |                 ----
39 |                 TransformStyle::Flat,
   |                 --------------------
40 |                 MixBlendMode::Normal,
   |                 --------------------
41 |                 &[],
   |                 ---
42 |                 RasterSpace::Screen,
   |                 ------------------- supplied 6 arguments

error[E0061]: this function takes 6 arguments but 5 arguments were supplied
  --> imagine/src/text.rs:59:17
   |
59 |         builder.push_text(info, &glyphs, font_instance_key, ColorF::BLACK, None);
   |                 ^^^^^^^^^ ----  -------  -----------------  -------------  ---- supplied 5 arguments
   |                 |
   |                 expected 6 arguments

error: aborting due to 24 previous errors

Some errors have detailed explanations: E0061, E0412, E0433, E0599.
For more information about an error, try `rustc --explain E0061`.
error: could not compile `imagine`.

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.