Compare commits
2 Commits
f491fce00b
...
70a3a97d48
Author | SHA1 | Date |
---|---|---|
TheOddGarlic | 70a3a97d48 | |
TheOddGarlic | 69c4cd9386 |
|
@ -10,4 +10,4 @@ raw-window-handle = "0.4.3"
|
|||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
abletk-direct2d = { path = "../abletk-direct2d" }
|
||||
windows = { version = "0.35.0", features = ["Win32_Graphics_Direct2D_Common"] }
|
||||
windows = { version = "0.36.1", features = ["Win32_Graphics_Direct2D_Common"] }
|
||||
|
|
|
@ -9,7 +9,7 @@ edition = "2021"
|
|||
raw-window-handle = "0.4.3"
|
||||
|
||||
[dependencies.windows]
|
||||
version = "0.35.0"
|
||||
version = "0.36.1"
|
||||
features = [
|
||||
"Foundation_Numerics",
|
||||
"Win32_System_Com",
|
||||
|
|
|
@ -23,13 +23,7 @@ pub(crate) const DEFAULT_BRUSH_COLOR: D2D1_COLOR_F = D2D1_COLOR_F {
|
|||
|
||||
pub(crate) const DEFAULT_BRUSH_PROPERTIES: D2D1_BRUSH_PROPERTIES = D2D1_BRUSH_PROPERTIES {
|
||||
opacity: 1.0,
|
||||
// Matrix3x2::identity() is not a const fn but it could be
|
||||
//
|
||||
// I (TheOddGarlic) sent windows-rs a PR and it got merged but now we wait
|
||||
// for it to be included in the next release
|
||||
transform: Matrix3x2 {
|
||||
M11: 1.0, M12: 0.0, M21: 0.0, M22: 1.0, M31: 0.0, M32: 0.0
|
||||
}
|
||||
transform: Matrix3x2::identity(),
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
use abletk::plugin::QuitPlugin;
|
||||
use abletk::prelude::*;
|
||||
use abletk::widget::Column;
|
||||
|
||||
#[launch]
|
||||
fn launch() -> _ {
|
||||
|
@ -15,8 +16,9 @@ fn launch() -> _ {
|
|||
.apply_plugin(QuitPlugin)
|
||||
.add_window(Window::builder(
|
||||
Row::new()
|
||||
.add(Label::new("Hello, AbleTK! ")
|
||||
.add(Label::new("Hello, ")
|
||||
.color(rgb!(0xFF00FFFF)))
|
||||
.add(Label::new("Hello, World!")
|
||||
.color(rgb!(0x64CAFEFF)))))
|
||||
.add(Column::new()
|
||||
.add(Label::new("World!"))
|
||||
.add(Label::new("AbleTK!")))))
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (C) 2022 Umut İnan Erdoğan <umutinanerdogan@pm.me>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
use crate::{layout::position::Position, widget::Widget};
|
||||
use abletk_common::Renderer;
|
||||
|
||||
pub struct Column {
|
||||
widgets: Vec<Box<dyn Widget>>,
|
||||
}
|
||||
|
||||
impl Widget for Column {
|
||||
fn draw(&self, renderer: &mut Renderer) {
|
||||
self.widgets.iter().for_each(|widget| {
|
||||
let pos = widget.position(renderer);
|
||||
renderer.position_at(
|
||||
renderer.position().0 + pos.x(),
|
||||
renderer.position().1 + pos.y()
|
||||
);
|
||||
widget.draw(renderer);
|
||||
renderer.position_at(
|
||||
renderer.position().0,
|
||||
renderer.position().1 + pos.height()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
fn position(&self, renderer: &mut Renderer) -> Position {
|
||||
let (width, height) = self.widgets.iter()
|
||||
.map(|widget| widget.position(renderer))
|
||||
.map(|pos| (pos.width(), pos.height()))
|
||||
.fold((0, 0), |accum, item| (
|
||||
if item.0 > accum.0 { item.0 } else { accum.0 },
|
||||
accum.1 + item.1
|
||||
));
|
||||
|
||||
Position::new(0, 0, width, height)
|
||||
}
|
||||
}
|
||||
|
||||
impl Column {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
widgets: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add<T: Widget + 'static>(mut self, widget: T) -> Self {
|
||||
self.widgets.push(Box::new(widget));
|
||||
self
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@ impl Label {
|
|||
pub fn new<S: Into<String>>(text: S) -> Self {
|
||||
Self {
|
||||
text: text.into(),
|
||||
color: rgb!(0xFFFFFFFF),
|
||||
color: rgb!(0x000000FF),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,12 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
mod column;
|
||||
mod label;
|
||||
mod row;
|
||||
|
||||
use abletk_common::Renderer;
|
||||
pub use column::*;
|
||||
pub use label::*;
|
||||
pub use row::*;
|
||||
|
||||
|
|
Loading…
Reference in New Issue