Compare commits
3 Commits
96b6c523d7
...
v0.1b
| Author | SHA1 | Date | |
|---|---|---|---|
| 32ffe82815 | |||
| a1412f03d2 | |||
| b2d372f8a7 |
@@ -27,11 +27,11 @@
|
|||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<property name="homogeneous">True</property>
|
<property name="homogeneous">True</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="header">
|
<object class="GtkLabel" id="name">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK | GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_SUBSTRUCTURE_MASK | GDK_SCROLL_MASK | GDK_TOUCH_MASK | GDK_SMOOTH_SCROLL_MASK | GDK_TOUCHPAD_GESTURE_MASK | GDK_TABLET_PAD_MASK</property>
|
<property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK | GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_SUBSTRUCTURE_MASK | GDK_SCROLL_MASK | GDK_TOUCH_MASK | GDK_SMOOTH_SCROLL_MASK | GDK_TOUCHPAD_GESTURE_MASK | GDK_TABLET_PAD_MASK</property>
|
||||||
<property name="label" translatable="yes">Cell</property>
|
<property name="label" translatable="yes">Name</property>
|
||||||
<property name="justify">right</property>
|
<property name="justify">right</property>
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="weight" value="bold"/>
|
<attribute name="weight" value="bold"/>
|
||||||
@@ -53,10 +53,16 @@
|
|||||||
<property name="valign">end</property>
|
<property name="valign">end</property>
|
||||||
<property name="margin_right">5</property>
|
<property name="margin_right">5</property>
|
||||||
<property name="margin_bottom">5</property>
|
<property name="margin_bottom">5</property>
|
||||||
|
<property name="relief">none</property>
|
||||||
<property name="direction">none</property>
|
<property name="direction">none</property>
|
||||||
<property name="popover">desc_sheet</property>
|
<property name="popover">desc_sheet</property>
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<object class="GtkImage">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="icon_name">accessories-dictionary-symbolic</property>
|
||||||
|
<property name="icon_size">3</property>
|
||||||
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
|
|||||||
151
res/main.glade
151
res/main.glade
@@ -7,6 +7,18 @@
|
|||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="icon_name">contact-new-symbolic</property>
|
<property name="icon_name">contact-new-symbolic</property>
|
||||||
</object>
|
</object>
|
||||||
|
<object class="GtkImage" id="image1">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="icon_name">preferences-system-symbolic</property>
|
||||||
|
</object>
|
||||||
|
<object class="GtkTextBuffer" id="pawn_desc"/>
|
||||||
|
<object class="GtkImage" id="show_list_img">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="icon_name">view-list-bullet-symbolic</property>
|
||||||
|
<property name="icon_size">1</property>
|
||||||
|
</object>
|
||||||
<object class="GtkApplicationWindow" id="app">
|
<object class="GtkApplicationWindow" id="app">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK | GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_SUBSTRUCTURE_MASK | GDK_SCROLL_MASK | GDK_TOUCH_MASK | GDK_SMOOTH_SCROLL_MASK | GDK_TOUCHPAD_GESTURE_MASK | GDK_TABLET_PAD_MASK</property>
|
<property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK | GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_SUBSTRUCTURE_MASK | GDK_SCROLL_MASK | GDK_TOUCH_MASK | GDK_SMOOTH_SCROLL_MASK | GDK_TOUCHPAD_GESTURE_MASK | GDK_TABLET_PAD_MASK</property>
|
||||||
@@ -16,31 +28,56 @@
|
|||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="title" translatable="yes">Play Mat</property>
|
<property name="title" translatable="yes">Play Mat</property>
|
||||||
<property name="subtitle" translatable="yes">version 0.1</property>
|
<property name="subtitle" translatable="yes">version 0.1</property>
|
||||||
<property name="spacing">0</property>
|
<property name="spacing">10</property>
|
||||||
<property name="show_close_button">True</property>
|
<property name="show_close_button">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButtonBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="layout_style">expand</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkToggleButton" id="show_panel">
|
<object class="GtkToggleButton" id="show_panel">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
<property name="halign">start</property>
|
|
||||||
<property name="valign">start</property>
|
|
||||||
<property name="action_name">app.panel_switch</property>
|
<property name="action_name">app.panel_switch</property>
|
||||||
<property name="image">show_list_img</property>
|
<property name="image">show_list_img</property>
|
||||||
<property name="always_show_image">True</property>
|
<property name="always_show_image">True</property>
|
||||||
<property name="active">True</property>
|
<property name="active">True</property>
|
||||||
</object>
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="add_btn">
|
<object class="GtkButton" id="add_pawn">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
<property name="halign">start</property>
|
|
||||||
<property name="valign">center</property>
|
|
||||||
<property name="image">add_pawn_img</property>
|
<property name="image">add_pawn_img</property>
|
||||||
<property name="always_show_image">True</property>
|
<property name="always_show_image">True</property>
|
||||||
</object>
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="options_btn">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
<property name="image">image1</property>
|
||||||
|
<property name="always_show_image">True</property>
|
||||||
|
<style>
|
||||||
|
<class name="destructive-action"/>
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
@@ -51,7 +88,7 @@
|
|||||||
<object class="GtkPaned" id="panel">
|
<object class="GtkPaned" id="panel">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="position">80</property>
|
<property name="position">160</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkListBox" id="pawn_list">
|
<object class="GtkListBox" id="pawn_list">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
@@ -135,10 +172,104 @@
|
|||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkImage" id="show_list_img">
|
<object class="GtkWindow" id="new_pawn_dialog">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="modal">True</property>
|
||||||
|
<property name="deletable">False</property>
|
||||||
|
<property name="transient_for">app</property>
|
||||||
|
<child type="titlebar">
|
||||||
|
<object class="GtkHeaderBar">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="icon_name">view-list-bullet-symbolic</property>
|
<property name="title" translatable="yes">Ajouter un personnage</property>
|
||||||
<property name="icon_size">1</property>
|
<child>
|
||||||
|
<object class="GtkButton" id="confirm">
|
||||||
|
<property name="label">gtk-apply</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
<property name="use_stock">True</property>
|
||||||
|
<property name="always_show_image">True</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="abort">
|
||||||
|
<property name="label">gtk-cancel</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
<property name="use_stock">True</property>
|
||||||
|
<property name="always_show_image">True</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkGrid">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">5</property>
|
||||||
|
<property name="margin_right">5</property>
|
||||||
|
<property name="margin_top">5</property>
|
||||||
|
<property name="margin_bottom">5</property>
|
||||||
|
<property name="row_spacing">5</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkEntry" id="name_entry">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="width_chars">40</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="name_label">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="halign">end</property>
|
||||||
|
<property name="label" translatable="yes">Name</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="desc_label">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="valign">start</property>
|
||||||
|
<property name="label" translatable="yes">Description</property>
|
||||||
|
<property name="ellipsize">end</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
<property name="height">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkTextView" id="desc_entry">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="margin_top">5</property>
|
||||||
|
<property name="margin_bottom">5</property>
|
||||||
|
<property name="vexpand">True</property>
|
||||||
|
<property name="wrap_mode">word</property>
|
||||||
|
<property name="buffer">pawn_desc</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
<property name="height">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</interface>
|
</interface>
|
||||||
|
|||||||
@@ -2,15 +2,26 @@
|
|||||||
<!-- Generated with glade 3.22.1 -->
|
<!-- Generated with glade 3.22.1 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.20"/>
|
<requires lib="gtk+" version="3.20"/>
|
||||||
|
<object class="GtkImage" id="image1">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="icon_name">send-to-symbolic</property>
|
||||||
|
</object>
|
||||||
|
<object class="GtkImage" id="image2">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="icon_name">accessories-calculator-symbolic</property>
|
||||||
|
</object>
|
||||||
<object class="GtkBox" id="pawn">
|
<object class="GtkBox" id="pawn">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_top">10</property>
|
||||||
|
<property name="homogeneous">True</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="name">
|
<object class="GtkLabel" id="name">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="margin_left">10</property>
|
<property name="margin_left">10</property>
|
||||||
<property name="hexpand">True</property>
|
|
||||||
<property name="label" translatable="yes">Name</property>
|
<property name="label" translatable="yes">Name</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
@@ -24,16 +35,19 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="halign">end</property>
|
<property name="halign">end</property>
|
||||||
<property name="margin_left">8</property>
|
<property name="valign">center</property>
|
||||||
<property name="spacing">3</property>
|
<property name="margin_right">5</property>
|
||||||
<property name="layout_style">start</property>
|
<property name="homogeneous">True</property>
|
||||||
|
<property name="layout_style">expand</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="place_btn">
|
<object class="GtkButton" id="place_btn">
|
||||||
<property name="label" translatable="yes">Place</property>
|
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
|
<property name="halign">end</property>
|
||||||
|
<property name="image">image1</property>
|
||||||
<property name="relief">half</property>
|
<property name="relief">half</property>
|
||||||
|
<property name="always_show_image">True</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
@@ -43,11 +57,13 @@
|
|||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="stats_btn">
|
<object class="GtkButton" id="stats_btn">
|
||||||
<property name="label" translatable="yes">Stats</property>
|
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
|
<property name="halign">end</property>
|
||||||
|
<property name="image">image2</property>
|
||||||
<property name="relief">half</property>
|
<property name="relief">half</property>
|
||||||
|
<property name="always_show_image">True</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">True</property>
|
<property name="expand">True</property>
|
||||||
|
|||||||
55
src/grid.rs
55
src/grid.rs
@@ -33,7 +33,7 @@ struct Cell {
|
|||||||
impl Cell {
|
impl Cell {
|
||||||
fn new(position: CellPosition) -> Self {
|
fn new(position: CellPosition) -> Self {
|
||||||
Cell {
|
Cell {
|
||||||
inner: CellWidget::new(position, ""),
|
inner: CellWidget::new(position),
|
||||||
position,
|
position,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,6 +47,7 @@ impl AsRef<gtk::EventBox> for Cell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// The cell widget is either empty or has a pawn
|
/// The cell widget is either empty or has a pawn
|
||||||
/// Pawn can be moved around cells using drag-n-drop. However, due to my inability
|
/// Pawn can be moved around cells using drag-n-drop. However, due to my inability
|
||||||
/// to dynamically change the behavior with set/unset methods, all cells are always
|
/// to dynamically change the behavior with set/unset methods, all cells are always
|
||||||
@@ -57,41 +58,33 @@ impl AsRef<gtk::EventBox> for Cell {
|
|||||||
struct CellWidget {
|
struct CellWidget {
|
||||||
eventbox: gtk::EventBox,
|
eventbox: gtk::EventBox,
|
||||||
position: gtk::Label,
|
position: gtk::Label,
|
||||||
header: gtk::Label,
|
name: gtk::Label,
|
||||||
desc_btn: gtk::Button,
|
desc_btn: gtk::Button,
|
||||||
|
targets: Vec<gtk::TargetEntry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CellWidget {
|
impl CellWidget {
|
||||||
fn new(pos: CellPosition, header_text: &str) -> Self {
|
fn new(pos: CellPosition) -> Self {
|
||||||
let cell_src = include_str!("../res/cell.glade");
|
let cell_src = include_str!("../res/cell.glade");
|
||||||
let builder = gtk::Builder::new_from_string(cell_src);
|
let builder = gtk::Builder::new_from_string(cell_src);
|
||||||
// Retrieve children
|
// Retrieve children
|
||||||
let eventbox: gtk::EventBox = builder.get_object("cell").unwrap();
|
|
||||||
let header: gtk::Label = builder.get_object("header").unwrap();
|
|
||||||
header.set_text(header_text);
|
|
||||||
let position: gtk::Label = builder.get_object("position").unwrap();
|
|
||||||
position.set_text(&format!("{}x{}", pos.0, pos.1));
|
|
||||||
let desc_btn: gtk::Button = builder.get_object("desc_btn").unwrap();
|
|
||||||
desc_btn.set_visible(false);
|
|
||||||
let cell = CellWidget {
|
let cell = CellWidget {
|
||||||
eventbox,
|
eventbox: builder.get_object("cell").unwrap(),
|
||||||
position,
|
position: builder.get_object("position").unwrap(),
|
||||||
header,
|
name: builder.get_object("name").unwrap(),
|
||||||
desc_btn,
|
desc_btn: builder.get_object("desc_btn").unwrap(),
|
||||||
|
targets: vec![
|
||||||
|
gtk::TargetEntry::new("text/plain;charset=utf-8", gtk::TargetFlags::SAME_APP, 0),
|
||||||
|
],
|
||||||
};
|
};
|
||||||
Self::set_content(&cell, None);
|
cell.desc_btn.set_visible(false);
|
||||||
|
cell.position.set_text(&format!("{}x{}", pos.0, pos.1));
|
||||||
cell.set_drag();
|
cell.set_drag();
|
||||||
cell.set_drop();
|
cell.set_drop();
|
||||||
|
Self::set_content(&cell, None);
|
||||||
cell
|
cell
|
||||||
}
|
}
|
||||||
|
|
||||||
// The data to be sent
|
|
||||||
fn targets() -> Vec<gtk::TargetEntry> {
|
|
||||||
vec![
|
|
||||||
gtk::TargetEntry::new("text/plain", gtk::TargetFlags::SAME_APP, 0)
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unset_drag(&self) { dbg!("Unset drag"); self.eventbox.drag_source_unset(); }
|
fn unset_drag(&self) { dbg!("Unset drag"); self.eventbox.drag_source_unset(); }
|
||||||
|
|
||||||
fn set_drag(&self) {
|
fn set_drag(&self) {
|
||||||
@@ -99,7 +92,7 @@ impl CellWidget {
|
|||||||
// Acting as source
|
// Acting as source
|
||||||
self.eventbox.drag_source_set(
|
self.eventbox.drag_source_set(
|
||||||
gdk::ModifierType::MODIFIER_MASK,
|
gdk::ModifierType::MODIFIER_MASK,
|
||||||
&Self::targets(),
|
&self.targets,
|
||||||
gdk::DragAction::MOVE,
|
gdk::DragAction::MOVE,
|
||||||
);
|
);
|
||||||
let c = self.clone();
|
let c = self.clone();
|
||||||
@@ -109,9 +102,13 @@ impl CellWidget {
|
|||||||
println!("Send...");
|
println!("Send...");
|
||||||
// TODO: Refactoring, this is the inverse of 'placing',
|
// TODO: Refactoring, this is the inverse of 'placing',
|
||||||
// building a PawnData instead of destructuring it.
|
// building a PawnData instead of destructuring it.
|
||||||
if let Some(to_send) = c.header.get_text() {
|
if let Some(to_send) = c.name
|
||||||
|
.get_text()
|
||||||
|
{
|
||||||
|
dbg!(&to_send);
|
||||||
data.set_text(&to_send);
|
data.set_text(&to_send);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
dbg!("Should not happen !!");
|
dbg!("Should not happen !!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -130,7 +127,7 @@ impl CellWidget {
|
|||||||
// Acting as destination
|
// Acting as destination
|
||||||
self.eventbox.drag_dest_set(
|
self.eventbox.drag_dest_set(
|
||||||
gtk::DestDefaults::ALL,
|
gtk::DestDefaults::ALL,
|
||||||
&Self::targets(),
|
&self.targets,
|
||||||
gdk::DragAction::MOVE,
|
gdk::DragAction::MOVE,
|
||||||
);
|
);
|
||||||
// Retrieve data from the source
|
// Retrieve data from the source
|
||||||
@@ -138,7 +135,7 @@ impl CellWidget {
|
|||||||
self.eventbox
|
self.eventbox
|
||||||
.connect_drag_data_received(move |w, _, _, _, data, _, _| {
|
.connect_drag_data_received(move |w, _, _, _, data, _, _| {
|
||||||
// Check if cell is not already occupied
|
// Check if cell is not already occupied
|
||||||
if !(c.header.get_text().unwrap().as_str() == "") {
|
if !(c.name.get_text().unwrap().as_str() == "") {
|
||||||
// TODO: Find what to do to abort, since
|
// TODO: Find what to do to abort, since
|
||||||
// DragContext methods don't seem to work...
|
// DragContext methods don't seem to work...
|
||||||
println!("Overriding !!");
|
println!("Overriding !!");
|
||||||
@@ -158,10 +155,10 @@ impl CellWidget {
|
|||||||
println!("Set content to {:?}", &data);
|
println!("Set content to {:?}", &data);
|
||||||
// TODO: there is surely something cleaner...
|
// TODO: there is surely something cleaner...
|
||||||
if let Some(name) = data {
|
if let Some(name) = data {
|
||||||
self.header.set_text(name);
|
self.name.set_text(name);
|
||||||
self.desc_btn.set_visible(true);
|
self.desc_btn.set_visible(true);
|
||||||
} else {
|
} else {
|
||||||
self.header.set_text("");
|
self.name.set_text("");
|
||||||
self.desc_btn.set_visible(false);
|
self.desc_btn.set_visible(false);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
99
src/main.rs
99
src/main.rs
@@ -20,8 +20,74 @@ mod pawn;
|
|||||||
pub struct AppData {
|
pub struct AppData {
|
||||||
/// A slot for any pawn waiting for placement
|
/// A slot for any pawn waiting for placement
|
||||||
pending: Option<pawn::PawnData>,
|
pending: Option<pawn::PawnData>,
|
||||||
/// Owned list of pawns
|
pawns: Option<pawn::PawnList>,
|
||||||
pawns: Vec<pawn::Pawn>,
|
}
|
||||||
|
|
||||||
|
#[derive(Debug,Clone)]
|
||||||
|
struct NewPawnDialog {
|
||||||
|
root: gtk::Window,
|
||||||
|
name: gtk::Entry,
|
||||||
|
desc: gtk::TextBuffer,
|
||||||
|
confirm: gtk::Button,
|
||||||
|
abort: gtk::Button,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NewPawnDialog {
|
||||||
|
|
||||||
|
fn init(builder: >k::Builder, app_state: AppState) -> Self {
|
||||||
|
let dialog = NewPawnDialog {
|
||||||
|
root: builder.get_object("new_pawn_dialog").unwrap(),
|
||||||
|
name: builder.get_object("name_entry").unwrap(),
|
||||||
|
desc: builder.get_object("pawn_desc").unwrap(),
|
||||||
|
confirm: builder.get_object("confirm").unwrap(),
|
||||||
|
abort: builder.get_object("abort").unwrap(),
|
||||||
|
};
|
||||||
|
let d = dialog.clone();
|
||||||
|
dialog.abort.connect_clicked(move |_| { d.reset(); d.hide(); });
|
||||||
|
let d = dialog.clone();
|
||||||
|
dialog.confirm.connect_clicked(move |_| {
|
||||||
|
if let Some(data) = d.take_data() {
|
||||||
|
let pawn = pawn::Pawn::from_data(data);
|
||||||
|
println!("Create {:?}", pawn);
|
||||||
|
app_state.add_pawn(&pawn);
|
||||||
|
d.reset();
|
||||||
|
d.hide();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
dialog
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reset(&self) {
|
||||||
|
self.name.set_text("");
|
||||||
|
self.desc.set_text("");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn take_data(&self) -> Option<pawn::PawnData> {
|
||||||
|
let name = String::from(self.name.get_text().unwrap().as_str());
|
||||||
|
let description = {
|
||||||
|
let (ref start, ref end) = self.desc.get_bounds();
|
||||||
|
String::from(
|
||||||
|
self.desc.get_text(start, end, true).unwrap().as_str()
|
||||||
|
)
|
||||||
|
};
|
||||||
|
if name.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(pawn::PawnData {
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
position: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn show(&self) {
|
||||||
|
self.root.show_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hide(&self) {
|
||||||
|
self.root.set_visible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A sharable state for the whole application
|
/// A sharable state for the whole application
|
||||||
@@ -35,6 +101,20 @@ impl std::ops::Deref for AppState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AppState {
|
||||||
|
|
||||||
|
fn add_pawn(&self, pawn: &pawn::Pawn) {
|
||||||
|
pawn.connect_place(self.clone());
|
||||||
|
pawn.connect_stats();
|
||||||
|
self.borrow_mut()
|
||||||
|
.pawns
|
||||||
|
.as_ref()
|
||||||
|
.expect("PawnList was not initialized !")
|
||||||
|
.add(&pawn);
|
||||||
|
dbg!(pawn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct App {
|
struct App {
|
||||||
inner: gtk::Application,
|
inner: gtk::Application,
|
||||||
state: AppState,
|
state: AppState,
|
||||||
@@ -75,13 +155,8 @@ impl App {
|
|||||||
// Pawn list
|
// Pawn list
|
||||||
let pawn_list = builder.get_object("pawn_list").unwrap();
|
let pawn_list = builder.get_object("pawn_list").unwrap();
|
||||||
let pawn_list = pawn::PawnList::init(pawn_list);
|
let pawn_list = pawn::PawnList::init(pawn_list);
|
||||||
|
app_state.borrow_mut().pawns.replace(pawn_list);
|
||||||
|
|
||||||
for pawn in pawn::pawn_factory() {
|
|
||||||
pawn_list.add(&pawn);
|
|
||||||
pawn.connect_place(app_state.clone());
|
|
||||||
pawn.connect_stats();
|
|
||||||
app_state.borrow_mut().pawns.push(pawn);
|
|
||||||
}
|
|
||||||
win.show_all(); // Before grid because we want to hide some widgets there
|
win.show_all(); // Before grid because we want to hide some widgets there
|
||||||
// Initialize grid
|
// Initialize grid
|
||||||
let grid: gtk::Grid = builder.get_object("map").unwrap();
|
let grid: gtk::Grid = builder.get_object("map").unwrap();
|
||||||
@@ -89,9 +164,17 @@ impl App {
|
|||||||
// * From pawn_list to cell : place pawn on dest cell
|
// * From pawn_list to cell : place pawn on dest cell
|
||||||
// * From cell to cell : move pawn from source to dest cell
|
// * From cell to cell : move pawn from source to dest cell
|
||||||
let _grid = grid::Grid::init(grid, 10, app_state.clone());
|
let _grid = grid::Grid::init(grid, 10, app_state.clone());
|
||||||
|
|
||||||
|
let dialog = NewPawnDialog::init(&builder, app_state.clone());
|
||||||
|
let new_pawn_btn: gtk::Button = builder.get_object("add_pawn").unwrap();
|
||||||
|
new_pawn_btn.connect_clicked(move |_| { Self::on_add_pawn(&dialog)});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn on_add_pawn(win: &NewPawnDialog) {
|
||||||
|
win.show();
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a simple action and connects the given handler to its activate signal.
|
/// Creates a simple action and connects the given handler to its activate signal.
|
||||||
fn new_action<F: Fn(&gio::SimpleAction, &Option<glib::Variant>) + 'static>(
|
fn new_action<F: Fn(&gio::SimpleAction, &Option<glib::Variant>) + 'static>(
|
||||||
app: >k::Application,
|
app: >k::Application,
|
||||||
|
|||||||
16
src/pawn.rs
16
src/pawn.rs
@@ -17,6 +17,7 @@ impl PawnList {
|
|||||||
let row = gtk::ListBoxRow::new();
|
let row = gtk::ListBoxRow::new();
|
||||||
row.add(pawn.as_ref());
|
row.add(pawn.as_ref());
|
||||||
self.inner.add(&row);
|
self.inner.add(&row);
|
||||||
|
self.inner.show_all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ impl PawnList {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PawnData {
|
pub struct PawnData {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub description: String,
|
||||||
pub position: Option<String>, // Content of label from CellWidget
|
pub position: Option<String>, // Content of label from CellWidget
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +39,7 @@ pub struct Pawn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Pawn {
|
impl Pawn {
|
||||||
pub fn new<S: Into<String>>(name: S) -> Self {
|
pub fn new<S: Into<String>>(name: S, description: S) -> Self {
|
||||||
let pawn_src = include_str!("../res/pawn.glade");
|
let pawn_src = include_str!("../res/pawn.glade");
|
||||||
let builder = gtk::Builder::new_from_string(pawn_src);
|
let builder = gtk::Builder::new_from_string(pawn_src);
|
||||||
let name = name.into();
|
let name = name.into();
|
||||||
@@ -47,6 +49,7 @@ impl Pawn {
|
|||||||
Pawn {
|
Pawn {
|
||||||
data: PawnData {
|
data: PawnData {
|
||||||
name,
|
name,
|
||||||
|
description: description.into(),
|
||||||
position: None,
|
position: None,
|
||||||
},
|
},
|
||||||
widget,
|
widget,
|
||||||
@@ -55,13 +58,16 @@ impl Pawn {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_data(data: PawnData) -> Self {
|
||||||
|
Self::new(data.name, data.description)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn connect_place(&self, state: AppState) {
|
pub fn connect_place(&self, state: AppState) {
|
||||||
let name = self.data.name.clone();
|
|
||||||
let data = self.data.clone();
|
let data = self.data.clone();
|
||||||
self.place_btn.connect_clicked(move |_| {
|
self.place_btn.connect_clicked(move |_| {
|
||||||
println!("Placing {}...", name);
|
println!("Placing {}...", &data.name);
|
||||||
let mut state = state.0.borrow_mut();
|
let mut state = state.0.borrow_mut();
|
||||||
state.pending = Some(data.clone()); // ???
|
let _ = state.pending.replace(data.clone()); // ???
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +87,7 @@ impl AsRef<gtk::Box> for Pawn {
|
|||||||
pub fn pawn_factory() -> Vec<Pawn> {
|
pub fn pawn_factory() -> Vec<Pawn> {
|
||||||
let mut pawns = Vec::with_capacity(3);
|
let mut pawns = Vec::with_capacity(3);
|
||||||
for name in &["Lomion", "Oilosse", "Fefi"] {
|
for name in &["Lomion", "Oilosse", "Fefi"] {
|
||||||
pawns.push(Pawn::new(*name));
|
pawns.push(Pawn::new(*name, ""));
|
||||||
}
|
}
|
||||||
pawns
|
pawns
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user