Giter VIP home page Giter VIP logo

azul's Introduction

Azul - Desktop GUI framework

CI Coverage Status LICENSE Rust Compiler Version dependency status

Azul is a free, functional, reactive GUI framework for Rust, C and C++, built using the WebRender rendering engine and a CSS / HTML-like document object model for rapid development of beautiful, native desktop applications

Features

Azul uses webrender (the rendering engine behind Firefox) to render your UI, so it supports lots of common CSS features like:

  • gradients (linear, radial, conic)
  • box shadows
  • SVG filters
  • composition operators (multiply, darken, etc.)
  • border styling
  • border-radii
  • scrolling / automatic overflow
  • CSS transforms

See the list of supported CSS keys / values for more info.

On top of that, Azul features...

  • lots of built-in widgets (Button, TextInput, CheckBox, ColorInput, TextInput, NumberInput)
  • embedding OpenGL textures
  • simplified HTML-like relative/absolute layout system based on CSS flexbox
  • 60+ FPS animations via Animation API
  • cross-platform native dialogs
  • cross-platform text shaping and rendering
  • SVG parsing and rendering
  • shape tesselation for rendering large numbers of 2D lines, circles, rects, shapes, etc. in a single draw call
  • managing off-main-thread tasks for I/O
  • dynamic linking via shared library*
  • usable from Rust, C, C++ and Python via auto-generated API bindings**
  • HTML-to-Rust compilation for fast prototyping / hot reload

* static linking not yet available

** C++ bindings and Python are not yet stabilized and might not work depending on the branch you're using. They will be stabilized before the release.

Screenshots

image image image image

Hello World

Python

from azul import *

class DataModel:
    def __init__(self, counter):
        self.counter = counter

def render_dom(data, info):
    
    label = Dom.text("{}".format(data.counter))
    label.set_inline_style("font-size: 50px;")
    
    button = Button("Increment counter")
    button.set_on_click(data, increment_counter)

    dom = Dom.body()
    dom.add_child(label)
    dom.add_child(button.dom())

    return dom.style(Css.empty())

def increment_counter(data, info):
    data.counter += 1;
    return Update.RefreshDom

app = App(DataModel(5), AppConfig(LayoutSolver.Default))
app.run(WindowCreateOptions(render_dom))

Rust

use azul::prelude::*;
use azul::widgets::{button::Button, label::Label};

struct DataModel {
    counter: usize,
}

extern "C" 
fn render_dom(data: &mut RefAny, _: &mut LayoutInfo) -> StyledDom {

    let data = data.downcast_ref::<DataModel>()?;

    let label = Dom::text(format!("{}", data.counter))
        .with_inline_style("font-size: 50px;");
        
    let button = Button::new("Increment counter")
        .onmouseup(increment_counter, data.clone());

    Dom::body()
    .with_child(label)
    .with_child(button.dom())
    .style(Css::empty())
}

extern "C" 
fn increment_counter(data: &mut RefAny, _: &mut CallbackInfo) -> Update {
    let mut data = data.downcast_mut::<DataModel>()?;
    data.counter += 1;
    Update::RefreshDom // call render_dom() again
}

fn main() {
    let initial_data = RefAny::new(DataModel { counter: 0 });
    let app = App::new(initial_data, AppConfig::default());
    app.run(WindowCreateOptions::new(render_dom));
}

C

#include "azul.h"

typedef struct {
    uint32_t counter;
} DataModel;

void DataModel_delete(DataModel* restrict A) { }
AZ_REFLECT(DataModel, DataModel_delete);

AzStyledDom render_dom(AzRefAny* data, AzLayoutInfo* info) {

    DataModelRef d = DataModelRef_create(data);
    if !(DataModel_downcastRef(data, &d)) {
        return AzStyledDom_empty();
    }
    
    char buffer [20];
    int written = snprintf(buffer, 20, "%d", d->counter);
    AzString const labelstring = AzString_copyFromBytes(&buffer, 0, written);
    AzDom label = AzDom_text(labelstring);
    AzString const inline_css = AzString_fromConstStr("font-size: 50px;");
    AzDom_setInlineStyle(&label, inline_css);
    
    AzString const buttontext = AzString_fromConstStr("Increment counter");
    AzButton button = AzButton_new(buttontext, AzRefAny_clone(data));
    AzButton_setOnClick(&button, incrementCounter);

    AzDom body = Dom_body();
    AzDom_addChild(body, AzButton_dom(&button));
    AzDom_addChild(body, label);
    
    AzCss global_css = AzCss_empty();
    return AzDom_style(body, global_css);
}

Update incrementCounter(RefAny* data, CallbackInfo* event) {
    DataModelRefMut d = DataModelRefMut_create(data);
    if !(DataModel_downcastRefMut(data, &d)) {
        return Update_DoNothing;
    }
    d->ptr.counter += 1;
    DataModelRefMut_delete(&d);
    return Update_RefreshDom;
}

int main() {
    DataModel model = { .counter = 5 };
    AzApp app = AzApp_new(DataModel_upcast(model), AzAppConfig_default());
    AzApp_run(app, AzWindowCreateOptions_new(render_dom));
    return 0;
}

License

Azul is licensed under the MPL-2.0. Which means that yes, you can build proprietary applications using azul without having to publish your code: you only have to publish changes made to the library itself.

Copyright 2017 - current Felix Schütt

azul's People

Contributors

antonok-edm avatar atul9 avatar brainstorm avatar brianharris avatar chungzh avatar cubetastic33 avatar dashaw92 avatar datatriny avatar dependabot[bot] avatar dignifiedquire avatar forloveofcats avatar fschutt avatar hattshire avatar iohannrabeson avatar jwharrie avatar kibouo avatar liigo avatar locks avatar pythoneer avatar serdnad avatar stubbfel avatar tobia avatar trimental avatar usagi avatar victorkoenders avatar vn971 avatar waywardmonkeys avatar whmountains avatar xoronic avatar yatekii avatar

Stargazers

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

Watchers

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

azul's Issues

glutin breaks after using azul

Description

This is a very strange bug. But the scenario is that I open an azul window, close it and then use glutin to create another window. Even minimal usage of glutin (without even initializing gl) completely breaks.

Version / OS

  • azul version: 8586f0f
  • Operating system: Windows 10 (this likely is specific to Windows)

Steps to Reproduce

app.run(Window::new(window_options, css).unwrap()).unwrap();

let events_loop = glutin::EventsLoop::new();
let window = glutin::WindowBuilder::new().build(&events_loop).unwrap();

Expected Behavior

The second window shows up.

Actual Behavior

The code panics deep within winit.

Additional Information

If you replace glutin with winit it works. So this must be something that glutin does in addition to winit's logic.

Impossible to override native styles using alternate dom syntax

Description

When using Label::new(...).dom().with_class("foo"), the foo class does not override the native styles provided by Css::hot_reload_override_native. Switching to Dom::new(NodeType::Label(...)).with_class("foo") works as expected.

Version / OS

  • azul version: latest from git (679af60)

  • Operating system: Linux

  • Windowing system (X11 or Wayland, Linux only): X11

Steps to Reproduce

