-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Generated with glade 3.38.2 --> | ||
<interface> | ||
<requires lib="gtk+" version="3.24"/> | ||
<object class="GtkApplicationWindow" id="win_test"> | ||
<property name="can-focus">False</property> | ||
<child> | ||
<object class="GtkBox"> | ||
<property name="visible">True</property> | ||
<property name="can-focus">False</property> | ||
<property name="orientation">vertical</property> | ||
<child> | ||
<object class="GtkEntry" id="text1"> | ||
<property name="visible">True</property> | ||
<property name="can-focus">True</property> | ||
</object> | ||
<packing> | ||
<property name="expand">False</property> | ||
<property name="fill">True</property> | ||
<property name="position">0</property> | ||
</packing> | ||
</child> | ||
<child> | ||
<object class="GtkEntry" id="text2"> | ||
<property name="visible">True</property> | ||
<property name="can-focus">True</property> | ||
</object> | ||
<packing> | ||
<property name="expand">False</property> | ||
<property name="fill">True</property> | ||
<property name="position">1</property> | ||
</packing> | ||
</child> | ||
<child> | ||
<object class="GtkEntry" id="text3"> | ||
<property name="visible">True</property> | ||
<property name="can-focus">True</property> | ||
</object> | ||
<packing> | ||
<property name="expand">False</property> | ||
<property name="fill">True</property> | ||
<property name="position">2</property> | ||
</packing> | ||
</child> | ||
<child> | ||
<object class="GtkEntry" id="text4"> | ||
<property name="visible">True</property> | ||
<property name="can-focus">True</property> | ||
</object> | ||
<packing> | ||
<property name="expand">False</property> | ||
<property name="fill">True</property> | ||
<property name="position">3</property> | ||
</packing> | ||
</child> | ||
</object> | ||
</child> | ||
</object> | ||
</interface> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use gtk::prelude::*; | ||
|
||
#[macro_use] | ||
mod util; | ||
|
||
#[derive(woab::WidgetsFromBuilder)] | ||
pub struct FlatWidgets { | ||
text1: gtk::Entry, | ||
text2: gtk::Entry, | ||
text3: gtk::Entry, | ||
text4: gtk::Entry, | ||
} | ||
|
||
#[derive(woab::WidgetsFromBuilder)] | ||
pub struct GroupedWidgets { | ||
#[widget(nested)] | ||
group_a: GroupA, | ||
#[widget(nested)] | ||
group_b: GroupB, | ||
} | ||
|
||
#[derive(woab::WidgetsFromBuilder)] | ||
pub struct GroupA { | ||
text1: gtk::Entry, | ||
text2: gtk::Entry, | ||
} | ||
|
||
#[derive(woab::WidgetsFromBuilder)] | ||
pub struct GroupB { | ||
text3: gtk::Entry, | ||
text4: gtk::Entry, | ||
} | ||
|
||
#[test] | ||
fn test_recusive_widgets_from_builder() -> anyhow::Result<()> { | ||
let factory = woab::BuilderFactory::from(include_str!("four_texts.glade").to_owned()); | ||
gtk::init()?; | ||
woab::run_actix_inside_gtk_event_loop()?; | ||
let bld = factory.instantiate(); | ||
|
||
let flat_widgets: FlatWidgets = bld.widgets()?; | ||
let grouped_widgets: GroupedWidgets = bld.widgets()?; | ||
|
||
assert!(grouped_widgets.group_a.text1.get_text().is_empty()); | ||
assert!(grouped_widgets.group_a.text2.get_text().is_empty()); | ||
assert!(grouped_widgets.group_b.text3.get_text().is_empty()); | ||
assert!(grouped_widgets.group_b.text4.get_text().is_empty()); | ||
|
||
flat_widgets.text1.set_text("Text 1"); | ||
flat_widgets.text2.set_text("Text 2"); | ||
flat_widgets.text3.set_text("Text 3"); | ||
flat_widgets.text4.set_text("Text 4"); | ||
|
||
wait_for!(flat_widgets.text1.get_text() == "Text 1")?; | ||
wait_for!(flat_widgets.text2.get_text() == "Text 2")?; | ||
wait_for!(flat_widgets.text3.get_text() == "Text 3")?; | ||
wait_for!(flat_widgets.text4.get_text() == "Text 4")?; | ||
|
||
assert!(grouped_widgets.group_a.text1.get_text() == "Text 1"); | ||
assert!(grouped_widgets.group_a.text2.get_text() == "Text 2"); | ||
assert!(grouped_widgets.group_b.text3.get_text() == "Text 3"); | ||
assert!(grouped_widgets.group_b.text4.get_text() == "Text 4"); | ||
|
||
Ok(()) | ||
} |