Alfredo Braunstein wrote:

> This is a quick-hacked inlined-in-open mode as Andre's proposal. Seems to
> work, but I didn't test it much.
> 
> Comments?

It seems that no one really tried this.

Let me point out that it works well in the sense that it finds the way that
uses less space (label on the side or on top); but it may seem a bit
squizofrenic when typing an inset consisting of a line that is approx the
allowed width; depending on the rebreaking the label can jump up or down to
use the more compact layout. I don't know if this is a problem, but if it
is, I don't know very well how to solve it.

Comments still welcomed...

Alfredo
? insetcollapsable-save.C
? insettext-save.C
Index: insetcollapsable.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v
retrieving revision 1.241
diff -u -p -u -r1.241 insetcollapsable.C
--- insetcollapsable.C	4 Mar 2004 07:38:11 -0000	1.241
+++ insetcollapsable.C	8 Mar 2004 10:16:06 -0000
@@ -41,7 +41,7 @@ using std::ostream;
 
 InsetCollapsable::InsetCollapsable(BufferParams const & bp,
 	CollapseStatus status)
-	: inset(bp), label("Label"), status_(status)
+	: inset(bp), label("Label"), status_(status), openinlined_(false)
 {
 	inset.setOwner(this);
 	inset.setAutoBreakRows(true);
@@ -144,8 +144,16 @@ void InsetCollapsable::metrics(MetricsIn
 		if (status_ == Open) {
 			Dimension insetdim;
 			inset.metrics(mi, insetdim);
-			dim.des += insetdim.height() + TEXT_TO_BOTTOM_OFFSET;
-			dim.wid = max(dim.wid, insetdim.wid);
+			openinlined_ = (insetdim.wid + dim.wid <= mi.base.textwidth);
+			if (openinlined_) {
+				dim.wid += insetdim.wid;
+				dim.des = max(dim.des, insetdim.height());
+			} else {
+				dim.des += insetdim.height()
+					+ TEXT_TO_BOTTOM_OFFSET;
+				dim.wid = max(dim.wid, insetdim.wid);
+			}
+			
 		}
 	}
 	dim_ = dim;
@@ -177,7 +185,11 @@ void InsetCollapsable::draw(PainterInfo 
 		if (status_ == Open) {
 			if (!owner())
 				x += scroll();
-			inset.draw(pi, x, y - aa + dimc.height() + inset.ascent());
+			
+			if (!openinlined_)
+				inset.draw(pi, x, y - aa + dimc.height() + inset.ascent());
+			else
+				inset.draw(pi, x + dimc.width(), y - aa + inset.ascent());
 		}
 	}
 }
@@ -324,14 +336,14 @@ void InsetCollapsable::priv_dispatch(LCu
 		case LFUN_MOUSE_PRESS:
 			if (status_ == Inlined)
 				inset.dispatch(cur, cmd);
-			else if (status_ == Open && cmd.y > button_dim.y2)
+			else if (status_ == Open && !hitButton(cmd))
 				inset.dispatch(cur, cmd);
 			break;
 
 		case LFUN_MOUSE_MOTION:
 			if (status_ == Inlined)
 				inset.dispatch(cur, cmd);
-			else if (status_ == Open && cmd.y > button_dim.y2)
+			else if (status_ == Open && !hitButton(cmd))
 				inset.dispatch(cur, cmd);
 			break;
 
Index: insetcollapsable.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.h,v
retrieving revision 1.168
diff -u -p -u -r1.168 insetcollapsable.h
--- insetcollapsable.h	16 Feb 2004 11:58:47 -0000	1.168
+++ insetcollapsable.h	8 Mar 2004 10:16:06 -0000
@@ -160,6 +160,8 @@ protected:
 private:
 	///
 	mutable CollapseStatus status_;
+	/// a substatus of the Open status, determined automatically in metrics
+	mutable bool openinlined_;
 };
 
 #endif

Reply via email to