Starting from the "Hello world" counter example from the README:
Add .with_class("label") to the end of the let label = line.
Switch the CSS from Css::native() to Css::hot_reload("style.css").unwrap()
Add the "style.css" file with the following contents:

.label {
    background-color: #000;
}

Expected Behavior

The top half of the screen should have a black background. This would match the behavior of declaring the label with the following line:

let label = Dom::new(NodeType::Label(format!("{}", self.counter))).with_class("label");

Actual Behavior

The top half of the screen has a white background.

`flex-grow: 0` still distributing remaining space, intended behavior?

I was wondering if the current flexbox behavior is intended. When you use flexbox on the web, not setting any flex-grow values basically means "distribute the children inside the flexbox without altering their size". You can then use child items that contain text which will nicely show one after the other inside the flexbox, without any extra space between each item or any added "padding" to the text items.

When I'm using azul this doesn't seem to be possible, by default flexbox items are stretched to fill all remaining space. The only way to get around this issue is by explicitly specifying the width or height of the item, but this isn't feasible when you want to use this to "auto size" a text element according to its content.

Here are a few different flex-grow combinations:

All items no flex-grow specified / all items flex-grow: 0 (NOK)

Azul

Web

all items flex-grow: 1 (OK)

Azul

Web

1 item with flex-grow: 2 others flex-grow: 1 (OK)

Azul

Web

1 item with flex-grow: 2 others flex-grow: 0 / 1 item with flex-grow: 2 others no flex-grow specified (NOK)

Azul

Web

1 item without flex-grow others flex-grow: 2 (NOK)

Azul

Web

1 item with flex-grow: 1, others flex-grow: 2 (OK)

Azul

Web

Web reference can be found here: https://jsfiddle.net/Lwm8k5t9/3/

UI blank and renders only after resize/click

Description

When trying out the examples on my machine, I noticed that reproducibly the UI only shows after I force a redraw by resizing the window or clicking somewhere inside it.

Version / OS

Steps to Reproduce

  • Create a new cargo project with azul as dependency.
  • paste one of the azul examples in main.rs
  • cargo run

Expected Behavior

The window opens and immediately shows the rendered example.

Actual Behavior

The window is empty and only redraws the example when resizing the window or clicking somewhere.

screenshot from 2018-11-25 12-25-03

After clicking:
screenshot from 2018-11-25 12-25-23

Additional Information

Fonts are squished

Description

The text rendering places glyphs very close to each other, much closer than they should be. This is independent of the font and also seems to happen in the screenshots in this repo.

Version / OS

  • azul version: Commit 95dc353
  • Operating system: Windows 10

Steps to Reproduce

Just render any text.

Expected Behavior

The text shouldn't be squished.
Browser:
https://i.imgur.com/MSuvYGD.png

Actual Behavior

The text is squished.
Azul:
https://i.imgur.com/ipgnnc7.png

"RSX" Component builder with macros

Description

One thing that I feel as though Azul could benefit from is a way to create structured DOMs in a more declarative fashion, if we look to WASM interface frameworks, we can see this idea with how yew allows users to craft interfaces.

Describe your solution

A macro like dom! or html! that would allow people to make GUIs in a way that resembles JSX or TSX in frontend web development terms

Are there alternatives or drawbacks?

  • Sticking with the current system, despite it being less declarative
  • Maintaining the macro might be a pain, I'm not sure

Is this a breaking change

No, the old way of creating UIs could exist side by side with this

Display issues on MacOS

As discussed in #4 I'm working on getting Azul to run on MacOS. There were no problems with the build but I currently get a blank screen when I try to load an SVG.

At first every time I loaded an SVG the program would panic with version 130 is not supported. I tried switching to #version 140 since that's what the glium examples use and sure enough, no more crashes.

What I have now is:

  • App window flashes white at startup, then turns black.
  • Clicking the black window opens a file picker.
  • I choose tiger.svg from the repository.
  • App window turns white, and the terminal logs 5 identical messages about pan and zoom.

I'm not sure if the shaders need to be updated to support version 140, or if the bug lies elsewhere. I'm not super familiar with graphics programming so any thoughts would be appreciated.

Question about sleep times

Somehow I'm failing to understand how this code will wait until 16 ms have passed.

// Wait until 16ms have passed
let time_end = Instant::now();
let diff = time_end - time_start;
if diff < Duration::from_millis(16) {
    thread::sleep(diff);
}

Context here: https://github.com/maps4print/azul/blob/master/src/app.rs#L247-L252

Assume the last frame took 1ms to draw. diff == 1 in that case, so the thread will be sleeping for 1ms instead of the desired 15 ms.

I'm thinking the code could be changed to something like this:

// Wait until 16ms have passed
let diff = time_start.elapsed();
let frame_time = Duration::from_millis(16);
if diff < frame_time {
    thread::sleep(frame_time - diff);
}

Not closing when try to exit in example "async"

Description

In the example program "async", when I started the 10 seconds countdown, and try to exit during this time, it just hold there.

I did some debugging, seeing that is probably the tasks are waiting to exit. Maybe we should think about a method to interrupt or kill the thread nicely? Force to kill the thread may result in inconsistent states, but I think we really should provide a way to exit during task evaluating instead of just waiting for it to end.

Version / OS

  • azul version: git version 2b9a791

  • Operating system: Manjaro linux

  • Windowing system (X11 or Wayland, Linux only): i3wm

Steps to Reproduce

Run the program, and starts the count down, and try exit.

Expected Behavior

Exit immediately

Actual Behavior

Still waiting for 10 seconds countdown.

Additional Information

Build error with rustc 1.31.0-nightly (96064eb61 2018-10-28)

Description

azul git:(master) $ rustc --version
rustc 1.31.0-nightly (96064eb61 2018-10-28)
azul git:(master) $ cargo run --example async
   Compiling azul v0.1.0 (/home/omer/rust/azul)
error: unused return value of `ui_solver::<impl id_tree::Arena<ui_solver::WidthCalculatedRect>>::bubble_preferred_widths_to_parents` that must be used
   --> src/ui_solver.rs:682:5
    |
682 |     width_calculated_arena.bubble_preferred_widths_to_parents(&layout_only_arena, &non_leaf_nodes_sorted_by_depth);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: lint level defined here
   --> src/lib.rs:67:9
    |
67  | #![deny(unused_must_use)]
    |         ^^^^^^^^^^^^^^^

error: unused return value of `ui_solver::<impl id_tree::Arena<ui_solver::HeightCalculatedRect>>::bubble_preferred_heights_to_parents` that must be used
   --> src/ui_solver.rs:697:5
    |
697 |     height_calculated_arena.bubble_preferred_heights_to_parents(&layout_only_arena, &solved_widths.non_leaf_nodes_sorted_by_depth);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

error: Could not compile `azul`.

To learn more, run the command again with --verbose.

Version / OS

  • azul version: git HEAD

  • Operating system: Xubuntu 18.04

  • Windowing system (X11 or Wayland, Linux only): X11

Steps to Reproduce

cargo run --example async

Expected Behavior

Should run

Actual Behavior

Fails to build

Additional Information

Doc-tests fails in master-branch

Description

   Doc-tests azul

