Commit 91b86d07 authored by twanvl's avatar twanvl

Moved tab_index to Style (instead of Field), it makes more sense there, since...

Moved tab_index to Style (instead of Field), it makes more sense there, since it pertains to the layout of stuff on the card.
Added fancy mouseover effect to field borders. This might be slow, so I should add a setting to disable it.
parent 28e42ea3
...@@ -41,7 +41,6 @@ Fields are part of the [[file:style triangle]]: ...@@ -41,7 +41,6 @@ Fields are part of the [[file:style triangle]]:
| @card list name@ [[type:string]] field name Alternate name to use for the card list, for example an abbreviation. | @card list name@ [[type:string]] field name Alternate name to use for the card list, for example an abbreviation.
| @card list alignment@ [[type:alignment]] @left@ Alignment of the card list column. | @card list alignment@ [[type:alignment]] @left@ Alignment of the card list column.
| @sort script@ [[type:script]] Alternate way to sort the card list when using this column to sort the list. | @sort script@ [[type:script]] Alternate way to sort the card list when using this column to sort the list.
| @tab index@ [[type:int]] @0@ Index for moving through the fields with the tab key. The default is from left to right and then top to bottom.
The @type@ determines what values of this field contain: The @type@ determines what values of this field contain:
! Type Values contain Displayed as ! Type Values contain Displayed as
......
...@@ -68,6 +68,7 @@ Here are some examples: ...@@ -68,6 +68,7 @@ Here are some examples:
--Properties-- --Properties--
! Property Type Default Description ! Property Type Default Description
| @z index@ [[type:int]] @0@ Stacking of this box, fields with a higher @z index@ are placed on top of those with a lower index. | @z index@ [[type:int]] @0@ Stacking of this box, fields with a higher @z index@ are placed on top of those with a lower index.
| @tab index@ [[type:int]] @0@ Index for moving through the fields with the tab key, fields with a lower tab index come first. Otherwise the order is from top to bottom and then left to right.
| @left@ [[type:scriptable]] [[type:double]] ''Required'' Distance between left edge of the box and the left of the card in pixels. | @left@ [[type:scriptable]] [[type:double]] ''Required'' Distance between left edge of the box and the left of the card in pixels.
| @width@ [[type:scriptable]] [[type:double]] ''Required'' Width of the box in pixels. | @width@ [[type:scriptable]] [[type:double]] ''Required'' Width of the box in pixels.
| @right@ [[type:scriptable]] [[type:double]] ''Required'' Distance between right edge of the box and the ''left'' of the card in pixels. | @right@ [[type:scriptable]] [[type:double]] ''Required'' Distance between right edge of the box and the ''left'' of the card in pixels.
......
...@@ -22,7 +22,8 @@ enum DrawWhat ...@@ -22,7 +22,8 @@ enum DrawWhat
, DRAW_EDITING = 0x40 // draw other editor stuff, can be disabled. , DRAW_EDITING = 0x40 // draw other editor stuff, can be disabled.
, DRAW_ERRORS = 0x80 // draw error indicators, can't be disabled , DRAW_ERRORS = 0x80 // draw error indicators, can't be disabled
, DRAW_ACTIVE = 0x100 // draw active editor stuff, such as hidden separators and atom highlights , DRAW_ACTIVE = 0x100 // draw active editor stuff, such as hidden separators and atom highlights
, DRAW_NATIVELOOK = 0x200 // use a native look , DRAW_HOVER = 0x200 // draw mouse over stuff, such as a highlighted border
, DRAW_NATIVELOOK = 0x400 // use a native look
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -35,7 +35,6 @@ Field::Field() ...@@ -35,7 +35,6 @@ Field::Field()
, card_list_visible(false) , card_list_visible(false)
, card_list_allow (true) , card_list_allow (true)
, card_list_align (ALIGN_LEFT) , card_list_align (ALIGN_LEFT)
, tab_index (0)
{} {}
Field::~Field() {} Field::~Field() {}
...@@ -66,7 +65,6 @@ IMPLEMENT_REFLECTION(Field) { ...@@ -66,7 +65,6 @@ IMPLEMENT_REFLECTION(Field) {
REFLECT(card_list_name); REFLECT(card_list_name);
REFLECT(sort_script); REFLECT(sort_script);
REFLECT_N("card_list_alignment", card_list_align); REFLECT_N("card_list_alignment", card_list_align);
REFLECT(tab_index);
REFLECT_IF_READING if(caption.empty()) caption = name_to_caption(name); REFLECT_IF_READING if(caption.empty()) caption = name_to_caption(name);
REFLECT_IF_READING if(card_list_name.empty()) card_list_name = capitalize(caption); REFLECT_IF_READING if(card_list_name.empty()) card_list_name = capitalize(caption);
} }
...@@ -99,6 +97,7 @@ intrusive_ptr<Field> read_new<Field>(Reader& reader) { ...@@ -99,6 +97,7 @@ intrusive_ptr<Field> read_new<Field>(Reader& reader) {
Style::Style(const FieldP& field) Style::Style(const FieldP& field)
: fieldP(field) : fieldP(field)
, z_index(0) , z_index(0)
, tab_index(0)
, left (1000000), top (1000000) , left (1000000), top (1000000)
, width(0), height(0) , width(0), height(0)
, right(1000000), bottom(1000000) , right(1000000), bottom(1000000)
...@@ -112,6 +111,7 @@ Style::~Style() {} ...@@ -112,6 +111,7 @@ Style::~Style() {}
IMPLEMENT_REFLECTION(Style) { IMPLEMENT_REFLECTION(Style) {
REFLECT(z_index); REFLECT(z_index);
REFLECT(tab_index);
REFLECT(left); REFLECT(left);
REFLECT(width); REFLECT(width);
REFLECT(right); REFLECT(right);
......
...@@ -59,7 +59,6 @@ class Field : public IntrusivePtrVirtualBase { ...@@ -59,7 +59,6 @@ class Field : public IntrusivePtrVirtualBase {
String card_list_name; ///< Alternate name to use in card list. String card_list_name; ///< Alternate name to use in card list.
Alignment card_list_align; ///< Alignment of the card list colummn. Alignment card_list_align; ///< Alignment of the card list colummn.
OptionalScript sort_script; ///< The script to use when sorting this, if not the value. OptionalScript sort_script; ///< The script to use when sorting this, if not the value.
int tab_index; ///< Tab index in editor
Dependencies dependent_scripts; ///< Scripts that depend on values of this field Dependencies dependent_scripts; ///< Scripts that depend on values of this field
/// Creates a new Value corresponding to this Field /// Creates a new Value corresponding to this Field
...@@ -99,6 +98,7 @@ class Style : public IntrusivePtrVirtualBase { ...@@ -99,6 +98,7 @@ class Style : public IntrusivePtrVirtualBase {
const FieldP fieldP; ///< Field this style is for, should have the right type! const FieldP fieldP; ///< Field this style is for, should have the right type!
int z_index; ///< Stacking of values of this field, higher = on top int z_index; ///< Stacking of values of this field, higher = on top
int tab_index; ///< Tab order in editor
Scriptable<double> left, top; ///< Position of this field Scriptable<double> left, top; ///< Position of this field
Scriptable<double> width, height; ///< Position of this field Scriptable<double> width, height; ///< Position of this field
Scriptable<double> right, bottom; ///< Position of this field Scriptable<double> right, bottom; ///< Position of this field
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
//| License: GNU General Public License 2 or later (see file COPYING) | //| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+ //+----------------------------------------------------------------------------+
#ifndef HEADER_DATA_FIELD_PACKAGE_CHOICE #ifndef HEADER_DATA_FIELD_PACKAGE_CHOICE
#define HEADER_DATA_FIELD_PACKAGE_CHOICE #define HEADER_DATA_FIELD_PACKAGE_CHOICE
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
......
...@@ -41,7 +41,8 @@ ValueViewerP DataEditor::makeViewer(const StyleP& style) { ...@@ -41,7 +41,8 @@ ValueViewerP DataEditor::makeViewer(const StyleP& style) {
DrawWhat DataEditor::drawWhat(const ValueViewer* viewer) const { DrawWhat DataEditor::drawWhat(const ValueViewer* viewer) const {
int what = DRAW_NORMAL int what = DRAW_NORMAL
| DRAW_ACTIVE * viewerIsCurrent(viewer); | DRAW_ACTIVE * viewerIsCurrent(viewer)
| DRAW_HOVER * (viewer == hovered_viewer);
if (nativeLook()) { if (nativeLook()) {
what |= DRAW_BOXES | DRAW_EDITING | DRAW_NATIVELOOK | DRAW_ERRORS; what |= DRAW_BOXES | DRAW_EDITING | DRAW_NATIVELOOK | DRAW_ERRORS;
} else { } else {
...@@ -121,13 +122,17 @@ int DataEditor::currentTabPos() const { ...@@ -121,13 +122,17 @@ int DataEditor::currentTabPos() const {
return -1; return -1;
} }
struct CompareTabIndex { struct CompareTabOrder {
bool operator() (ValueViewer* a, ValueViewer* b) { bool operator() (ValueViewer* a, ValueViewer* b) {
Style& as = *a->getStyle(), &bs = *b->getStyle(); Style& as = *a->getStyle(), &bs = *b->getStyle();
Field& af = *as.fieldP, &bf = *bs.fieldP; // if tab_index differs, use that
if (af.tab_index < bf.tab_index) return true; if (as.tab_index < as.tab_index) return true;
if (af.tab_index > bf.tab_index) return false; if (as.tab_index > as.tab_index) return false;
if (fabs(as.top - bs.top) < 15) { // otherwise look at the positions
double vertical_overlap = min(bs.bottom - as.top, as.bottom - bs.top);
double horizontal_overlap = min(bs.right - as.left, as.right - bs.left);
if (vertical_overlap > 0 && vertical_overlap > horizontal_overlap) {
// fields overlap (mostly) vertically
// the fields are almost on the same 'row' // the fields are almost on the same 'row'
// compare horizontally first // compare horizontally first
if (as.left < bs.left) return true; // horizontal sorting if (as.left < bs.left) return true; // horizontal sorting
...@@ -150,7 +155,7 @@ void DataEditor::createTabIndex() { ...@@ -150,7 +155,7 @@ void DataEditor::createTabIndex() {
by_tab_index.push_back(v.get()); by_tab_index.push_back(v.get());
} }
} }
stable_sort(by_tab_index.begin(), by_tab_index.end(), CompareTabIndex()); stable_sort(by_tab_index.begin(), by_tab_index.end(), CompareTabOrder());
} }
void DataEditor::onInit() { void DataEditor::onInit() {
createTabIndex(); createTabIndex();
...@@ -268,6 +273,8 @@ void DataEditor::onMotion(wxMouseEvent& ev) { ...@@ -268,6 +273,8 @@ void DataEditor::onMotion(wxMouseEvent& ev) {
ValueEditor* e = hovered_viewer->getEditor(); ValueEditor* e = hovered_viewer->getEditor();
RealPoint pos = mousePoint(ev, *hovered_viewer); RealPoint pos = mousePoint(ev, *hovered_viewer);
if (e) e->onMouseLeave(pos, ev); if (e) e->onMouseLeave(pos, ev);
if (hovered_viewer) redraw(*hovered_viewer);
if (new_hovered_viewer) redraw(*new_hovered_viewer);
} }
hovered_viewer = new_hovered_viewer; hovered_viewer = new_hovered_viewer;
// change cursor and set status text // change cursor and set status text
...@@ -293,6 +300,7 @@ void DataEditor::onMouseLeave(wxMouseEvent& ev) { ...@@ -293,6 +300,7 @@ void DataEditor::onMouseLeave(wxMouseEvent& ev) {
if (hovered_viewer) { if (hovered_viewer) {
ValueEditor* e = hovered_viewer->getEditor(); ValueEditor* e = hovered_viewer->getEditor();
if (e) e->onMouseLeave(mousePoint(ev,*hovered_viewer), ev); if (e) e->onMouseLeave(mousePoint(ev,*hovered_viewer), ev);
if (hovered_viewer) redraw(*hovered_viewer);
hovered_viewer = nullptr; hovered_viewer = nullptr;
} }
// clear status text // clear status text
......
...@@ -59,6 +59,8 @@ bool ValueViewer::setFieldBorderPen(RotatedDC& dc) { ...@@ -59,6 +59,8 @@ bool ValueViewer::setFieldBorderPen(RotatedDC& dc) {
if (!(what & DRAW_BORDERS)) return false; if (!(what & DRAW_BORDERS)) return false;
if (what & DRAW_ACTIVE) { if (what & DRAW_ACTIVE) {
dc.SetPen(wxPen(Color(0,128,255), 1, wxSOLID)); dc.SetPen(wxPen(Color(0,128,255), 1, wxSOLID));
} else if (what & DRAW_HOVER) {
dc.SetPen(dotted_pen(Color(0,128,255)));
} else { } else {
dc.SetPen(dotted_pen(Color(128,128,128))); dc.SetPen(dotted_pen(Color(128,128,128)));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment