FLUID: Arrow keys move widgets inside Fl_Flex
This commit is contained in:
parent
904d25dafe
commit
fb6c38b1a4
@ -921,8 +921,8 @@ static void draw_right_brace(const Fl_Widget *w);
|
||||
static void draw_top_brace(const Fl_Widget *w);
|
||||
static void draw_bottom_brace(const Fl_Widget *w);
|
||||
static void draw_grid(int x, int y, int dx, int dy);
|
||||
static void draw_width(int x, int y, int r, Fl_Align a);
|
||||
static void draw_height(int x, int y, int b, Fl_Align a);
|
||||
void draw_width(int x, int y, int r, Fl_Align a);
|
||||
void draw_height(int x, int y, int b, Fl_Align a);
|
||||
|
||||
static int nearest(int x, int left, int grid, int right=0x7fff) {
|
||||
int grid_x = ((x-left+grid/2)/grid)*grid+left;
|
||||
@ -1734,7 +1734,7 @@ static void draw_bottom_brace(const Fl_Widget *w) {
|
||||
fl_xyline(x-2, y, x+w->w()+1);
|
||||
}
|
||||
|
||||
static void draw_height(int x, int y, int b, Fl_Align a) {
|
||||
void draw_height(int x, int y, int b, Fl_Align a) {
|
||||
char buf[16];
|
||||
int h = b - y;
|
||||
sprintf(buf, "%d", h);
|
||||
@ -1768,7 +1768,7 @@ static void draw_height(int x, int y, int b, Fl_Align a) {
|
||||
fl_xyline(x - 4, b, x + 4);
|
||||
}
|
||||
|
||||
static void draw_width(int x, int y, int r, Fl_Align a) {
|
||||
void draw_width(int x, int y, int r, Fl_Align a) {
|
||||
char buf[16];
|
||||
int w = r-x;
|
||||
sprintf(buf, "%d", w);
|
||||
|
@ -515,6 +515,25 @@ void Fl_Flex_Type::insert_child_at(Fl_Widget *child, int x, int y) {
|
||||
}
|
||||
}
|
||||
|
||||
void Fl_Flex_Type::keyboard_move_child(Fl_Widget_Type *child, int key) {
|
||||
Fl_Flex *flex = ((Fl_Flex*)o);
|
||||
int ix = flex->find(child->o);
|
||||
if (ix == flex->children()) return;
|
||||
if (flex->horizontal()) {
|
||||
if (key==FL_Right) {
|
||||
flex->insert(*child->o, ix+2);
|
||||
} else if (key==FL_Left) {
|
||||
if (ix > 0) flex->insert(*child->o, ix-1);
|
||||
}
|
||||
} else {
|
||||
if (key==FL_Down) {
|
||||
flex->insert(*child->o, ix+2);
|
||||
} else if (key==FL_Up) {
|
||||
if (ix > 0) flex->insert(*child->o, ix-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Fl_Flex_Type::size(Fl_Type *t, char fixed_only) {
|
||||
if (!t->is_widget()) return 0;
|
||||
if (!t->parent) return 0;
|
||||
|
@ -126,6 +126,7 @@ public:
|
||||
void layout_widget() FL_OVERRIDE;
|
||||
void change_subtype_to(int n);
|
||||
void insert_child_at(Fl_Widget *child, int x, int y);
|
||||
void keyboard_move_child(Fl_Widget_Type*, int key);
|
||||
static int parent_is_flex(Fl_Type*);
|
||||
static int size(Fl_Type*, char fixed_only=0);
|
||||
static int is_fixed(Fl_Type*);
|
||||
|
@ -40,12 +40,16 @@
|
||||
#include <FL/Fl_Menu_Item.H>
|
||||
#include <FL/Fl_Round_Button.H>
|
||||
#include <FL/Fl_Shared_Image.H>
|
||||
#include <FL/Fl_Tooltip.H>
|
||||
#include "../src/flstring.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern void draw_width(int x, int y, int r, Fl_Align a);
|
||||
extern void draw_height(int x, int y, int b, Fl_Align a);
|
||||
|
||||
extern Fl_Preferences fluid_prefs;
|
||||
|
||||
// Update the XYWH values in the widget panel...
|
||||
@ -618,23 +622,13 @@ void Fl_Window_Type::draw_overlay() {
|
||||
int x,y,r,t;
|
||||
newposition(myo,x,y,r,t);
|
||||
if (!show_guides || !drag || numselected != 1) {
|
||||
if (Fl_Flex_Type::parent_is_flex(q) && !Fl_Flex_Type::is_fixed(q)) {
|
||||
if (((Fl_Flex*)((Fl_Flex_Type*)q->parent)->o)->horizontal()) {
|
||||
int yh = y + (t-y)/2;
|
||||
fl_begin_loop();
|
||||
fl_vertex(x+2, yh); fl_vertex(x+12, yh+5); fl_vertex(x+12, yh-5);
|
||||
fl_end_loop();
|
||||
fl_begin_loop();
|
||||
fl_vertex(r-3, yh); fl_vertex(r-13, yh+5); fl_vertex(r-13, yh-5);
|
||||
fl_end_loop();
|
||||
if (Fl_Flex_Type::parent_is_flex(q) && Fl_Flex_Type::is_fixed(q)) {
|
||||
Fl_Flex *flex = ((Fl_Flex*)((Fl_Flex_Type*)q->parent)->o);
|
||||
Fl_Widget *wgt = myo->o;
|
||||
if (flex->horizontal()) {
|
||||
draw_width(wgt->x(), wgt->y()+15, wgt->x()+wgt->w(), FL_ALIGN_CENTER);
|
||||
} else {
|
||||
int xh = x + (r-x)/2;
|
||||
fl_begin_loop();
|
||||
fl_vertex(xh, y+2); fl_vertex(xh+5, y+12); fl_vertex(xh-5, y+12);
|
||||
fl_end_loop();
|
||||
fl_begin_loop();
|
||||
fl_vertex(xh, t-3); fl_vertex(xh+5, t-13); fl_vertex(xh-5, t-13);
|
||||
fl_end_loop();
|
||||
draw_height(wgt->x()+15, wgt->y(), wgt->y()+wgt->h(), FL_ALIGN_CENTER);
|
||||
}
|
||||
}
|
||||
fl_rect(x,y,r-x,t-y);
|
||||
@ -837,8 +831,11 @@ extern Fl_Menu_Item New_Menu[];
|
||||
This is not ideal for widgets that are moved or resized within a group that
|
||||
manages the layout of its children. We must create a more universal way to
|
||||
modify move events per widget type.
|
||||
|
||||
\param[in] key if key is not 0, it contains the code of the keypress that
|
||||
caused this call. This must only be set when handle FL_KEYBOARD events.
|
||||
*/
|
||||
void Fl_Window_Type::moveallchildren()
|
||||
void Fl_Window_Type::moveallchildren(int key)
|
||||
{
|
||||
undo_checkpoint();
|
||||
Fl_Type *i;
|
||||
@ -862,7 +859,9 @@ void Fl_Window_Type::moveallchildren()
|
||||
// so that the user request is reflected.
|
||||
Fl_Flex_Type* ft = (Fl_Flex_Type*)myo->parent;
|
||||
Fl_Flex* f = (Fl_Flex*)ft->o;
|
||||
if (drag & FD_DRAG) {
|
||||
if (key) {
|
||||
ft->keyboard_move_child(myo, key);
|
||||
} else if (drag & FD_DRAG) {
|
||||
ft->insert_child_at(myo->o, Fl::event_x(), Fl::event_y());
|
||||
} else {
|
||||
if (f->horizontal()) {
|
||||
@ -1181,7 +1180,7 @@ int Fl_Window_Type::handle(int event) {
|
||||
dx *= x_step;
|
||||
dy *= y_step;
|
||||
}
|
||||
moveallchildren();
|
||||
moveallchildren(Fl::event_key());
|
||||
drag = 0;
|
||||
return 1;
|
||||
|
||||
|
@ -72,7 +72,7 @@ protected:
|
||||
Fl_Widget_Type *_make() FL_OVERRIDE {return 0;} // we don't call this
|
||||
Fl_Widget *widget(int,int,int,int) FL_OVERRIDE {return 0;}
|
||||
int recalc; // set by fix_overlay()
|
||||
void moveallchildren();
|
||||
void moveallchildren(int key=0);
|
||||
ID id() const FL_OVERRIDE { return ID_Window; }
|
||||
bool is_a(ID inID) const FL_OVERRIDE { return (inID==ID_Window) ? true : super::is_a(inID); }
|
||||
void open_();
|
||||
|
Loading…
x
Reference in New Issue
Block a user