running 8 tests
test src/app.rs - app::App<T>::run (line 176) ... ignored
test src/app_state.rs - app_state::AppState::windows (line 32) ... ignored
test src/css.rs - css::DynamicCssProperty (line 145) ... ignored
test src/default_callbacks.rs - default_callbacks::stack_checked_pointer::is_subtype_of (line 135) ... ignored
test src/window.rs - window::Window::marker (line 498) ... ignored
test src/window.rs - window::Window::marker (line 504) ... ignored
test src/app.rs - app::App<T>::delete_font (line 430) ... FAILED
test src/app_state.rs - app_state::AppState<T>::add_font (line 132) ... ok

failures:

---- src/app.rs - app::App<T>::delete_font (line 430) stdout ----
error[E0599]: no method named `mock_render_frame` found for type `azul::prelude::App<MyAppData>` in the current scope
  --> src/app.rs:447:5
   |
19 | app.mock_render_frame();
   |     ^^^^^^^^^^^^^^^^^

thread 'src/app.rs - app::App<T>::delete_font (line 430)' panicked at 'couldn't compile the test', librustdoc/test.rs:330:13
note: Run with `RUST_BACKTRACE=1` for a backtrace.


failures:
    src/app.rs - app::App<T>::delete_font (line 430)

test result: FAILED. 1 passed; 1 failed; 6 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--doc'

Version / OS

  • azul version:
    Version 0.1.0

  • Operating system:
    Linux 4.15.0-34-generic x86_64 (Ubuntu 18.04.1)

  • Windowing system (X11 or Wayland, Linux only):
    X11

Steps to Reproduce

Run cargo test in the project directory.

Additional Information

$ rustup toolchain list
stable-x86_64-unknown-linux-gnu (default)

$ cargo --version
cargo 1.28.0 (96a2c7d16 2018-07-13)

$ rustc --version
rustc 1.28.0 (9634041f0 2018-07-30)

Everything is too huge

Description

When I start the demo app, it is about twice as large as my screen. The font appears to be about double what it's supposed to be.

Version / OS

  • azul version: 0.1.0

  • Operating system: Debian linux, openbox window manager

  • Windowing system (X11 or Wayland, Linux only): X11

Expected Behavior

Draw from system info that doesn't lie about the dpi or the screen size, or do some sanity checking to notice when that info is lies and do something sensible instead

Actual Behavior

Similar to Servo, everything is too huge (the problem might be upstream, but I'm reluctant to report it to servo, because in servo's case the issue is confounded with many other problems happening at the same time.)

Additional Information

This issue may have something to do with the fact I'm using a tv as a monitor. Until recently, many other apps had similar issues, either rendering text and icons way too large (most qt apps), or, strangely, in the case of openbox and tint2, rendering text way too small. Most apps, though (chrome, firefox, terminals, other gtk apps), got along fine.

While reporting this bug, though, I got around to creating a ~/.Xresources file, containing Xft.dpi: 75. This has corrected all of the offending programs I was aware of, but it has not corrected the azul demo.

Blank window on osx

Description

I followed the instructions of the tutorial and build the app for osx, also tried the examples in the repository. But every time I see a blank window. I then tried added a button and logged on every click the logged appeared but the button is invisible.

The same code works on Windows machine that I tried. Dose anyone have an idea were is the problem. I can try to fix it by myself if someone directs me were to look.

Version / OS

  • Operating system:
    MacOS Majave version 10.14

Helloworld broken

Description

The hello world program on the website won't compile.

Version / OS

  • azul version: v0.1.0
  • Operating system: Solus

Steps to Reproduce

Take the example helloworld program on the website and try to compile it.

Expected Behavior

For it to compile

Actual Behavior

It doesn't compile

Solution

I found the answer going through the debug example. at the line:
let mut app = App::new(MyDataModel { counter: 0 });
it needs to be:
let mut app = App::new(MyDataModel { counter: 0 }, AppConfig::default());
This makes the helloworld program compile and would give people coming to this Gui framework a better experanice.

Documentation on docs.rs?

It would be nice if azul had full docs on docs.rs, like most rust crates. Is there a reason this doesn't exist right now?

Running the HelloWorld application on windows panics

Description

$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.46s
     Running `target\debug\guitests.exe`
[ERROR][azul::logging] An unexpected panic ocurred, the program has to exit.
Please report this error and attach the log file found in the directory of the executable.

The error ocurred in: libcore\result.rs at line 945 in thread main

Error information:
called `Result::unwrap()` on an `Err` value: CreateError(NotSupported("required extension \"WGL_ARB_create_context_profile\" not found"))

Backtrace:

