1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#![crate_name="orbtk"]
#![crate_type="lib"]
#![deny(warnings)]

pub use button::Button;
pub use cell::CloneCell;
pub use color::Color;
pub use event::Event;
pub use label::Label;
pub use menu::{Menu, Action};
pub use place::Placeable;
pub use point::Point;
pub use progress_bar::ProgressBar;
pub use rect::Rect;
pub use renderer::Renderer;
pub use text_box::TextBox;
pub use widget::{Widget, WidgetCore};
pub use window::Window;

pub mod button;
pub mod cell;
pub mod color;
pub mod event;
pub mod label;
pub mod menu;
pub mod place;
pub mod point;
pub mod progress_bar;
pub mod rect;
pub mod renderer;
pub mod text_box;
pub mod widget;
pub mod window;

use callback::{Click, Enter};
pub mod callback;

pub fn example() {
    let window = Window::new(Rect::new(100, 100, 420, 420), "OrbTK");

    let x = 10;
    let mut y = 0;

    let mut menu = Menu::new("Menu")
        .position(x, y)
        .size(32, 16);

    y += menu.core.rect.get().height as i32 + 10;

    let label = Label::new()
        .position(x, y)
        .size(400, 16)
        .text("Test Label")
        .place(&window);

    y += label.core.rect.get().height as i32 + 10;

    let text_box = TextBox::new()
        .position(x, y)
        .size(342, 16)
        .on_enter(move |text_box: &TextBox| {
            label.text.set(text_box.text.get());
        })
        .place(&window);

    let button = Button::new()
        .position(x + text_box.core.rect.get().width as i32 + 10, y)
        .size(48, text_box.core.rect.get().height)
        .text("Update")
        .on_click(move |_button: &Button, _point: Point| {
            text_box.emit_enter();
        })
        .place(&window);

    y += button.core.rect.get().height as i32 + 10;

    let progress_label = Label::new()
        .text("Progress: 0%")
        .position(x, y)
        .size(400, 16)
        .place(&window);

    y += progress_label.core.rect.get().height as i32 + 10;

    let progress_bar = ProgressBar::new()
        .position(x, y)
        .size(400, 16)
        .on_click(move |progress_bar: &ProgressBar, point: Point| {
            let progress = point.x * 100 / progress_bar.core.rect.get().width as i32;
            progress_label.text.set(format!("Progress: {}%", progress));
            progress_bar.value.set(progress);
        })
        .place(&window);

    y += progress_bar.core.rect.get().height as i32 + 10;

    let multi_line_label = Label::new()
        .text("Multi-Line Text")
        .position(x, y)
        .size(400, 16)
        .place(&window);

    y += multi_line_label.core.rect.get().height as i32 + 10;

    let multi_line_text_box = TextBox::new()
        .position(x, y)
        .size(400, 128)
        .place(&window);

    y += multi_line_text_box.core.rect.get().height as i32 + 10;

    let offset_label = Label::new()
        .position(x, y)
        .size(400, 256)
        .text("Test Offset")
        .text_offset(50, 50)
        .place(&window);

    {
        let offset_label_clone = offset_label.clone();
        menu.add_action(Action::new("Label One")
            .on_click(move |_action: &Action, _point: Point| {
                offset_label_clone.text.set("One".to_owned());
            }));
    }

    {
        let offset_label_clone = offset_label.clone();
        menu.add_action(Action::new("Label Two")
            .on_click(move |_action: &Action, _point: Point| {
                offset_label_clone.text.set("Two".to_owned());
            }));
    }

    menu.add_separator();

    {
        let offset_label_clone = offset_label.clone();
        menu.add_action(Action::new("Reset Label")
            .on_click(move |_action: &Action, _point: Point| {
                offset_label_clone.text.set("Text Offset".to_owned());
            }));
    }

    // TODO: Don't require this to be placed last to be drawn last
    menu.place(&window);

    window.exec();
}