Giter Club home page Giter Club logo

Comments (3)

rillki avatar rillki commented on June 15, 2024

Here is the full code:

import dlangui;
import std;

mixin APP_ENTRY_POINT;

/// entry point for dlangui based application
extern (C) int UIAppMain(string[] args) {
    // create window
    Window window = Platform.instance.createWindow("DlangUI example - HelloWorld", null);

    // frames
    auto frame1 = new AppFrame();
    auto frame2 = new AppFrame();

    /****** FRAME 1 ********/
    auto frame1_button1 = new Button(null, "Press me"d);
    auto frame1_button2 = new Button(null, "Remove me"d);
    auto frame1_button3 = new Button(null, "new window frame"d);
    frame1.addChildren([
        new HorizontalLayout().addChildren([
            new TextWidget(null, "1 text item"d),
            new TextWidget(null, "2 text item"d),
            new TextWidget(null, "3 text item"d)
        ]),
        new TextWidget(null, "4 text item"d),
        new TextWidget(null, "5 text item"d),
        new TextWidget(null, "6 text item"d),
        frame1_button1,
        frame1_button2,
        frame1_button3,
    ]);
    frame1_button1.click = delegate(Widget src) {
        frame1.addChild(new TextWidget(null, "hello, world! "d ~ frame1.childCount.to!dstring));
        return true;
    };
    frame1_button2.click = delegate(Widget src) {
        frame1.removeChild(frame1.childCount-1);
        return true;
    };
    frame1_button3.click = delegate(Widget src) {
        window.executeInUiThread(() => window.mainWidget = frame2);
        return true;
    };

    /****** FRAME 2 ********/
    auto frame2_button1 = new Button(null, "Take me back"d);
    frame2.addChildren([
        new TextWidget(null, "4 text item"d),
        new TextWidget(null, "5 text item"d),
        frame2_button1,
    ]);
    frame2_button1.click = delegate(Widget src) {
        window.executeInUiThread(() => window.mainWidget = frame1);
        return true;
    };

    // start with frame 1
    window.executeInUiThread(() => window.mainWidget = frame1);

    // show window
    window.show();

    // run message loop
    return Platform.instance.enterMessageLoop();
}

from dlangui.

GrimMaple avatar GrimMaple commented on June 15, 2024

Thanks, I'll take a look when I get time!

from dlangui.

GrimMaple avatar GrimMaple commented on June 15, 2024

Here is the full code:

So the reason why this happens is:

    @property void mainWidget(Widget widget)
    {
        mainWidgetChange(this, _mainWidget, widget);
        if (_mainWidget !is null)
        {
            _mainWidget.window = null;
            destroy(_mainWidget); // This line
        }
        _mainWidget = widget;
        if (_mainWidget !is null)
            _mainWidget.window = this;
    }

When you change the widget, the "source" widget gets destroyed, so when you attempt to set it the second time it errors out.
I cannot simply remove this behavior as it will break other parts of dlangui. For now, the workaround would be creating the frame from scratch.

from dlangui.

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.