pub struct Row { /* private fields */ }
Expand description
A wrapper around a Flex row
Implementations§
source§impl Row
impl Row
source§impl Row
impl Row
sourcepub fn with_label(self, title: &str) -> Self
pub fn with_label(self, title: &str) -> Self
Initialize with a label
sourcepub fn with_align(self, align: Align) -> Self
pub fn with_align(self, align: Align) -> Self
Initialize with alignment
sourcepub fn with_type<T: WidgetType>(self, typ: T) -> Self
pub fn with_type<T: WidgetType>(self, typ: T) -> Self
Initialize with type
sourcepub fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
pub fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize at bottom of another widget
sourcepub fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
pub fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize above of another widget
sourcepub fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
pub fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize right of another widget
sourcepub fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
pub fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize left of another widget
sourcepub fn center_x<W: WidgetExt>(self, w: &W) -> Self
pub fn center_x<W: WidgetExt>(self, w: &W) -> Self
Initialize center of another widget on the x axis
sourcepub fn center_y<W: WidgetExt>(self, w: &W) -> Self
pub fn center_y<W: WidgetExt>(self, w: &W) -> Self
Initialize center of another widget on the y axis
sourcepub fn center_of_parent(self) -> Self
pub fn center_of_parent(self) -> Self
Initialize center of parent
sourcepub fn size_of_parent(self) -> Self
pub fn size_of_parent(self) -> Self
Initialize to the size of the parent
Methods from Deref<Target = Flex>§
sourcepub fn set_size<W: WidgetExt>(&mut self, w: &W, size: i32)
👎Deprecated since 1.4.8: please use fixed
instead
pub fn set_size<W: WidgetExt>(&mut self, w: &W, size: i32)
fixed
insteadSet the size of the widget, same as fixed
(before it was changed in FLTK 1.4)
sourcepub fn fixed<W: WidgetExt>(&mut self, w: &W, size: i32)
pub fn fixed<W: WidgetExt>(&mut self, w: &W, size: i32)
Set the size of the widget, same as set_size
, but more inline with the new FLTK Fl_Flex api
Examples found in repository?
examples/hello_flex.rs (line 10)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
fn main() {
let app = app::App::default();
let mut wind = Window::default().with_size(400, 300);
let mut col = Flex::default_fill().column();
col.set_margins(120, 80, 120, 80);
let mut frame = Frame::default();
let mut but = Button::default().with_label("Click me!");
col.fixed(&but, 40);
col.end();
wind.end();
wind.show();
but.set_callback(move |_| frame.set_label("Hello world"));
app.run().unwrap();
}
More examples
examples/tabs.rs (line 17)
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
fn draw_gallery() {
let mut tab = Tabs::default_fill();
let mut grp1 = Flex::default_fill().with_label("Tab1\t\t").row();
let mut col = Flex::default().column();
grp1.fixed(&col, 160);
col.set_pad(10);
col.set_margin(10);
let _but1 = Button::default().with_label("Button");
let _but2 = RoundButton::default().with_label("Round");
let _but3 = CheckButton::default().with_label("Check");
let _but4 = LightButton::default().with_label("Light");
let mut but5 = MenuButton::default().with_label("Menu");
but5.add_choice("Hello|World|From|Rust");
let _but6 = ReturnButton::default().with_label("Return");
let mut chce = Choice::default();
chce.add_choice("Hello");
let _inp = Input::default();
let mut out = Output::default();
out.set_value("output");
col.end();
grp1.end();
let grp2 = Flex::default_fill().with_label("Tab2\t\t").row();
grp2.end();
tab.end();
tab.auto_layout();
}
examples/editor.rs (line 250)
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
fn main() {
let a = app::App::default().with_scheme(app::Scheme::Oxy);
app::get_system_colors();
let mut buf = text::TextBuffer::default();
buf.set_tab_distance(4);
let state = State::new(buf.clone());
app::GlobalState::new(state);
let mut w = window::Window::default()
.with_size(WIDTH, HEIGHT)
.with_label("Ted");
w.set_xclass("ted");
{
let mut col = group::Flex::default_fill().column();
col.set_pad(0);
let mut m = menu::SysMenuBar::default();
init_menu(&mut m);
let mut ed = text::TextEditor::default().with_id("ed");
ed.set_buffer(buf);
ed.set_linenumber_width(40);
ed.set_text_font(Font::Courier);
ed.set_trigger(CallbackTrigger::Changed);
ed.set_callback(editor_cb);
handle_drag_drop(&mut ed);
w.resizable(&col);
col.fixed(&m, 30);
col.end();
}
w.end();
w.show();
w.set_callback(win_cb);
a.run().unwrap();
}
examples/temp_converter2.rs (line 52)
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
pub fn new() -> Self {
let a = app::App::default();
MyApp::init_styles();
let (s, r) = app::channel();
let (inp1, inp2) = {
let mut win = window::Window::default().with_size(150, 200);
let mut flex = group::Flex::default()
.with_size(130, 180)
.center_of(&win)
.column();
make_label("Celcius");
let mut inp1 = input::FloatInput::default().with_size(0, 40);
make_label("Fahrenheit");
let mut inp2 = input::FloatInput::default().with_size(0, 40);
flex.fixed(&inp1, 30);
flex.fixed(&inp2, 30);
flex.end();
win.end();
win.make_resizable(true);
win.show();
inp1.set_value(&format!("{}", 0.0));
inp2.set_value(&format!("{}", 32.0));
inp1.set_trigger(CallbackTrigger::Changed);
inp2.set_trigger(CallbackTrigger::Changed);
inp1.emit(s, Message::CelciusChanged);
inp2.emit(s, Message::FahrenheitChanged);
(inp1, inp2)
};
Self { a, inp1, inp2, r }
}
examples/flex.rs (line 28)
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
fn buttons_panel(parent: &mut group::Flex) {
frame::Frame::default();
let w = frame::Frame::default().with_label("Welcome to Flex Login");
let mut urow = group::Flex::default().row();
{
frame::Frame::default()
.with_label("Username:")
.with_align(enums::Align::Inside | enums::Align::Right);
let username = input::Input::default();
urow.fixed(&username, 180);
urow.end();
}
let mut prow = group::Flex::default().row();
{
frame::Frame::default()
.with_label("Password:")
.with_align(enums::Align::Inside | enums::Align::Right);
let password = input::Input::default();
prow.fixed(&password, 180);
prow.end();
}
let pad = frame::Frame::default();
let mut brow = group::Flex::default().row();
{
frame::Frame::default();
let reg = create_button("Register");
let login = create_button("Login");
brow.fixed(®, 80);
brow.fixed(&login, 80);
brow.end();
}
let b = frame::Frame::default();
frame::Frame::default();
parent.fixed(&w, 60);
parent.fixed(&urow, 30);
parent.fixed(&prow, 30);
parent.fixed(&pad, 1);
parent.fixed(&brow, 30);
parent.fixed(&b, 30);
}
fn middle_panel(parent: &mut group::Flex) {
frame::Frame::default();
let mut frame = frame::Frame::default().with_label("Image");
frame.set_frame(enums::FrameType::BorderBox);
frame.set_color(enums::Color::from_rgb(0, 200, 0));
let spacer = frame::Frame::default();
let mut bp = group::Flex::default().column();
buttons_panel(&mut bp);
bp.end();
frame::Frame::default();
parent.fixed(&frame, 200);
parent.fixed(&spacer, 10);
parent.fixed(&bp, 300);
}
fn main_panel(parent: &mut group::Flex) {
frame::Frame::default();
let mut mp = group::Flex::default().row();
middle_panel(&mut mp);
mp.end();
frame::Frame::default();
parent.fixed(&mp, 200);
}
examples/frames.rs (line 33)
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
fn main() {
let app = app::App::default();
let mut win = window::Window::default()
.with_size(1000, 800)
.with_label("Frames")
.center_screen();
let mut col = group::Flex::default_fill().column();
col.set_margin(20);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 0..8 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 8..17 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 17..26 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 26..35 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 35..44 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 44..53 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
col.end();
col.set_pad(30);
win.end();
win.show();
win.set_color(enums::Color::White);
app.run().unwrap();
}
Additional examples can be found in:
sourcepub fn set_margin(&mut self, m: i32)
pub fn set_margin(&mut self, m: i32)
Set the margin
Examples found in repository?
examples/composite_widgets.rs (line 49)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
fn main() {
let app = app::App::default();
app::set_visible_focus(false);
let mut win = window::Window::default().with_size(500, 400);
win.make_resizable(true);
win.set_color(enums::Color::Black);
let mut col = group::Flex::default_fill().column();
col.set_margin(20);
col.set_pad(10);
for i in 0..3 {
let label = format!("Button {}", i + 1);
let mut but = MyButton::new(500, 100);
but.set_label(&label);
but.set_callback(move |_| println!("{label}"));
}
col.end();
win.end();
win.show();
app.run().unwrap();
}
More examples
examples/tabs.rs (line 19)
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
fn draw_gallery() {
let mut tab = Tabs::default_fill();
let mut grp1 = Flex::default_fill().with_label("Tab1\t\t").row();
let mut col = Flex::default().column();
grp1.fixed(&col, 160);
col.set_pad(10);
col.set_margin(10);
let _but1 = Button::default().with_label("Button");
let _but2 = RoundButton::default().with_label("Round");
let _but3 = CheckButton::default().with_label("Check");
let _but4 = LightButton::default().with_label("Light");
let mut but5 = MenuButton::default().with_label("Menu");
but5.add_choice("Hello|World|From|Rust");
let _but6 = ReturnButton::default().with_label("Return");
let mut chce = Choice::default();
chce.add_choice("Hello");
let _inp = Input::default();
let mut out = Output::default();
out.set_value("output");
col.end();
grp1.end();
let grp2 = Flex::default_fill().with_label("Tab2\t\t").row();
grp2.end();
tab.end();
tab.auto_layout();
}
examples/frames.rs (line 30)
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
fn main() {
let app = app::App::default();
let mut win = window::Window::default()
.with_size(1000, 800)
.with_label("Frames")
.center_screen();
let mut col = group::Flex::default_fill().column();
col.set_margin(20);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 0..8 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 8..17 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 17..26 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 26..35 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 35..44 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 44..53 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
col.end();
col.set_pad(30);
win.end();
win.show();
win.set_color(enums::Color::White);
app.run().unwrap();
}
sourcepub fn set_pad(&mut self, p: i32)
pub fn set_pad(&mut self, p: i32)
Set the padding
Examples found in repository?
examples/composite_widgets.rs (line 50)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
fn main() {
let app = app::App::default();
app::set_visible_focus(false);
let mut win = window::Window::default().with_size(500, 400);
win.make_resizable(true);
win.set_color(enums::Color::Black);
let mut col = group::Flex::default_fill().column();
col.set_margin(20);
col.set_pad(10);
for i in 0..3 {
let label = format!("Button {}", i + 1);
let mut but = MyButton::new(500, 100);
but.set_label(&label);
but.set_callback(move |_| println!("{label}"));
}
col.end();
win.end();
win.show();
app.run().unwrap();
}
More examples
examples/counter2.rs (line 14)
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
fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = app::App::default();
let mut wind = Window::default().with_size(160, 200).with_label("Counter");
let mut flex = Flex::default_fill().column();
flex.set_margins(30, 40, 30, 40);
flex.set_pad(10);
let mut but_inc = Button::default().with_label("+");
let mut frame = Frame::default().with_label("0");
let mut but_dec = Button::default().with_label("-");
flex.end();
wind.end();
wind.show();
let (s, r) = app::channel::<Message>();
but_inc.emit(s, Message::Increment);
but_dec.emit(s, Message::Decrement);
while app.wait() {
let label: i32 = frame.label().parse()?;
if let Some(msg) = r.recv() {
match msg {
Message::Increment => frame.set_label(&(label + 1).to_string()),
Message::Decrement => frame.set_label(&(label - 1).to_string()),
}
}
}
Ok(())
}
examples/tabs.rs (line 18)
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
fn draw_gallery() {
let mut tab = Tabs::default_fill();
let mut grp1 = Flex::default_fill().with_label("Tab1\t\t").row();
let mut col = Flex::default().column();
grp1.fixed(&col, 160);
col.set_pad(10);
col.set_margin(10);
let _but1 = Button::default().with_label("Button");
let _but2 = RoundButton::default().with_label("Round");
let _but3 = CheckButton::default().with_label("Check");
let _but4 = LightButton::default().with_label("Light");
let mut but5 = MenuButton::default().with_label("Menu");
but5.add_choice("Hello|World|From|Rust");
let _but6 = ReturnButton::default().with_label("Return");
let mut chce = Choice::default();
chce.add_choice("Hello");
let _inp = Input::default();
let mut out = Output::default();
out.set_value("output");
col.end();
grp1.end();
let grp2 = Flex::default_fill().with_label("Tab2\t\t").row();
grp2.end();
tab.end();
tab.auto_layout();
}
examples/counter4.rs (line 46)
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
fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = app::App::default();
let counter = Counter::new(0);
let mut wind = Window::default().with_size(160, 200).with_label("Counter");
let mut flex = Flex::default_fill().column();
flex.set_margins(30, 40, 30, 40);
flex.set_pad(10);
let mut but_inc = Button::default().with_label("+");
let mut frame = Frame::default().with_label(&counter.value().to_string());
let mut but_dec = Button::default().with_label("-");
flex.end();
wind.end();
wind.show();
but_inc.set_callback({
let mut c = counter.clone();
move |_| c.increment()
});
but_dec.set_callback({
let mut c = counter.clone();
move |_| c.decrement()
});
frame.handle(move |f, ev| {
if ev == MyEvent::CHANGED.into() {
f.set_label(&counter.clone().value().to_string());
true
} else {
false
}
});
Ok(app.run()?)
}
examples/editor.rs (line 239)
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
fn main() {
let a = app::App::default().with_scheme(app::Scheme::Oxy);
app::get_system_colors();
let mut buf = text::TextBuffer::default();
buf.set_tab_distance(4);
let state = State::new(buf.clone());
app::GlobalState::new(state);
let mut w = window::Window::default()
.with_size(WIDTH, HEIGHT)
.with_label("Ted");
w.set_xclass("ted");
{
let mut col = group::Flex::default_fill().column();
col.set_pad(0);
let mut m = menu::SysMenuBar::default();
init_menu(&mut m);
let mut ed = text::TextEditor::default().with_id("ed");
ed.set_buffer(buf);
ed.set_linenumber_width(40);
ed.set_text_font(Font::Courier);
ed.set_trigger(CallbackTrigger::Changed);
ed.set_callback(editor_cb);
handle_drag_drop(&mut ed);
w.resizable(&col);
col.fixed(&m, 30);
col.end();
}
w.end();
w.show();
w.set_callback(win_cb);
a.run().unwrap();
}
examples/frames.rs (line 38)
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
fn main() {
let app = app::App::default();
let mut win = window::Window::default()
.with_size(1000, 800)
.with_label("Frames")
.center_screen();
let mut col = group::Flex::default_fill().column();
col.set_margin(20);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 0..8 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 8..17 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 17..26 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 26..35 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 35..44 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
let mut row = group::Flex::default();
col.fixed(&row, 75);
for i in 44..53 {
let _ = MyFrame::new(i);
}
row.end();
row.set_pad(10);
col.end();
col.set_pad(30);
win.end();
win.show();
win.set_color(enums::Color::White);
app.run().unwrap();
}
Additional examples can be found in:
sourcepub fn set_spacing(&mut self, p: i32)
pub fn set_spacing(&mut self, p: i32)
Set the padding
Examples found in repository?
examples/threads_windows.rs (line 24)
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
fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = app::App::default();
let mut wind = Window::default().with_size(160, 200).with_label("Counter");
let mut col = Flex::default()
.with_size(120, 140)
.center_of(&wind)
.column();
col.set_spacing(10);
let mut but_inc = Button::default().with_label("+");
let mut frame = Frame::default().with_label("0");
let mut but_dec = Button::default().with_label("-");
col.end();
wind.end();
wind.show();
let mut msg_wind = Window::default().with_size(120, 100).with_label("Message");
let mut msgview = HelpView::default().with_size(120, 100);
msgview.set_align(Align::Center);
msg_wind.end();
let (s, r) = app::channel::<Message>();
but_inc.set_callback({
move |_| {
s.send(Message::Deactivate);
thread::spawn(move || {
thread::sleep(Duration::from_secs(1));
s.send(Message::Increment);
s.send(Message::Message("Incremented"));
s.send(Message::Activate);
});
}
});
but_dec.set_callback({
move |_| {
s.send(Message::Deactivate);
thread::spawn(move || {
thread::sleep(Duration::from_secs(1));
s.send(Message::Decrement);
s.send(Message::Message("Decremented"));
s.send(Message::Activate);
});
}
});
while app.wait() {
if let Some(msg) = r.recv() {
let label: i32 = frame.label().parse()?;
match msg {
Message::Increment => frame.set_label(&(label + 1).to_string()),
Message::Decrement => frame.set_label(&(label - 1).to_string()),
Message::Activate => {
but_inc.activate();
but_dec.activate();
}
Message::Deactivate => {
but_inc.deactivate();
but_dec.deactivate();
}
Message::Message(s) => {
msgview.set_value(s);
msg_wind.show();
}
}
}
}
Ok(())
}
sourcepub fn set_margins(&mut self, left: i32, top: i32, right: i32, bottom: i32)
pub fn set_margins(&mut self, left: i32, top: i32, right: i32, bottom: i32)
Set the margins
Examples found in repository?
examples/hello_flex.rs (line 7)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
fn main() {
let app = app::App::default();
let mut wind = Window::default().with_size(400, 300);
let mut col = Flex::default_fill().column();
col.set_margins(120, 80, 120, 80);
let mut frame = Frame::default();
let mut but = Button::default().with_label("Click me!");
col.fixed(&but, 40);
col.end();
wind.end();
wind.show();
but.set_callback(move |_| frame.set_label("Hello world"));
app.run().unwrap();
}
More examples
examples/counter2.rs (line 13)
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
fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = app::App::default();
let mut wind = Window::default().with_size(160, 200).with_label("Counter");
let mut flex = Flex::default_fill().column();
flex.set_margins(30, 40, 30, 40);
flex.set_pad(10);
let mut but_inc = Button::default().with_label("+");
let mut frame = Frame::default().with_label("0");
let mut but_dec = Button::default().with_label("-");
flex.end();
wind.end();
wind.show();
let (s, r) = app::channel::<Message>();
but_inc.emit(s, Message::Increment);
but_dec.emit(s, Message::Decrement);
while app.wait() {
let label: i32 = frame.label().parse()?;
if let Some(msg) = r.recv() {
match msg {
Message::Increment => frame.set_label(&(label + 1).to_string()),
Message::Decrement => frame.set_label(&(label - 1).to_string()),
}
}
}
Ok(())
}
examples/counter4.rs (line 45)
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
fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = app::App::default();
let counter = Counter::new(0);
let mut wind = Window::default().with_size(160, 200).with_label("Counter");
let mut flex = Flex::default_fill().column();
flex.set_margins(30, 40, 30, 40);
flex.set_pad(10);
let mut but_inc = Button::default().with_label("+");
let mut frame = Frame::default().with_label(&counter.value().to_string());
let mut but_dec = Button::default().with_label("-");
flex.end();
wind.end();
wind.show();
but_inc.set_callback({
let mut c = counter.clone();
move |_| c.increment()
});
but_dec.set_callback({
let mut c = counter.clone();
move |_| c.decrement()
});
frame.handle(move |f, ev| {
if ev == MyEvent::CHANGED.into() {
f.set_label(&counter.clone().value().to_string());
true
} else {
false
}
});
Ok(app.run()?)
}
examples/counter.rs (line 21)
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
fn main() {
let app = app::App::default().with_scheme(app::Scheme::Gtk);
app::background(0x62, 0x00, 0xee);
app::set_visible_focus(false);
let count = Rc::new(RefCell::new(0));
let mut wind = Window::default().with_size(160, 200).with_label("Counter");
let mut flex = Flex::default_fill().column();
flex.set_margins(30, 40, 30, 40);
flex.set_pad(10);
let mut but_inc = Button::default().with_label("+");
let mut frame = Frame::default().with_label(&count.borrow().to_string());
let mut but_dec = Button::default().with_label("-");
flex.end();
// wind.make_resizable(true);
wind.end();
wind.show();
but_inc.set_callback({
let count = count.clone();
let mut frame = frame.clone();
move |_| {
*count.borrow_mut() += 1;
frame.set_label(&count.borrow().to_string());
}
});
but_dec.set_callback(move |_| {
*count.borrow_mut() -= 1;
frame.set_label(&count.borrow().to_string());
});
// Theming
wind.set_color(Color::White);
but_inc.set_color(Color::from_u32(0x304FFE));
but_inc.set_selection_color(Color::Green);
but_inc.set_label_size(20);
but_inc.set_frame(FrameType::FlatBox);
but_inc.set_label_color(Color::White);
but_dec.set_color(Color::from_u32(0x2962FF));
but_dec.set_selection_color(Color::Red);
but_dec.set_frame(FrameType::FlatBox);
but_dec.set_label_size(20);
but_dec.set_label_color(Color::White);
// End theming
app.run().unwrap();
}
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Row
impl Send for Row
impl Sync for Row
impl Unpin for Row
impl UnwindSafe for Row
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more