basic splitter -> kick-ass splitter

This commit is contained in:
Maximilian Hils 2014-09-18 23:47:54 +02:00
parent e66f240e81
commit 390a435ac4
5 changed files with 94 additions and 28 deletions

View File

@ -69,16 +69,29 @@ body,
flex: 1 1 auto; flex: 1 1 auto;
} }
.splitter { .splitter {
flex: 0 0 4px; flex: 0 0 1px;
background-color: #ccc; background-color: #aaa;
content: "X"; position: relative;
} }
.splitter-x { .splitter > div {
position: absolute;
}
.splitter.splitter-x {
cursor: col-resize; cursor: col-resize;
} }
.splitter-y { .splitter.splitter-x > div {
margin-left: -1px;
width: 4px;
height: 100%;
}
.splitter.splitter-y {
cursor: row-resize; cursor: row-resize;
} }
.splitter.splitter-y > div {
margin-top: -1px;
height: 4px;
width: 100%;
}
.nav-tabs { .nav-tabs {
border-bottom: solid #a6a6a6 1px; border-bottom: solid #a6a6a6 1px;
} }

View File

@ -403,15 +403,21 @@ var Splitter = React.createClass({displayName: 'Splitter',
}); });
window.addEventListener("mousemove",this.onMouseMove); window.addEventListener("mousemove",this.onMouseMove);
window.addEventListener("mouseup",this.onMouseUp); window.addEventListener("mouseup",this.onMouseUp);
// Occasionally, only a dragEnd event is triggered, but no mouseUp.
window.addEventListener("dragend",this.onDragEnd);
}, },
onMouseUp: function(e){ onDragEnd: function(){
this.getDOMNode().style.transform="";
window.removeEventListener("dragend",this.onDragEnd);
window.removeEventListener("mouseup",this.onMouseUp); window.removeEventListener("mouseup",this.onMouseUp);
window.removeEventListener("mousemove",this.onMouseMove); window.removeEventListener("mousemove",this.onMouseMove);
},
onMouseUp: function(e){
this.onDragEnd();
var node = this.getDOMNode(); var node = this.getDOMNode();
var prev = node.previousElementSibling; var prev = node.previousElementSibling;
var next = node.nextElementSibling; var next = node.nextElementSibling;
this.getDOMNode().style.transform="";
var dX = e.pageX-this.state.startX; var dX = e.pageX-this.state.startX;
var dY = e.pageY-this.state.startY; var dY = e.pageY-this.state.startY;
@ -438,7 +444,7 @@ var Splitter = React.createClass({displayName: 'Splitter',
} }
this.getDOMNode().style.transform = "translate("+dX+"px,"+dY+"px)"; this.getDOMNode().style.transform = "translate("+dX+"px,"+dY+"px)";
}, },
reset: function(){ reset: function(willUnmount) {
if (!this.state.applied) { if (!this.state.applied) {
return; return;
} }
@ -448,6 +454,16 @@ var Splitter = React.createClass({displayName: 'Splitter',
prev.style.flex = ""; prev.style.flex = "";
next.style.flex = ""; next.style.flex = "";
if(!willUnmount){
this.setState({
applied: false
});
}
},
componentWillUnmount: function(){
this.reset(true);
}, },
render: function(){ render: function(){
var className = "splitter"; var className = "splitter";
@ -456,7 +472,11 @@ var Splitter = React.createClass({displayName: 'Splitter',
} else { } else {
className += " splitter-y"; className += " splitter-y";
} }
return React.DOM.div({className: className, onMouseDown: this.onMouseDown}); return (
React.DOM.div({className: className},
React.DOM.div({onMouseDown: this.onMouseDown, draggable: "true"})
)
);
} }
}); });
/** @jsx React.DOM */ /** @jsx React.DOM */
@ -991,7 +1011,6 @@ var ProxyAppMain = React.createClass({displayName: 'ProxyAppMain',
SettingsStore.removeListener("change", this.onSettingsChange); SettingsStore.removeListener("change", this.onSettingsChange);
}, },
onSettingsChange: function () { onSettingsChange: function () {
console.log("onSettingsChange");
this.setState({settings: SettingsStore.getAll()}); this.setState({settings: SettingsStore.getAll()});
}, },
render: function () { render: function () {
@ -999,7 +1018,7 @@ var ProxyAppMain = React.createClass({displayName: 'ProxyAppMain',
React.DOM.div({id: "container"}, React.DOM.div({id: "container"},
Header({settings: this.state.settings}), Header({settings: this.state.settings}),
this.props.activeRouteHandler({settings: this.state.settings}), this.props.activeRouteHandler({settings: this.state.settings}),
Splitter({axis: "y"}), this.state.settings.showEventLog ? Splitter({axis: "y"}) : null,
this.state.settings.showEventLog ? EventLog(null) : null, this.state.settings.showEventLog ? EventLog(null) : null,
Footer({settings: this.state.settings}) Footer({settings: this.state.settings})
) )

View File

@ -30,14 +30,29 @@ html, body, #container {
} }
.splitter { .splitter {
flex: 0 0 4px; flex: 0 0 1px;
background-color: #ccc; background-color: #aaa;
content: "X"; position: relative;
> div {
position: absolute;
//debug: background-color: orange;
} }
.splitter-x {
&.splitter-x {
cursor: col-resize; cursor: col-resize;
> div {
margin-left: -1px;
width: 4px;
height: 100%;
} }
.splitter-y { }
&.splitter-y {
cursor: row-resize; cursor: row-resize;
> div {
margin-top: -1px;
height: 4px;
width: 100%;
}
}
} }

View File

@ -19,7 +19,6 @@ var ProxyAppMain = React.createClass({
SettingsStore.removeListener("change", this.onSettingsChange); SettingsStore.removeListener("change", this.onSettingsChange);
}, },
onSettingsChange: function () { onSettingsChange: function () {
console.log("onSettingsChange");
this.setState({settings: SettingsStore.getAll()}); this.setState({settings: SettingsStore.getAll()});
}, },
render: function () { render: function () {
@ -27,7 +26,7 @@ var ProxyAppMain = React.createClass({
<div id="container"> <div id="container">
<Header settings={this.state.settings}/> <Header settings={this.state.settings}/>
<this.props.activeRouteHandler settings={this.state.settings}/> <this.props.activeRouteHandler settings={this.state.settings}/>
<Splitter axis="y"/> {this.state.settings.showEventLog ? <Splitter axis="y"/> : null}
{this.state.settings.showEventLog ? <EventLog/> : null} {this.state.settings.showEventLog ? <EventLog/> : null}
<Footer settings={this.state.settings}/> <Footer settings={this.state.settings}/>
</div> </div>

View File

@ -22,15 +22,21 @@ var Splitter = React.createClass({
}); });
window.addEventListener("mousemove",this.onMouseMove); window.addEventListener("mousemove",this.onMouseMove);
window.addEventListener("mouseup",this.onMouseUp); window.addEventListener("mouseup",this.onMouseUp);
// Occasionally, only a dragEnd event is triggered, but no mouseUp.
window.addEventListener("dragend",this.onDragEnd);
}, },
onMouseUp: function(e){ onDragEnd: function(){
this.getDOMNode().style.transform="";
window.removeEventListener("dragend",this.onDragEnd);
window.removeEventListener("mouseup",this.onMouseUp); window.removeEventListener("mouseup",this.onMouseUp);
window.removeEventListener("mousemove",this.onMouseMove); window.removeEventListener("mousemove",this.onMouseMove);
},
onMouseUp: function(e){
this.onDragEnd();
var node = this.getDOMNode(); var node = this.getDOMNode();
var prev = node.previousElementSibling; var prev = node.previousElementSibling;
var next = node.nextElementSibling; var next = node.nextElementSibling;
this.getDOMNode().style.transform="";
var dX = e.pageX-this.state.startX; var dX = e.pageX-this.state.startX;
var dY = e.pageY-this.state.startY; var dY = e.pageY-this.state.startY;
@ -57,7 +63,7 @@ var Splitter = React.createClass({
} }
this.getDOMNode().style.transform = "translate("+dX+"px,"+dY+"px)"; this.getDOMNode().style.transform = "translate("+dX+"px,"+dY+"px)";
}, },
reset: function(){ reset: function(willUnmount) {
if (!this.state.applied) { if (!this.state.applied) {
return; return;
} }
@ -67,6 +73,16 @@ var Splitter = React.createClass({
prev.style.flex = ""; prev.style.flex = "";
next.style.flex = ""; next.style.flex = "";
if(!willUnmount){
this.setState({
applied: false
});
}
},
componentWillUnmount: function(){
this.reset(true);
}, },
render: function(){ render: function(){
var className = "splitter"; var className = "splitter";
@ -75,6 +91,10 @@ var Splitter = React.createClass({
} else { } else {
className += " splitter-y"; className += " splitter-y";
} }
return <div className={className} onMouseDown={this.onMouseDown}></div>; return (
<div className={className}>
<div onMouseDown={this.onMouseDown} draggable="true"></div>
</div>
);
} }
}); });