#include <AUI/Platform/Entry.h>
#include <AUI/Platform/AWindow.h>
#include <AUI/Util/UIBuildingHelpers.h>
#include "AUI/View/AProgressBar.h"
#include "AUI/View/ASlider.h"
#include "AUI/View/AButton.h"
using namespace declarative;
using namespace std::chrono;
using namespace std::chrono_literals;
static constexpr high_resolution_clock::duration MAX_DURATION = 60s;
class TimerWindow :
public AWindow {
public:
TimerWindow() :
AWindow(
"AUI - 7GUIs - Timer", 300_dp, 50_dp) {
Vertical::Expanding {
Horizontal {
Label { "Elapsed Time:" },
Centered::Expanding {
_new<AProgressBar>()
let {
it & mElapsedTimeRatio;
},
},
},
Label {} & mElapsedTime.readProjected([](high_resolution_clock::duration d) {
return "{:.1f}s"_format(duration_cast<milliseconds>(d).count() / 1000.f);
}),
Horizontal {
Label { "Duration:" },
[](high_resolution_clock::duration d) -> aui::float_within_0_1 {
return float(d.count()) / float(MAX_DURATION.count());
},
[](aui::float_within_0_1 d) -> high_resolution_clock::duration {
return high_resolution_clock::duration(long(float(d) * float(MAX_DURATION.count())));
},
});
},
},
},
});
connect(mTimer->fired, me::update);
mTimer->start();
}
private:
high_resolution_clock::time_point mStartTime = high_resolution_clock::now();
return std::min(mCurrentTime - mStartTime, *mDuration);
};
return float(mElapsedTime->count()) / float(mDuration->count());
};
void update() { mCurrentTime = high_resolution_clock::now(); }
void reset() { mStartTime = high_resolution_clock::now(); }
};
_new<TimerWindow>()->show();
return 0;
}
void setContents(const _< AViewContainer > &container)
Moves (like via std::move) all children and layout of the specified container to this container.
Represents a window in the underlying windowing system.
Definition AWindow.h:45
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
static decltype(auto) connect(const Signal &signal, Object *object, Function &&function)
Connects signal to the slot of the specified object.
Definition AObject.h:86
#define let
Performs multiple operations on a single object without repeating its name (in place) This function c...
Definition kAUI.h:262
#define with_style
Allows to define a style to the view right in place.
Definition kAUI.h:287
#define AUI_ENTRY
Application entry point.
Definition Entry.h:90
Readonly property that holds a value computed by an expression.
Definition APropertyPrecomputed.h:51
Basic easy-to-use property implementation containing T.
Definition AProperty.h:30
Controls the expanding of AView.
Definition Expanding.h:26
Definition callables.h:36