improves ui, cleans up a little
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
@@ -16,31 +16,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_btn">
|
||||||
<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 +76,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,6 +160,11 @@
|
|||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</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="GtkImage" id="show_list_img">
|
<object class="GtkImage" id="show_list_img">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
49
src/grid.rs
49
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", 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,7 +102,7 @@ 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() {
|
||||||
data.set_text(&to_send);
|
data.set_text(&to_send);
|
||||||
} else {
|
} else {
|
||||||
dbg!("Should not happen !!");
|
dbg!("Should not happen !!");
|
||||||
@@ -130,7 +123,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 +131,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 +151,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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user