LoginSignup
4
5

More than 5 years have passed since last update.

自作GUIライブラリawebviewでD言語くんかわいい

Last updated at Posted at 2015-12-12

D言語くんかわいい

dkawaii.gif

namachanさんのDlangUI de Dlang-manをパクr…、いや、インスパイアされました。

自作のD言語用のGUIライブラリawebviewを使って作りました。悲しいことに、未だにWindowsでしか使えません。そのうちLinuxとMacでも使えるようにします。

コード

awebviewでは、HTMLを使ってUI部分を書きます。

<!doctype html>
<html lang="jp">
<head>
    <title>Hello</title>
</head>
<body>
<img src="views/dman.png">
%[elements["b_kawaii"].html%]
</body>
</html>

あとは、UIの制御部分。

import awebview.gui.application;
import awebview.gui.activity;
import awebview.gui.html;
import awebview.gui.widgets.text;
import awebview.gui.widgets.button;
import awebview.wrapper;

import carbon.functional : passTo;

import std.random;
import std.datetime;

void main()
{
    auto app = SDLApplication.instance;
    auto pref = WebPreferences.recommended;

    with(app.newFactoryOf!SDLActivity(pref)){
        id = "MainActivity";
        width = 600;
        height = 400;
        title = "aaa";

        // ページの作成とか
        app.addActivity(newInstance.passTo!((a){
            a.load(new DManPage("dmanPage"));
        }));
    }

    app.run();
}


// ページ
class DManPage : TemplateHTMLPage!(import(`dman.html`))
{
    this(string id)
    {
        super(id, null);

        // ボタンの作成
        this ~= _kawaii = new InputButton!()("b_kawaii");
        _kawaii.staticProps["value"] = "D言語くん可愛い!!!";
        _kawaii.onClick.connect!"onClickKawaii"(this);  // クリック時のイベント
    }


    void onClickKawaii()
    {
        // <p>タグの作成
        auto dmanText = new Paragraph!()(format("dmanText%d", ++_count));
        this ~= dmanText;   // このページに登録
        this.activity[$("body")].append(dmanText.html); // このページのbodyの末尾に追加

        dmanText.text = "D言語くん可愛い";     // <p>タグの内部にテキスト

        // 以下3行で, ランダムに位置を表示する
        dmanText.staticProps["style.position"] = "absolute";
        dmanText.staticProps["style.top"] = format("%dpx", uniform(0, 300));
        dmanText.staticProps["style.left"] = format("%dpx", uniform(0, 500));
    }


  private:
    InputButton!() _kawaii;
    size_t _count;
}

awebviewの使い方とか

D言語AdventCalendarの24日目の記事の方に書く予定です。卒論ツライ。

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5