backtrace::backtrace @ mod.rs:42
backtrace::capture::Backtrace @ capture.rs:88
backtrace::capture::Backtrace @ capture.rs:64
azul::logging::set_up_panic_hooks @ logging.rs:87
core::ops::function::Fn::call<fn(core::panic::PanicInfo*),(core::panic @ function.rs:73
std::panicking @ panicking.rs:482
std::panicking @ panicking.rs:390
std::panicking @ panicking.rs:325
core::panicking @ panicking.rs:77
core::result::unwrap_failed<azul::window @ macros.rs:26
core::result::Result<azul::window::Window<guitests::DataModel>, azul::window::WindowCreateError>::unwrap<azul::window::Window<guitests::DataModel>,azul::window @ result.rs:782
guitests @ main.rs:28
std::rt::lang_start @ rt.rs:74
std::panicking::try @ panicking.rs:310
panic_unwind @ lib.rs:105
std::rt @ rt.rs:58
std::rt @ rt.rs:74
 @ exe_common.inl:253

error: process didn't exit successfully: `target\debug\guitests.exe` (exit code: 101)

Version / OS

  • azul version: master
  • Operating system: Windows 8

Does not build, "expat is required" while building servo-fontconfig-sys v4.0.7

Description

Trying to build the example code here https://azul.rs/ with

[dependencies]
azul = { git = "https://github.com/maps4print/azul" }

The build does not succeed

...
   Compiling x11-clipboard v0.3.0                                                                                              
   Compiling serde_derive v1.0.66                                                                                              
   Compiling lyon_tessellation v0.11.0                                                                                         
   Compiling lyon_algorithms v0.11.2                                                                                           
   Compiling wayland-commons v0.20.12                                                                                          
   Compiling clipboard2 v0.1.1                                                                                                 
   Compiling lyon v0.11.0                                                                                                      
error: failed to run custom build command for `servo-fontconfig-sys v4.0.7`                                                    
process didn't exit successfully: `/home/mako/programming/dataBrowser/azmes/target/debug/build/servo-fontconfig-sys-16ec22efbcd7c1cd/build-script-build` (exit code: 101)
--- stdout
cd /home/mako/programming/dataBrowser/azmes/target/debug/build/servo-fontconfig-sys-fe78eda65efae03d/out && \
	CC="gcc" \
	AR="ar" \
	FREETYPE_CFLAGS="" \
	FREETYPE_LIBS="" \
	CFLAGS=""" -fPIC" \
	/home/mako/.cargo/registry/src/github.com-1ecc6299db9ec823/servo-fontconfig-sys-4.0.7/configure \
	--disable-docs \
	--disable-shared \
	 \
	--host=x86_64-unknown-linux-gnu --sysconfdir=/etc --localstatedir=/var
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for x86_64-unknown-linux-gnu-strip... no
checking for strip... strip

...

checking for FT_Get_X11_Font_Format... cflags:  -fPIC -I/usr/include/freetype2
cppflags: 
ldflags: 
libs:  -lfreetype
yes
checking for FT_Select_Size... cflags:  -fPIC -I/usr/include/freetype2
cppflags: 
ldflags: 
libs:  -lfreetype
yes
checking for FT_Bitmap_Size.y_ppem... yes
checking for EXPAT... no
checking expat.h usability... no
checking expat.h presence... no
checking for expat.h... no
checking xmlparse.h usability... no
checking xmlparse.h presence... no
checking for xmlparse.h... no
makefile.cargo:83: recipe for target '/home/mako/programming/dataBrowser/azmes/target/debug/build/servo-fontconfig-sys-fe78eda65efae03d/out/Makefile' failed

--- stderr
configure: error: 
*** expat is required. or try to use --enable-libxml2
make: *** [/home/mako/programming/dataBrowser/azmes/target/debug/build/servo-fontconfig-sys-fe78eda65efae03d/out/Makefile] Error 1
thread 'main' panicked at 'assertion failed: Command::new("make").env("MAKEFLAGS",
                         env::var("CARGO_MAKEFLAGS").unwrap_or_default()).args(&["-R",
                                                                                 "-f",
                                                                                 "makefile.cargo"]).status().unwrap().success()', /home/mako/.cargo/registry/src/github.com-1ecc6299db9ec823/servo-fontconfig-sys-4.0.7/build.rs:20:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

warning: build failed, waiting for other jobs to finish...
error: build failed                                    

Version / OS

  • azul version: github as it is now

  • Operating system: Debian stretch

  • Windowing system (X11 or Wayland, Linux only): X11

error: no matching version `^0.5.2` found for package `dwrote`

Description

I followed the steps for installing Azul mentioned in the wiki. When I try to build the initial "hello world" application with Azul as an dependency I get the following error:

error: no matching version `^0.5.2` found for package `dwrote`
location searched: registry `https://github.com/rust-lang/crates.io-index`
versions found: 0.6.0, 0.5.1, 0.5.0, ...
required by package `webrender v0.57.2 (https://github.com/servo/webrender?rev=f4941fb8d126f893f01f3511ab9bb4d15dbbab70#f4941fb8)`
    ... which is depended on by `azul v0.1.0 (https://github.com/maps4print/azul#170bd198)`
    ... which is depended on by `azul_app v0.1.0 (file:///Users/myuser/Documents/Programming/RustProjects/azul_app)`

My Cargo.toml file looks like this

[package]
name = "azul_app"
version = "0.1.0"
authors = ["Alexander Weiß"]

[dependencies]
# use the latest commit (time of writing it is #170bd1980e9833894be7678dfe2d2c429957b934)
azul = { git = "https://github.com/maps4print/azul"} 

Version / OS

  • azul version: 0.1.0
  • Operating system: Mac OS 10.14 (Mojave)

Steps to Reproduce

Follow the installation steps in the wiki

Expected Behavior

Azul should build fine

Actual Behavior

Azul does not build with the error mentioned above

Additional Information

I looked in the dependencies and it seems that the servo WebRender project updated it's dwrote dependency to 0.6.0. (Commit in servo) I think it should be fine to change the servo/webrender in Azul to the commit where the dwrote dependency was updated.

How to add daemons from inside a DefaultCallback?

I'm fairly familiar with rust, and am just starting to learn azul's framework. Expanding on the two-way data binding tutorial, I'd like to add a daemon to blink a cursor within the text field.
How do you add a daemon from within a DefaultCallback?

It seems like you can only add_daemon() when AppState<T> or App<T> is available, not from the AppStateNoData<T> passed to default callbacks. From the docs, I gather that AppStateNoData is meant for use in smaller scopes without access to the main state datatype (as is the case in the two-way data binding tutorial: accessing TextInputState rather than MyAppData).
I must be missing something, otherwise all daemons would need to be added in the user code rather than the library code for each widget.

Any help is greatly appreciated. Happy to see active development on a promising light-weight GUI solution for rust.

Starting to use azul

Hi!

I have eagerly been following your project. It looks very promising.

I am looking into using azul for my project where I use my own 2D renderer for the main canvas.
Atm I use relm with gtk-rs. but GTK is really suboptimal, especially when it comes to rendering to an OGL canvas.

Now, I am well aware that azul is in a pretty early stage, but I am very willing to take all the bugs and maybe even fix them if the base features work.

So what I need is basic text-input like <input> in HTML and rendering to a canvas. How well is this doable atm? I saw the explanations concerning my own 2D rendering in the README.md but that code doesn't seem to do anything with OGL at all.

Can you tell me if those two features work in a base form and maybe point me to it?

Btw, do you use caching like a vdom internally? Or do you just calculate the entire UI each frame?

Best,
Yatekii

Crash on Linux, X11, in Calculator example

Video on YouTube - I'm clicking the multiply button, yet nothing happens.

Then, as seen in the video, it crashes:

An unexpected panic ocurred, the program has to exit.
Please report this error and attach the log file found in the directory of the executable.

The error ocurred in: examples/calculator.rs at line 108 in thread main

Error information:
attempt to subtract with overflow

Backtrace:

backtrace::backtrace::libunwind::trace @ libunwind.rs:53
backtrace::backtrace::trace @ mod.rs:42
backtrace::capture::Backtrace::new_unresolved @ capture.rs:88
backtrace::capture::Backtrace::new @ capture.rs:63
azul::logging::set_up_panic_hooks::panic_fn @ logging.rs:87
core::ops::function::Fn::call @ function.rs:73
std::panicking::rust_panic_with_hook @ panicking.rs:479
std::panicking::continue_panic_fmt @ panicking.rs:390
 @ panicking.rs:325
core::panicking::panic_fmt @ panicking.rs:77
core::panicking::panic @ panicking.rs:52
calculator::OperandStack::get_number @ calculator.rs:108
calculator::handle_mouseclick_numpad::{{closure}} @ calculator.rs:231
&lt;alloc::sync::Arc&lt;std::sync::mutex::Mutex&lt;T&gt;&gt; as azul::traits::Modify&lt;T&gt;&gt;::modify @ traits.rs:45
calculator::handle_mouseclick_numpad @ calculator.rs:229
azul::app::do_hit_test_and_call_callbacks::{{closure}} @ app.rs:770
azul::app::do_hit_test_and_call_callbacks @ app.rs:782
&lt;azul::app::App&lt;T&gt;&gt;::run_inner @ app.rs:255
&lt;azul::app::App&lt;T&gt;&gt;::run @ app.rs:209
calculator::main @ calculator.rs:260
std::rt::lang_start::{{closure}} @ rt.rs:74
std::rt::lang_start_internal::{{closure}} @ rt.rs:59
std::panicking::try::do_call @ panicking.rs:310
 @ lib.rs:105
std::panicking::try @ panicking.rs:289
std::panic::catch_unwind @ panic.rs:392
std::rt::lang_start_internal @ rt.rs:58
std::rt::lang_start @ rt.rs:74
unresolved function

Panic running debug example on mac

I get a panic running the debug example. Rust 1.29.2, macOS 10.12.6

[ERROR][azul::logging] We are sorry, an unexpected panic ocurred, the program has to exit.
Please report this error and attach the log file found in the directory of the executable.

The error ocurred in: libcore/option.rs at line 345 in thread main

Error information:
called `Option::unwrap()` on a `None` value

Backtrace:

backtrace::backtrace::trace @ mod.rs:42
backtrace::capture::Backtrace::new_unresolved @ capture.rs:88
backtrace::capture::Backtrace::new @ capture.rs:63
azul::logging::set_up_panic_hooks::panic_fn @ logging.rs:84
core::ops::function::Fn::call @ function.rs:73
std::panicking::rust_panic_with_hook @ panicking.rs:479
std::panicking::continue_panic_fmt @ panicking.rs:390
 @ panicking.rs:325
core::panicking::panic_fmt @ panicking.rs:77
core::panicking::panic @ panicking.rs:52
<core::option::Option<T>>::unwrap @ macros.rs:20
debug::my_button_click_handler @ debug.rs:150
azul::app::do_hit_test_and_call_callbacks::{{closure}} @ app.rs:723
azul::app::do_hit_test_and_call_callbacks @ app.rs:735
<azul::app::App<T>>::run_inner @ app.rs:234
<azul::app::App<T>>::run @ app.rs:192
debug::main @ debug.rs:235
std::rt::lang_start::{{closure}} @ rt.rs:74
std::panicking::try::do_call @ panicking.rs:310
 @ lib.rs:105
std::rt::lang_start_internal @ panicking.rs:289
std::rt::lang_start @ rt.rs:74

Window transparency

Description

Version / OS

  • azul version: 741e3e9

  • Operating system: Windows 10 1809

  • rust toolchain:

    • nightly-x86_64-pc-windows-msvc (default)
    • rustc 1.32.0-nightly (6b9b97bd9 2018-11-15)

Steps to Reproduce

Create a new azul app and replace the code in main.rs with the following:

extern crate azul;
use azul::prelude::*;


fn main() {
    let mut app_data = AppData {};

    let app = App::new(app_data, AppConfig::default());

    let mut create = WindowCreateOptions::<AppData>::default();
    create.state.is_transparent = true;
    create.background = ColorF { r: 1.0, g: 1.0, b: 1.0, a: 0.0 };
    let window = Window::new(create, Css::native()).unwrap();
    app.run(window).unwrap();
}

pub struct AppData {}
impl Layout for AppData {
    fn layout(&self, _: WindowInfo<Self>) -> Dom<Self> {
        Dom::new(NodeType::Div)
    }
}

Expected Behavior

Window background should correctly render the background color given in WindowCreateOptions.

Actual Behavior

Colors are rendered like seen in the following examples:
ColorF { r: 1.0, g: 1.0, b: 1.0, a: 0.0 }

anmerkung 2018-11-19 230724

ColorF { r: 0.5, g: 0.5, b: 0.5, a: 0.0 }

anmerkung 2018-11-19 230325

ColorF { r: 0.0, g: 0.0, b: 0.0, a: 0.0 }

anmerkung 2018-11-19 223020

Additional Information

On windows, examples are build without console support to display printouts

On windows, examples (calculator, table, etc...) link against the windowing subsystem (using the linker flag #![windows_subsystem = "windows"]), this means the console isn't available when running the executable using explorer or cmd.exe

This prevents debug prints from being seen by the user, e.g. the table example (in its current limited form) seems not to respond to mouse clicks because those trigger console printouts.

(For some reason using a terminal emulator like msys/mingw makes the console available regardless.)

Version / OS

Steps to Reproduce

Expected Behavior

The console should print "table was clicked" for every mouse click

Actual Behavior

Nothing is printed

Update The installation wiki

Hi and thanks for providing a great starter wiki :)

I noticed azul 0.1.0 is available on crates.io, so I wanted to submit a patch to update the wiki, but I can't figure out a way to submit it.

If there's a way to submit it please let me know, else here's the patch :)

index 6559042..0bfe92c 100644
--- a/Installation.md
+++ b/Installation.md
@@ -82,15 +82,9 @@ lines beneath the [dependencies] section:
 
 ```toml
 [dependencies]
-azul = { git = "https://github.com/maps4print/azul" }
+azul = "0.1.0"

-**WARNING: ** Azul has not yet been released on crates.io, therefore,
-there is no package available. This guide will be updated once the
-first stable version releases. It is recommended to version-lock your
-dependency with { git = "...", rev = "the_last_commit_hash" }, so
-that you know which commit you are using.

This will pull in the latest stable version of azul. Open the
/my_first_azul_app/src/main.rs file and edit it to look like this:


The preview is a bit  ugly since github parses the diff, I basically changed the git pointer to 0.1.0 and removed the warning ^^' 

Linux Wayland glitches

Description

Running the Calculator and Table example under Wayland looks "out of shape".

Version / OS

  • azul version:
    master from this commit

  • Operating system:
    Arch Linux 4.18.16 Gnome 3.30.1

  • Windowing system (X11 or Wayland, Linux only):
    Wayland

Steps to Reproduce

clone from the listed commit and run cargo run --example calculator

Expected Behavior

accurate layout

Actual Behavior

glitched layout

Additional Information


Material Design components

This is a really nice framework for GUI.
Since the cc imports can be made as crates it would be amazing if some standard GUI components were made.
The obvious one is Material Design.

If the community and maintenance are in favour of this I could start on some.

I think it will be much easier to build than the ones in flutter. I would use those as the initial reference in terms of design and behaviour.

Please shout if you have any opinions about this idea.

MacOS multiple monitors fail

Description

Running calculator cargo run --example calculator from current master, I get a white screen when I move to my secondary monitor.

Version / OS

  • azul version: 0.1.0

  • Operating system: MacOS 10.13.6

  • Windowing system (X11 or Wayland, Linux only): N/A

Steps to Reproduce

  • In MacOS 10.13.6 with rustc 1.30.0 (da5f414c2 2018-10-24) clone this repo at 3950674 .
  • Run cargo run --example calculator
  • Move window to secondary monitor.

Expected Behavior

Calculator is visible

Actual Behavior

Blank screen is seen

Additional Information

I love this project, good luck!

"table" example fails on mac

On Mac, the table example shows the following error. Seems to be some sort of file access issue?

[ERROR][azul::logging] We are sorry, an unexpected panic ocurred, the program has to exit.
Please report this error and attach the log file found in the directory of the executable.

The error ocurred in: libcore/option.rs at line 345 in thread main

Error information:
called `Option::unwrap()` on a `None` value

Backtrace:

backtrace::backtrace::trace @ mod.rs:42
backtrace::capture::Backtrace::new_unresolved @ capture.rs:88
backtrace::capture::Backtrace::new @ capture.rs:63
azul::logging::set_up_panic_hooks::panic_fn @ logging.rs:84
core::ops::function::Fn::call @ function.rs:73
std::panicking::rust_panic_with_hook @ panicking.rs:479
std::panicking::continue_panic_fmt @ panicking.rs:390
 @ panicking.rs:325
core::panicking::panic_fmt @ panicking.rs:77
core::panicking::panic_bounds_check @ panicking.rs:59
<usize as core::slice::SliceIndex<[T]>>::index_mut @ mod.rs:2091
core::slice::<impl core::ops::index::IndexMut<I> for [T]>::index_mut @ mod.rs:1964
<alloc::vec::Vec<T> as core::ops::index::IndexMut<I>>::index_mut @ vec.rs:1729
<azul::id_tree::Arena<T> as core::ops::index::IndexMut<azul::id_tree::node_id::NodeId>>::index_mut @ id_tree.rs:277
<azul::dom::Dom<T>>::push_class @ dom.rs:828
<azul::dom::Dom<T>>::with_class @ dom.rs:798
azul::widgets::table_view::render_table @ table_view.rs:47
<azul::default_callbacks::stack_checked_pointer::StackCheckedPointer<T>>::invoke_mut_iframe @ default_callbacks.rs:86
azul::widgets::table_view::render_table_callback @ table_view.rs:38
azul::display_list::displaylist_handle_rect @ display_list.rs:545
<azul::display_list::DisplayList<'a, T>>::into_display_list_builder @ display_list.rs:319
azul::app::render @ app.rs:770
<azul::app::App<T>>::run_inner @ app.rs:288
<azul::app::App<T>>::run @ app.rs:192
table::main @ table.rs:30
std::rt::lang_start::{{closure}} @ rt.rs:74
std::panicking::try::do_call @ panicking.rs:310
 @ lib.rs:105
std::rt::lang_start_internal @ panicking.rs:289
std::rt::lang_start @ rt.rs:74

1679:1679: syntax error: Expected “"” but found end of script. (-2741)
sh: line 31: azul::app::render: command not found
sh: line 32: azul::app::App: No such file or directory
sh: line 33: azul::app::App: No such file or directory
sh: line 34: table::main: command not found
sh: line 35: std::rt::lang_start::{{closure}}: command not found
sh: line 36: std::panicking::try::do_call: command not found
sh: line 37: @: command not found
sh: line 38: std::rt::lang_start_internal: command not found
sh: line 39: std::rt::lang_start: command not found
sh: -c: line 40: unexpected EOF while looking for matching `"'
sh: -c: line 41: syntax error: unexpected end of file

Labels on div with position: absolute are behind the div

Description

If you have a div with position: absolute, you can't place any labels on it without them appearing behind the div.

Version / OS

  • azul version:
    Commit: 95dc353

  • Operating system:
    Windows

  • Windowing system (X11 or Wayland, Linux only):

Steps to Reproduce

  1. Create a div.
  2. Add position: absolute;
  3. Set a background background-color: black;
  4. Place a label inside.
  5. ???
  6. Profit

Expected Behavior

The label gets rendered.

Actual Behavior

The label gets rendered behind and the depth test rejects it.

Additional Information

Without a background color:
https://i.imgur.com/auhmzKF.png

With a background color:
https://i.imgur.com/WN4P9L8.png

UI doesn't render correctly under a tiling wm

Description

When a program using azul is launch under a tiling window manager in titling mode the ui doesn't render correctly. Switching to floating mode and resizing the window doesn't fix the problem. It seems like the rendering engine thinks the window is a different size than it is.

Version / OS

  • azul version:
    87fc38a

  • Operating system:
    Ubuntu 16.04 running bspwm as the window manager

  • Windowing system (X11 or Wayland, Linux only):
    X11

Steps to Reproduce

Run a azul example under a tiling wm

Expected Behavior

azul_working

Actual Behavior

azul

Information about provenance of callbacks

I know I'm being impatient, but azul has enough features for me to start using it now, except for one little thing. In the current last chapter of the guide there is the following

... callback information that is necessary to determine what item (of a bigger list, for example) was interacted with. Ex. if you have 100 list items, you don't want to write 100 callbacks for each one, but rather have one callback that acts on which ID was selected. The WindowEvent gives you the necessary information to react to these events.

I cannot stress enough how important that is. If you have several sliders, you want to make it easy to link each one of them with the value that it controls in the data model. Right now one way of doing this is by customizing your callback with a macro, but that won't work if you generate the Dom programmatically. The chapter I quoted sketches another way, by trawling through the Dom tree, and it would be rather easy to work out a

impl<T> Dom<T> {
    fn get_node_by_node_data_id (&self, ... ) { ... }
}

using the current state of the code. But it is obviously something that fschutt is leery about, and I agree that only the rendering code should enter the Dom kitchen.

I would like to suggest the following instead: add an associated IndexType to the Layout trait, and an extra parameter of that type to callbacks. The type is to be used by developers any way they want to access the data model.

I wouldn't be surprised if that is already in the plans. Or something else that's even better.

That's the only extra stuff I want for the 0.1 release (and solving the MacOs bug)

no matching package named `azul` found

When I followed the wiki, in the installation section I encountered a problem: cargo gave me an error and complained that "no matching package named azul found", just like the screenshot shows:
_ _20181009023005
I searched the crates.io and found azul indeed doesn't exist there.
Uploading 深度截图_选择区域_20181009022846.png…
So what happened?

Font on Button does not show if DOM contains a TextInput and a Button

Description

Hi! I'm trying to create a basic text-based form, but whenever I add both the button to submit and the textinput to the dom, only the textinput works. The buttons become unstyled and don't respond to clicks. Am I just doing something wrong, or is this a bug?

Version / OS

  • azul version: 0.1.0

  • Operating system: Arch Linux

  • Windowing system (X11 or Wayland, Linux only): X11

Steps to Reproduce

Have both a textinput and a button in the same div

Expected Behavior

The both work the same way as they would independently

Actual Behavior

The buttons become unstyled and fail to respond

Additional Information

2018-11-27-105052_980x619_scrot

How can I help?

Like the title says, I can't wait to use Azul and would like to help move it forward. What would you recommend as a good first task to get my feet wet?

"debug" example crashes

I am not sure if it is expected on the current state of the project development, but I figured it would rather give some feedback:

$ env RUST_BACKTRACE=1 cargo run --example debug
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/examples/debug`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: CreateError(NoAvailablePixelFormat)', /checkout/src/libcore/result.rs:916:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at /checkout/src/libstd/sys_common/backtrace.rs:68
             at /checkout/src/libstd/sys_common/backtrace.rs:57
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:397
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:577
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:538
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:522
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:498
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:71
   9: core::result::unwrap_failed
             at /checkout/src/libcore/macros.rs:23
  10: <core::result::Result<T, E>>::unwrap
             at /checkout/src/libcore/result.rs:782
  11: debug::main
             at examples/debug.rs:45
  12: std::rt::lang_start::{{closure}}
             at /checkout/src/libstd/rt.rs:74
  13: std::panicking::try::do_call
             at /checkout/src/libstd/rt.rs:59
             at /checkout/src/libstd/panicking.rs:480
  14: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:101
  15: std::rt::lang_start_internal
             at /checkout/src/libstd/panicking.rs:459
             at /checkout/src/libstd/panic.rs:365
             at /checkout/src/libstd/rt.rs:58
  16: std::rt::lang_start
             at /checkout/src/libstd/rt.rs:74
  17: main
  18: __libc_start_main
  19: _start
  • Arch Linux, x86_64, kernel 4.15.10
  • Intel HD 4600 video card
  • Gnome 3.26.2
  • Rust 1.24.0

`App::delete_font` doctest fails

Description

Version / OS

  • azul version: d75f216

  • Operating system: Arch Linux

  • Windowing system (X11 or Wayland, Linux only): X11, i3

Steps to Reproduce

  • Run cargo test --features=doc-test
  • Wait for a window to open (this is done by a different doctest)
  • Close the window

Expected Behavior

The app::App<T>::delete_font doctest should pass.

Actual Behavior

[ERROR][azul::logging] An unexpected panic ocurred, the program has to exit.
Please report this error and attach the log file found in the directory of the executable.

The error ocurred in: src/app.rs at line 20 in thread main

Error information:
assertion failed: !app.has_font(&FontId::ExternalFont("Webly Sleeky UI".into()))

Backtrace:

backtrace::backtrace::libunwind::trace @ libunwind.rs:53
backtrace::backtrace::trace @ mod.rs:42
backtrace::capture::Backtrace::new_unresolved @ capture.rs:88
backtrace::capture::Backtrace::new @ capture.rs:63
azul::logging::set_up_panic_hooks::panic_fn @ logging.rs:87
core::ops::function::Fn::call @ function.rs:78
std::panicking::rust_panic_with_hook @ panicking.rs:481
std::panicking::begin_panic @ panicking.rs:411
rust_out::main
std::rt::lang_start::{{closure}}
std::rt::lang_start_internal::{{closure}} @ rt.rs:59
std::panicking::try::do_call @ panicking.rs:310
 @ lib.rs:103
std::panicking::try @ panicking.rs:289
std::panic::catch_unwind @ panic.rs:392
std::rt::lang_start_internal @ rt.rs:58
std::rt::lang_start
unresolved function


  File "<string>", line 1
    import Tkinter,tkMessageBox;root=Tkinter.Tk();root.withdraw();res=tkMessageBox.showinfo(icon='error',title='Unexpected fatal error',message='An unexpected panic ocurred, the program has to exit.
                                                                                                                                                                                                     ^
SyntaxError: EOL while scanning string literal

I have not found the mentioned log file, but I hope this output contains enough info. (I also have no idea what the additional output at the bottom is; it seems unrelated to the test failure)

Additional Information

A Navigation Service

Hi! I want to implement a Navigation Service. In ran straight into some Problems.

I'm gonna tell you how I wanted to do this first. I wanted to create a struct, the Navigation Service, that goes into the AppData. To this struct you can register page structs that implements a trait Navigable.
Then in the layout() function of AppData you can navigate to different pages or rather switch between page structs and call their implementation of layout to different pages. So a navigation just swaps the dom the app is rendering.

pub trait Navigable: Layout {
    // Some functions
}

and the Navigation Service

pub struct NavigationService {
    pages: HashMap<String, Arc<Navigable>>,
    pub navigation_stack: VecDeque<Arc<Navigable>>,
    current_page_idx: u8,
}
impl NavigationService {
    // Some functions to actually do the navigation and return a page that implements Navigable
}

Next i tried to implement Layout for my AppData and call my NavigationService in it. And that's where my problems started.

impl Layout for AppData {
    fn layout(&self, info: WindowInfo<Self>) -> Dom<Self> {
        // here i get the following error for the .layout(info) function call
        // [rustc] the `layout` method cannot be invoked on a trait object
        self.navigation_service.current_page().layout(info)
    }
}

When i replace the Layout trait with one i created myself and i call the function of this replaced trait, then i don't get the error. So.....i'm kinda at my wits end and hope you may have an idea were the real problem is, or maybe the way i'm trying to do this is totally wrong. I appreciate any help or thoughts on this.

Docs tutorial example does not compile.

Description

I'm going through the tutorial and this import throws unresolved reference error.

use azul::widgets::*;

This fixes the problem and allows to continue through the docs.

use azul::widgets::button::Button;
use azul::widgets::label::Label;

Version / OS

Ubuntu 18.10
rustc 1.31.0-nightly (1cf82fd9c 2018-10-30)

Misalignment during hit_test callback caused by hidpi_factor

Description

As I was testing callbacks (On::MouseOver) and CSS dynamic styling so that a zone becomes white when hovered, I noticed that cursor position and WorldPoint positions were misaligned.

How to fix it ?

Since winit seems to handle those factors and adapt the windows by itself, I fail to see the point of not feeding WorldPoint directly with the cursor coordinates. Maybe has something to do with the SVG part which I haven't tested yet.

In app.rs, simply impose a hidpi_factor of 1.0. like so
let physical_position = pos.to_physical(1.0);

Version / OS

  • azul version: last version

  • Operating system: Windows 10 && ArchLinux both have the issue

  • Windowing system (X11 or Wayland, Linux only): Don't know, using LXDE on Archlinux if that helps

Steps to Reproduce

Based on the "hot_reload" example :

hot_reload.css :

#wrapper {
    background: linear-gradient(300deg, red 0%, blue 100%);
    flex-direction: row;
}

#red {
    background-color: #BF0C2B;
    color: white;
    font-size: 12px;
    font-family: sans-serif;
    width: 200px;
}

#sub-wrapper {
    flex-direction: column-reverse;
    width: 400px;
}

#yellow {
    background-color: [[ theme_background_color | #F5900E ]];
    height: 70px;
    flex-direction: row-reverse;
}

#grey {
    background-color: transparent;
}

#below-yellow {
    background-color: #F14C13;
    width: 50px;
}

main.rs :

extern crate azul;

use azul::{
    prelude::*,
    widgets::*,
};

struct MyDataModel;


impl Layout for MyDataModel {
    fn layout(&self, _info: WindowInfo) -> Dom<Self> {

        return Dom::new(NodeType::Div)
            .with_callback(On::MouseOver, Callback(mouse_over_reset))
            .with_id("wrapper")
            .with_child(Dom::new(NodeType::Label(format!("Hello World")))
                .with_id("red")
            )
            .with_child(Dom::new(NodeType::Div)
                .with_id("sub-wrapper")
                .with_child(Dom::new(NodeType::Div)
                    .with_callback(On::MouseOver, Callback(mouse_over_white))
                    .with_id("yellow")
                    .with_child(Dom::new(NodeType::Div)
                        .with_id("below-yellow")
                    )
                )
                .with_child(Dom::new(NodeType::Div)
                    .with_id("grey")
                )
            )
    }
}

fn mouse_over_white(app_state: &mut AppState<MyDataModel>, event: WindowEvent) -> UpdateScreen {
    app_state.windows[event.window].css.set_dynamic_property("theme_background_color", ("background-color", "#fff")).unwrap();
    UpdateScreen::Redraw
}

fn mouse_over_reset(app_state: &mut AppState<MyDataModel>, _event: WindowEvent) -> UpdateScreen {
    UpdateScreen::Redraw
}

fn main() {
    // workaround for: https://github.com/rust-lang/rust/issues/53749
	macro_rules! css_path { () => (concat!(env!("CARGO_MANIFEST_DIR"), "/src/hot_reload.css")) }

    #[cfg(debug_assertions)]
    let css = Css::hot_reload(css_path!()).unwrap();
    #[cfg(not(debug_assertions))]
    let css = Css::new_from_str(include_str!(css_path!())).unwrap();

    let mut app = App::new(MyDataModel{}, AppConfig::default());
    app.create_window(WindowCreateOptions::default(), css).unwrap();
    app.run().unwrap();
}

Expected Behavior

The yellow rectangle at the bottom should become white when the cursor is hovering over it and becomes yellow again when moving the cursor elsewhere on the layout.

Actual Behavior

The yellow rectangle becomes white when the cursor is slightly upward and left of its real position.

Additional Information

See screenshots that include cursor position, hidpi_factor and WorldPoint coordinates used to determine hit_test() results :

before
after

Proposal to refactor style API

Description

Currently, the only way to style azul applications is with CSS syntax that is loaded as an extra file or string.

Describe your solution

#29 and #56 both describe proposals to load and parse custom syntax for DOM layout. There are a lot of different ways to write a hierarchical data structure, so I agree with the idea of keeping the public interface of azul minimal but open for extension -- just supplying the datatypes in the main library is a great way to support that.

Likewise, there are many different ways to specify the style of an application (Sass, SCSS, Less, Stylus, ...). Opening up an API for azul's style datatypes would make these alternative parsers a viable option, while also making for a more consistent programming interface. Keeping style parsing in separate crates could reduce the burden of support, and open the possibility of hotswapping alternate implementations.

While I don't personally have strong feelings about inline styles, this change would also make those fairly simple to expose from an API standpoint. I'd envision something like a with_style(...) method for DOM nodes.

Ultimately, my proposal is to expose style specifiers for azul apps in a similar way to how DOM trees are currently assembled, without needing to write any CSS. For example, something like the following would be valid code:

let rules = vec![
    Rule::new(Selector::new(StylePath::Global).with_child(Selector::new(StylePath::Div).with_class("node")), Style::Background(Color { r: 0, g: 0, b: 0, a: 255 }))
];

let app = App::new(mydatamodel, AppConfig::default());
app.run(Window::new(WindowCreateOptions::default(), AppStyle::new(rules)).unwrap()).unwrap();

Then, a separate crate (perhaps in the same workspace), azul-css, could produce that AppStyle object from CSS (in a file, string, macro, ...) like the following:

* div.node {
    background-color: black;
}

Are there alternatives or drawbacks?

I'd be open to suggestions on syntax/API - consider the above example a rough draft.

In terms of drawbacks -- the base syntax would be more verbose than it is currently, but that would be dealt with by parser crates for anyone concerned.

Is this a breaking change

I think the most "correct" way to implement this would be as a breaking change. I suppose it would be possible to implement this in a backward compatible way, but it probably wouldn't result in a clean API.

Additional notes

Hot-reload could be managed by exposing a HotReloadable trait for 3rd party style suppliers to implement, which would allow azul to periodically request an Option<AppStyle> by callback. For example,

app.run(Window::new(WindowCreateOptions::default(), AppStyle::hot_reload(azul_css::hot_reloader("/path/to/file.css"))).unwrap()).unwrap();

Where can I set up texts and other resources before I load a window?

Hi there, I'm trying to load texts into the window before the layout() function is called, and then pass the TextIds to it internally, where can I initially load these texts, I can't find any kind of setup function where I can use an AppState<T>, unless I use a button, but I can't force users to have to push a button for text to appear. Thanks!

Do css/dom errors fail silently?

Do dom and css fail silently if there's an error or if it can't find a css attribute?
I ask to know for debugging apps, and their appropriate dom and css.

Examples don't show correctly on linux

On ubuntu 18.04 with Gnome and X11, the examples don't show correctly (buttons are invisible, svg images don't show the way they should appear, the table demo shows nothing.)
I get the following message : "GtkDialog mapped without a transient parent. This is discouraged.", but I'm not sure this is the real cause of the problem ...
Thanks anyway for the great job, azul seems very promising.

[Feature Request] Allow error-propagation

Description

I tried to propagate errors instead of letting the program panic! with unwrap() calls:

fn start() -> Result<(), /* What to put here? */> {
    // Instantiate the app with default values.
    let mut app = App::new(DataModel::default(), AppConfig::default());

    // Create a new window.
    app.create_window(WindowCreateOptions::default(), Css::native())?;

    // Run the app.
    app.run()?
}

The example above illustrates the issue:

  • app.create_window returns a Result<(), WindowCreateError>
  • app.run returns a Result<T, RuntimeError<T>>

But they do not share an Into (or From) implementation. In other words: There is a lack of an Error-implementation higher in the hierarchy.

This forces the API-consumer to either unwrap all errors which:

  • Causes visual clutter in the code
  • Panics: Exactly the thing that the Error type should prevent

Proposed solutions

Option 1: Implement std::error::Error for all the top-level error-types in Azul

From looking at the code, that would be:

  • CssParseError
  • FontError
  • ImageError
  • ClipboardError
  • WindowCreateError

I'm not sure, but I think that those are the only errors returned from functions in the library.

Option 2: Create one top-level azul::Error

The azul::Error should then be implemented by all the errors mentioned in option 1.

Which all other azul Errors can convert into. (Also see rfc-356 about stuttering names)

Option 3: Kind-of combination of option 1 and option 2

Creating one top-level azul::Error which implements std::error::Error. This allows API-consumers to use the azul::Error together with other libraries and use the errors interchangeably.

This one is my favourite :)

Is this a breaking change

I'm not sure, option 2 and 3 may be be a breaking change?


I'm willing to help and write the code if you find one of the solutions a good idea.

Great job by the way, I like the library and I think it has a big potential of becoming a widely used GUI library for Rust (which is something Rust really needs).

Proposal to use a document loader

Description

Writing the dom code for a document is long and kind of hard to follow. It is nicely formatted, but it is rather cumbersome to write. And so I created a document loader which does the following:

  • Load the text
  • Tokenize text
  • Parse the tokens
  • Provide texts, fonts and sizes needed to be cached
  • Create the Dom<T> from the abstract syntax tree emitted by the parser

Describe your solution

A document loader. Kind of like an HTML document loader, but with a less involved syntax (We don't need to be able to use javascript or css in the file).
Here an example of the syntax my loader currently uses:

{this is a comment}
div:wrapper[
    label:red ("Hello123");
    div:sub_wrapper[
        div:yellow;
        div:grey;
    ]
    text:pink ("Lorem Ipsum dolor sit amet" "Roboto" 10);
    image:cat ("Cat01");
]

Are there alternatives or drawbacks?

An alternative solution is to create a different form to define documents. My loader may have some drawbacks in the future for supporting widgets/new features of Azul, not to mention I'm no language specialist, but it may be a start.

Is this a breaking change

All of the current code would still work. This could be a separate module or project completely.

Additional notes

The repo containing the code is available here

Azul ignores keyboard layout

Description

When I launch text_input example and switch keyboard to Russian I still get symbols from English layout.

Version / OS

  • azul version: 71286f2

  • Operating system: Windows

Steps to Reproduce

  • Enable Russian keys
  • Launch text_input example
  • Switch layout to Russian
  • Try to enter some symbols.

Expected Behavior

Symbols from Russian layout appears.

Actual Behavior

Symbols from English layout appears.

Additional Information

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.